[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

11/10/2007 at 07:59AM PST, ID: 22952080
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.6

Problem with polymorphism and cout

Asked by ammotroop in C++ Programming Language, Programming Languages

Tags: _outline

Experts,

I am having one heck of a time trying to get something to print out using cout.  Here is a description of the application that I am writing.  Basically it is a contact management app that will allow a user to add, edit, delete contacts as they so choose.  They can have multiple contact books which they can "open" and do whatever they want.

The problem is that in our class we have to use polymorphism inheritance and all is good.  It took me a while to figure out an error with fstream but once I got that worked out my application works smoothly.

The problem is that when I call

/* Use to pass cout as a reference */
_contacts->ViewFile(0, cout);

or

/* Does not pass cout as reference */
_contacts->ViewFile(0);

once I start trying to output anything on the screen it basically overwrites what is there.  Here is the function ViewFile.

void Contacts::ViewFile(int contactNum, ostream& obj)
{
      /* String to hold line */
      string _outLine;

      /* Check contactNum */
      //if (contactNum > this->_iperson.size() - 1)
            //contactNum = this->_iperson.size() - 1;

      this->ShowInfo();

      Person& _person = _iperson[0];

      _outLine.append("Name:\t\t");
      _outLine.append(this->_iperson[contactNum].LastName);
      _outLine.append(", ");
      _outLine.append(this->_iperson[contactNum].FirstName);
      _outLine.append(" ");
      _outLine.append(this->_iperson[contactNum].MiddleName);
      _outLine.append("\n");

      cout.write(_outLine.c_str(), _outLine.size());

      return;

      /* Loop through contact addresses */
      if (_iperson[0].Addresses.size() > 0)
      {
            cout << "Address(es):\t";

            for (int a = 0; a < _iperson[0].Addresses.size(); a++)
            {
                  /* Insert tabs if not first address */
                  if (a != 0) cout << "\t\t";
                  
                  /* Output location and country */
                  cout << _iperson[0].Addresses[a].AddressLocation << " - " << _iperson[0].Addresses[a].Country << endl;

                  /* Output address 1 and 2 */
                  cout << endl << "\t\t" << _iperson[0].Addresses[a].Address1;

                  if (_person.Addresses[a].Address2 != "")
                        cout << endl << "\t\t" << _iperson[0].Addresses[a].Address2;

                  /* Output city, State Zip Code */
                  cout.write("Test", string("Test").size());

                  cout << endl << "\t\t" << _iperson[0].Addresses[a].City << ", "
                        << _iperson[0].Addresses[a].State << " "
                        << _iperson[0].Addresses[a].ZipCode << endl;
            }
      }
}

Now here is the trick.  this->ShowInfo() prints out on the screen fine.  It is only AFTER I start making any calls to _iperson[contactNum] that it starts printing out at the beginning of the line no matter what is before or after.

So if I called
cout << _iperson[contactNum].FirstName << _iperson[contactNum].LastName
it would print out
Bullard

cause my last name is longer than the first.  So I don't understand why this is happening.

Any help would be greatly appreciated.  :)
[+][-]11/10/07 08:02 AM, ID: 20256116

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/10/07 08:06 AM, ID: 20256125

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/10/07 08:08 AM, ID: 20256134

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/10/07 08:52 AM, ID: 20256257

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/10/07 10:05 AM, ID: 20256503

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/10/07 10:50 AM, ID: 20256627

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/10/07 11:03 AM, ID: 20256659

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: C++ Programming Language, Programming Languages
Tags: _outline
Sign Up Now!
Solution Provided By: Infinity08
Participating Experts: 1
Solution Grade: A
 
 
[+][-]11/10/07 11:24 PM, ID: 20258322

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20090824-EE-VQP-74 / EE_QW_2_20070628