Inheritance Lab help

Could someone take a look at this lab. It works the only issue is as I run it and get the bottom of the inheritance program it prompts the user to
"Enter 3 digit area code: Enter 3 digit area code: "

Here is the code, if anyone could possibly take a look at it, any help would be great.

//Lab4.cpp

#include <iostream>
#include <string>
#include "TelephoneNumber.h"
using namespace std;

ostream & operator<<(ostream & Out, TelephoneNumber & TN);

void main()
{
cout << "Welcome to the Telephone Numbers Lab4!\n" << endl;
TelephoneNumber MyName;
TelephoneNumber Test1("111", "111", "1111");
TelephoneNumber Test2("22", "222", "2222");
WorkingTN MyNum;
WorkingTN Test3("333", "333", "333", "ME");
BillingTN ME;

cout << MyName << endl;

cout << Test1 << endl;

cout << Test2 << "\n" << endl;

cout << MyNum << endl;

cout << Test3 << endl;

cout << MyName << Test1 << Test2 << MyNum << Test3 << endl;

cout << ME;
}

ostream & operator<<(ostream & Out, TelephoneNumber & TN)
{
TN.PrintToStream(Out);
return Out;
}

//class TelephoneNumber declaration
//TelephoneNumber.h
//(Documentation prologue goes here

#include <iostream>
#include <string>
using namespace std;

#ifndef TELEPHONE_H
#define TELEPHONE_H

class TelephoneNumber
{
public:
TelephoneNumber();
TelephoneNumber(const string & inNPA, const string & inNXX, const string & inLine);
~TelephoneNumber()
{
cout << "In TelephoneNumber destructor\n";
}

void SetNPA(const string & newNPA);
void SetNXX(const string & newNXX);
void SetLine(const string & newLine);

string GetNPA() const;
string GetNXX() const;
string GetLine() const;

virtual void PrintToStream(ostream & Out);

private:
string NPA;
string NXX;
string Line;
};

class WorkingTN : public TelephoneNumber
{
public:
WorkingTN();
WorkingTN(const string & inNPA, const string & inNXX, const string & inLine, const string & Name);
~WorkingTN()
{
cout << "In Working Telephone Number destructor\n";
}

void SetCustName(const string & newName);

string GetCustName();

void PrintToStream(ostream & Out);

protected:
string CustomerName;

};

class BillingTN : public WorkingTN
{
public:
BillingTN();
~BillingTN()
{
cout << "In Billing Telephone Number Destructor\n";
}

void SetBillingTN(const int & Num);

int GetBillingTN();

void PrintToStream(ostream & Out);
protected:
int NumWorkingTNs;

};

#endif // !1

//Class TelephoneNumber member implementations
//(Documentation prologue
//TelephoneNumber.cpp

#include <iostream>
#include <string>
#include "TelephoneNumber.h"
using namespace std;

TelephoneNumber::TelephoneNumber()
{

do
{
cout << "Enter 3 digit Area Code: ";
getline(cin, NPA);
} while ((NPA.length() != 3));

do
{
cout << "Enter 3 digit Prefix: ";
getline(cin, NXX);
} while ((NXX.length() != 3));

do
{
cout << "Enter 4 digit Extension: ";
getline(cin, Line);
} while ((Line.length() != 4));

cout << "In TelephoneNumber default constructor\n";

}

TelephoneNumber::TelephoneNumber(const string & inNPA, const string & inNXX, const string & inLine)
{
if (inNPA.length() < 3)
{
cout << "NPA parameter too short -- defaulting to 555\n" << endl;
NPA = "555";
}
else if (NPA.length() > 3)
{
cout << "NPA parameter too long -- truncating to 3 digits\n" << endl;
NPA = inNPA.substr(0, 3);
}
else
{
NPA = inNPA;
cout << "In 3 parameter TelephoneNumber constructor\n" << endl;
}

if (inNXX.length() < 3)
{
cout << "NXX parameter too short -- defaulting to 555\n" << endl;
NXX = "555";
}
else if (NXX.length() > 3)
{
cout << "NXX parameter too long -- truncating to 3 digits\n" << endl;
NXX = inNXX.substr(0, 3);
}
else
{
NXX = inNXX;
cout << "In 3 parameter TelephoneNumber constructor\n" << endl;
}

if (inLine.length() < 4)
{
cout << "NXX parameter too short -- defaulting to 555\n" << endl;
Line = "5555";
}
else if (Line.length() > 4)
{
cout << "NXX parameter too long -- truncating to 3 digits\n" << endl;
Line = inLine.substr(0, 4);
}
else
{
Line = inLine;
cout << "In 3 parameter TelephoneNumber constructor\n" << endl;
}
}

void TelephoneNumber::SetNPA(const string & newNPA)
{
NPA = newNPA;
}

void TelephoneNumber::SetNXX(const string & newNXX)
{
NXX = newNXX;
}

void TelephoneNumber::SetLine(const string & newLine)
{
Line = newLine;
}

string TelephoneNumber::GetNPA() const
{
return NPA;
}

string TelephoneNumber::GetNXX() const
{
return NXX;
}

string TelephoneNumber::GetLine() const
{
return Line;
}

void TelephoneNumber::PrintToStream(ostream & Out)
{
Out << "Telephone Number: (" << NPA << ") " << NXX << "-" << Line << endl;
}

WorkingTN::WorkingTN() : TelephoneNumber()
{
char choice;

do
{
cout << "Enter your first name: ";
getline(cin, CustomerName);

cout << "Is this the correct(y/n): ";
cin >> choice;

switch (choice)
{
case 'y':
case 'Y':
break;

case 'n':
case 'N':
cout << "Try Again!" << endl;
getline(cin, CustomerName);
break;

default:
cout << "Invalid choice, Try Again!" << endl;
getline(cin, CustomerName);
continue;
}
} while ((choice != 'y') && (choice != 'Y'));

cout << "\nIn Working Telephone Number Default Constructor!" << endl;
}

WorkingTN::WorkingTN(const string & inNPA, const string & inNXX, const string & inLine, const string & Name) : TelephoneNumber(inNPA, inNXX, inLine)
{
TelephoneNumber::SetNPA(inNPA);
TelephoneNumber::SetNXX(inNXX);
TelephoneNumber::SetLine(inLine);
CustomerName = Name;

cout << "In Working Telephone Number Three Parameter Constructor!\n" << endl;
}

void WorkingTN::SetCustName(const string & newName)
{
CustomerName = newName;
}

string WorkingTN::GetCustName()
{
return CustomerName;
}

void WorkingTN::PrintToStream(ostream & Out)
{
TelephoneNumber::PrintToStream(Out);
Out << "Customer Name: " << CustomerName << "\n" << endl;
}

BillingTN::BillingTN()
{
do
{
cout << "Enter number of working telephone numbers: ";
cin >> NumWorkingTNs;
if (NumWorkingTNs != 0)
{
cout << "In Billing Telephone Number Default Constructor!\n" << endl;
}
else
{
cout << "You have enter invalid entry, should be > 0!" << endl;
cout << "Please Try Again!" << endl;
}
} while ((NumWorkingTNs == 0) || (NumWorkingTNs < 0));
}

void BillingTN::SetBillingTN(const int & Num)
{
NumWorkingTNs = Num;
}

int BillingTN::GetBillingTN()
{
return NumWorkingTNs;
}

void BillingTN::PrintToStream(ostream & Out)
{
TelephoneNumber::PrintToStream(Out);
Out << "Customer Name: " << CustomerName << endl;
Out << "Number of working lines: " << NumWorkingTNs << "\n" << endl;
}

Thanks in advance for any advice/help
Here is the output after running the code.

Welcome to the Telephone Numbers Lab4!

Enter 3 digit Area Code: 444
Enter 3 digit Prefix: 444
Enter 4 digit Extension: 4444
In TelephoneNumber default constructor
In 3 parameter TelephoneNumber constructor

In 3 parameter TelephoneNumber constructor

In 3 parameter TelephoneNumber constructor

NPA parameter too short -- defaulting to 555

In 3 parameter TelephoneNumber constructor

In 3 parameter TelephoneNumber constructor

Enter 3 digit Area Code: 555
Enter 3 digit Prefix: 555
Enter 4 digit Extension: 5555
In TelephoneNumber default constructor
Enter your first name: MyNum Test
Is this the correct(y/n): y

In Working Telephone Number Default Constructor!
In 3 parameter TelephoneNumber constructor

In 3 parameter TelephoneNumber constructor

NXX parameter too short -- defaulting to 555

In Working Telephone Number Three Parameter Constructor!

Enter 3 digit Area Code: Enter 3 digit Area Code: 999
Enter 3 digit Prefix: 999
Enter 4 digit Extension: 9999
In TelephoneNumber default constructor
Enter your first name: ME Test
Is this the correct(y/n): Y

In Working Telephone Number Default Constructor!
Enter number of working telephone numbers: 54
In Billing Telephone Number Default Constructor!

Telephone Number: (444) 444-4444

Telephone Number: (111) 111-1111

Telephone Number: (555) 222-2222


Telephone Number: (555) 555-5555
Customer Name: MyNum Test


Telephone Number: (333) 333-333
Customer Name: ME


Telephone Number: (444) 444-4444
Telephone Number: (111) 111-1111
Telephone Number: (555) 222-2222
Telephone Number: (555) 555-5555
Customer Name: MyNum Test

Telephone Number: (333) 333-333
Customer Name: ME


Telephone Number: (999) 999-9999
Customer Name: ME Test
Number of working lines: 54

In Billing Telephone Number Destructor
In Working Telephone Number destructor
In TelephoneNumber destructor
In Working Telephone Number destructor
In TelephoneNumber destructor
In Working Telephone Number destructor
In TelephoneNumber destructor
In TelephoneNumber destructor
In TelephoneNumber destructor
In TelephoneNumber destructor
Press any key to continue . . .
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
WorkingTN::WorkingTN() : TelephoneNumber()
{
    cout << "Enter your first name: ";
    getline(cin, CustomerName);

    char choice;

    do
    {

        cout << "Is this the correct(y/n): ";
        cin >> choice;

        switch (choice)
        {
        case 'y':
        case 'Y':
            break;

        case 'n':
        case 'N':
            cout << "Try Again!" << endl;
            break;

        default:
            cout << "Invalid choice, Try Again!" << endl;
        }

    }
    while ((choice != 'y') && (choice != 'Y'));

    cin.ignore( 1000, '\n' ) ; // ***** added *********************

    cout << "\nIn Working Telephone Number Default Constructor!" << endl;
}

See: http://www.cplusplus.com/forum/general/69685/#msg372532
Topic archived. No new replies allowed.