So my code will compile and I do get output but it does not look the way its suppose to. I'm also not certain I am doing the virtual functions properly

Expected Output

Telephone Number : NPA-NXX-Line
Customer: CustomerName
Number of Working Lines: NumWorkingTNs

Current Output


derived class WorkTelephoneNumber constructor
derived class WorkTelephoneNumber constructor
derived class WorkTelephoneNumber constructor
derived class WorkTelephoneNumber constructor
derived class BillingTelephoneNumber constructor
derived class WorkTelephoneNumber constructor
derived class BillingTelephoneNumber constructor
derived class WorkTelephoneNumber constructor
derived class BillingTelephoneNumber constructor
Testing the overladen << operator with the virtualprinttostream()

The telephone numbers are:
7194400379
7195906768
7195906729

The working telephone numbers are:
WorkNumber: 7195906732 Name: Book Store
WorkNumber: 2123716940 Name: Borland C++ Guru
WorkNumber: 4056123433 Name: Visual C++ Expert

The billing telephone numbers are:
BillingNumber: 7195906850 Lines: 0
BillingNumber: 7195986708 Lines: 0
BillingNumber: 7195980200 Lines: 0

Here endeth the hierarchy of the telephone!
BillingTelephoneNumber destructor fx flushed object containing variable value 0
WorkTelephoneNumber destructor fx flushed object containing variable value Receptionist
TelephoneNumber destructor fx flushed object containing variable value 7195980200
BillingTelephoneNumber destructor fx flushed object containing variable value 0
WorkTelephoneNumber destructor fx flushed object containing variable value Librarian
TelephoneNumber destructor fx flushed object containing variable value 7195986708
BillingTelephoneNumber destructor fx flushed object containing variable value 0
WorkTelephoneNumber destructor fx flushed object containing variable value Dean of C
TelephoneNumber destructor fx flushed object containing variable value 7195906850
WorkTelephoneNumber destructor fx flushed object containing variable value Visual C++ Expert
TelephoneNumber destructor fx flushed object containing variable value 4056123433
WorkTelephoneNumber destructor fx flushed object containing variable value Borland C++ Guru
TelephoneNumber destructor fx flushed object containing variable value 2123716940
WorkTelephoneNumber destructor fx flushed object containing variable value Book Store
TelephoneNumber destructor fx flushed object containing variable value 7195906732
TelephoneNumber destructor fx flushed object containing variable value 7195906729
TelephoneNumber destructor fx flushed object containing variable value 7195906768
TelephoneNumber destructor fx flushed object containing variable value 7194400379


The code is
CS215Lab4.cpp

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

ostream& operator << (ostream &out, TelephoneNumber &tn)
{
	//cout << "DEBUG> overloaded operator <<\n"; 
	tn.printtostream(out);
	return out;	
}

int main()
{
	TelephoneNumber yournumber("719", "440", "0379");
	TelephoneNumber paul("719","590","6768");
	TelephoneNumber bob("719","590","6729");
	WorkTelephoneNumber csstaff1 ("719","590","6732","Book Store");
	WorkTelephoneNumber csstaff2 ("212","371","6940","Borland C++ Guru");
	WorkTelephoneNumber csstaff3 ("405","612","3433","Visual C++ Expert");
	BillingTelephoneNumber csdept ("719","590","6850","Dean of CS");
	BillingTelephoneNumber library ("719","598","6708","Librarian");
	BillingTelephoneNumber reception ("719","598","0200","Receptionist",35);
	cout << "Testing the overladen << operator with the virtual" << "printtostream()\n\n";
	cout << "The telephone numbers are: \n" << endl;
	cout << yournumber << endl;
	cout << paul << endl;
	cout << bob << endl;
	cout << "The working telephone numbers are: \n" << endl;
	//printf("DEBUG> csstaff1.line= %s\n", csstaff1.GetLINE().c_str() );
	cout << csstaff1 << endl;
	cout << csstaff2 << endl;
	cout << csstaff3 << endl;
	cout << "The billing telephone numbers are: \n" << endl;
	cout << csdept << endl;
	cout << library << endl;
	cout << reception << endl;
	cout << "Here endeth the hierarchy of the telephone!" << endl;
	return 0;
}

TelephoneNumber.h

//  PROCESS THIS FILE ONLY PER PROJECT
#ifndef TelephoneNumber_h	// Avoid duplicate compilations
#define TelephoneNumber_h   //
//=======================================================================
// INCLUDE FILES
#include <iostream>
#include <string>
using namespace std;
//=======================================================================
// CONSTANT DEFINITION
//
//=======================================================================
// EXTERNAL CLASS VARIABLE
//
//=======================================================================
// FUNCTION PROTOTYPES
//
//=======================================================================
// Class Object
//=======================================================================     

class TelephoneNumber 
{               
	
public:                
	
    TelephoneNumber() 
	{
		cout <<"\n TelephoneNumber default constructor proof\n";
	}

    TelephoneNumber(string i_npa ,string i_nxx ,string i_line);
	
    void ph_num();
	
	
	void SetNPA(string newnpa) 
	{
		npa = newnpa; 
	}
	
	void SetNXX(string newnxx)
	{
		nxx = newnxx;
	}
	
	void SetLINE(string newline) 
	{ 
		line = newline;
	} 
	
    string GetNPA() const
	{
		return npa; 
	}
	
    string GetNXX() const 
	{
		return nxx; 
	}
    
    string GetLINE() const 
	{
		return line; 
	}

    string GetPHONENUM() const
    {
        return p_num;
    }

    virtual void printtostream(ostream& out)
    {
        cout << p_num << endl;
    }

	~TelephoneNumber();

private:
	string npa, nxx, line, p_num;

};

#endif

TelephoneNumber.cpp

#include "TelephoneNumber.h"
//========================================================================
// CONSTANT DEFINITIONS
//
//========================================================================
// EXTERNAL CLASS VARIABLES
//
//========================================================================
//========================================================================
// CONSTANT DEFINITIONS
//
//========================================================================
// EXTERNAL CLASS VARIABLES
//
//========================================================================
//************************************************************************
//  BEGINNING OF PROGRAMMING CODE
//************************************************************************
//***********************************************************************
//  TelephoneNumber Constructor
//***********************************************************************

TelephoneNumber::TelephoneNumber(string i_npa ,string i_nxx ,string i_line)
{
    npa  = i_npa;
    nxx  = i_nxx;
    line = i_line;
    ph_num();
}

void TelephoneNumber::ph_num() 
{	
	p_num = npa + nxx + line;
}       
//***********************************************************************
//  Telephone Number Destructor
//***********************************************************************

TelephoneNumber::~TelephoneNumber() 
{
	
    cout <<" \n TelephoneNumber destructor fx flushed object containing variable value "<< p_num <<
	"\n\n"<<endl;	
}

WorkingTelephoneNumber.h

#ifndef WorkTelephoneNumber_h	// Avoid duplicate compilations
#define WorkTelephoneNumber_h   //
//=======================================================================
// INCLUDE FILES                        
#include <iostream>        
#include <string>
#include "TelephoneNumber.h"
using namespace std;
//=======================================================================
// CONSTANT DEFINITION
//
//=======================================================================
// EXTERNAL CLASS VARIABLE
//
//=======================================================================
// FUNCTION PROTOTYPES
//
//=======================================================================
// Class Object
//=======================================================================

class WorkTelephoneNumber : public TelephoneNumber 
{ 
	
public:
	
	WorkTelephoneNumber() 
	{
		cout <<"\n WorkTelephoneNumber default constructor proof\n";
	}
	
	WorkTelephoneNumber(string i_npa, string i_nxx, string i_line, string i_name);
	
	void cust_num();

	void SetCustName(string newname)
	{
		newname = CustName; 
	}
	
	string GetCustName() const 
	{
		return CustName; 
	}
	
	virtual void printtostream(ostream& out)
	{
        cout << "WorkNumber: " << GetPHONENUM() << " Name: " << GetCustName() << endl;
    }

	~WorkTelephoneNumber();

protected:
	string CustName;    

};

#endif

WorkingTelephoneNumber.cpp

#include <iostream>
#include "WorkTelephoneNumber.h"
#include "TelephoneNumber.h"
//========================================================================
// CONSTANT DEFINITIONS
//
//========================================================================
// EXTERNAL CLASS VARIABLES
//
//========================================================================
//========================================================================
// CONSTANT DEFINITIONS
//
//========================================================================
// EXTERNAL CLASS VARIABLES
//
//========================================================================
//************************************************************************
//  BEGINNING OF PROGRAMMING CODE
//************************************************************************

//************************************************************************
//  Work Telephone Number Constructor
//************************************************************************

WorkTelephoneNumber::WorkTelephoneNumber(string i_npa, string i_nxx, string i_line, string i_name) : TelephoneNumber(i_npa, i_nxx, i_line)
{
	//TelephoneNumber(i_npa, i_nxx, i_line);
	cout << "derived class WorkTelephoneNumber constructor" << endl;

    CustName = i_name; 
}


void WorkTelephoneNumber::cust_num()
{	
	/* Interactive Code
	cout << " \n WorkTelephoneNumber parameterized constructor proof\n\n Type customer name then press 'ENTER' key  ";
	
	cin >> CustName; cout <<" \n Customer name: "<< CustName <<endl;  
	 */
}
	 
//************************************************************************
//  Work Telephone Number Destructor
//************************************************************************

WorkTelephoneNumber::~WorkTelephoneNumber() 
{	
	cout <<" \n WorkTelephoneNumber destructor fx flushed object containing variable value "<< CustName <<
	"\n\n" << endl;
}

BillingTelephoneNumber.h

#include <iostream>        
#include <string>
#include "WorkTelephoneNumber.h"
using namespace std; 
//=======================================================================
// CONSTANT DEFINITION
//
//=======================================================================
// EXTERNAL CLASS VARIABLE
//
//=======================================================================
// FUNCTION PROTOTYPES
//
//=======================================================================
// Class Object
//=======================================================================    

class BillingTelephoneNumber : public WorkTelephoneNumber 
{ 
	
public:
	
	BillingTelephoneNumber()
	{
		cout <<"\n BillingTelephoneNumber default constructor proof\n";
	}
	
	BillingTelephoneNumber(string i_npa, string i_nxx, string i_line, string i_name, int numlines=0);
	
	void cust_num_lines();
	
	void setnumlines(int numlines)
	{
		numlines = 0; 
	}
	
	int getnumlines() const
	{
		return numlines; 
	}
	
	virtual void printtostream(ostream& out)
    {
        cout << "BillingNumber: " << GetPHONENUM() << " Lines: " << getnumlines() << endl;
    }

	~BillingTelephoneNumber();

protected:
	
	int numlines;

};

#endif

BillingTelephoneNumber.cpp

#include <iostream>
#include "BillingTelephoneNumber.h"
#include "WorkTelephoneNumber.h"
#include "TelephoneNumber.h"
//========================================================================
// CONSTANT DEFINITIONS
//
//========================================================================
// EXTERNAL CLASS VARIABLES
//
//========================================================================
//========================================================================
// CONSTANT DEFINITIONS
//
//========================================================================
// EXTERNAL CLASS VARIABLES
//
//========================================================================
//************************************************************************
//  BEGINNING OF PROGRAMMING CODE
//************************************************************************

//************************************************************************
// Billing Telephone Number Constructor
//************************************************************************

BillingTelephoneNumber::BillingTelephoneNumber(string i_npa, string i_nxx, string i_line, string i_name, int numlines) : WorkTelephoneNumber(i_npa, i_nxx, i_line, i_name)
{
	cout << "derived class BillingTelephoneNumber constructor" << endl;
}     

void BillingTelephoneNumber::cust_num_lines()
{ 
	
}

//************************************************************************
// Billing Telephone Number Destructor
//************************************************************************

BillingTelephoneNumber::~BillingTelephoneNumber()
{
	cout <<" \n BillingTelephoneNumber destructor fx flushed object containing variable value "<< numlines <<
	"\n\n"<<endl;
}

try to comment all the cout operations and just leave the out you want

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.