print derived class objects

This short code compiles nicely - i am looking for print methods to make the output print the format shown below - i am looking for a function or method of calling the existing code objects to make them display like the below example - there has to be a way to tweek the main() using the current objects to get a print like this:

Customer: Security
Telephone no#: (312)777-1111

Customer: Security
Telephone no#: (312)777-1111
No# phone lines: 10

___________________________________

Customer: Library
Telephone no#: (312)444-2222

Customer: Library
Telephone no#: (312)444-2222
No# phone lines: 8

Here is the program - it is ok in its current form but i need the above display to work - thanks ~LS

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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// W I P_2                   //Tnum.h interface 

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

class Tnum {               

public:                
	string NPA, NXX, LINE, P_NUM;

	Tnum( ) {cout <<"\n Tnum default constructor proof\n";}

	Tnum( string a,string b,string c );

	void ph_num( );

   ~Tnum( );

	string GetNPA( ) const { return NPA; }
	void SetNPA( string g ) { NPA = g; }

	string GetNXX( ) const { return NXX; }
	void SetNXX( string h ) { NXX = h; }

	string GetLINE( ) const { return LINE; }
	void SetLINE( string i ) { LINE = i; } 
};

Tnum::Tnum( string a,string b,string c ) {

	NPA  = a;
	NXX  = b;
	LINE = c;
	P_NUM = NPA + NXX + LINE;  }

void Tnum::ph_num( ) {

	cout <<" \n Tnum parameterized constructor proof\n\n Type 3 digit area code then press 'ENTER' key  ";
	cin >> NPA;

	cout <<" \n Type 3 digit prefix then press 'ENTER' key  ";
	cin >> NXX;

	cout <<" \n Type 4 digit line number then press 'ENTER' key  ";
	cin >> LINE;

	P_NUM = NPA + NXX + LINE; cout <<" \n Telephone no#: "<< P_NUM <<"\n"; }       

Tnum::~Tnum( ) {

	cout <<" \n Tnum destructor fx flushed object containing variable value "<< P_NUM <<"\n\n_________________________________________________________________________"<<endl;}

//________________________________________________
                            
                               //WorTN.h interface                              

class WorTN : public Tnum { 

public:
   string CustName;    

   WorTN( ) {cout <<"\n WorTN default constructor proof\n";}

   WorTN( string d );

   void cust_num( );
             
   ~WorTN( );

   string GetCustName( ) const { return CustName; }
   void SetCustName( string j ) { CustName = j; }
};

WorTN::WorTN( string d ) { CustName = d; }
   
void WorTN::cust_num( ) {
	   
   cout << " \n WorTN parameterized constructor proof\n\n Type customer name then press 'ENTER' key  ";

   cin >> CustName; cout <<" \n Customer name: "<< CustName <<endl;  }

WorTN::~WorTN( ) {

   cout <<" \n WorTN destructor fx flushed object containing variable value "<< CustName <<"\n\n_________________________________________________________________________"<<endl;}


//____________________________________________________________________________
                            
                               //BTN.h interface                              

class BTN : public WorTN { 

public:
   int NumWrkLines;

   BTN( ) {cout <<"\n BTN default constructor proof\n";}
          
   BTN( int e );

   void cust_num_lines( );
    
  ~BTN( );

   int GetNumWrkLines( ) const { return NumWrkLines; }
   void SetNumWrkLines( int k ) { NumWrkLines = k; }
};

BTN::BTN( int e ) { NumWrkLines = e; }	 
 
void BTN::cust_num_lines( ) { 
	
   cout << " \n BTN parameterized constructor proof\n\n Type number of lines then press 'ENTER' key  ";
   cin >> NumWrkLines;

   cout <<" \n No# of lines: "<< NumWrkLines <<endl;  }

BTN::~BTN( ) {

   cout <<" \n BTN destructor fx flushed object containing variable value "<< NumWrkLines <<"\n\n_________________________________________________________________________"<<endl;}

//___________________________________________________________________________________

                       //Tnum_main.cpp utilization

ostream &operator<<(ostream &print1, Tnum m) {
   print1 << "\n Telephone no#: (" << m.NPA << ") ";
   print1 << m.NXX << "-" << m.LINE << "\n";   
   return print1; }

ostream &operator<<(ostream &print2, WorTN n) {
   print2 << "\n Customer: "<< n.CustName << "\n";
   return print2; }

ostream &operator<<(ostream &print3, BTN o) {
   print3 << "\n No# phone lines: "<< o.NumWrkLines << "\n"; 
   return print3; }

ostream& T( ostream& p ) { return p <<'\a'; }   

int main( ) {

   Tnum xx;     xx.ph_num( );           
   WorTN yy;    yy.cust_num( );        
   BTN zz;      zz.cust_num_lines( );  

   Tnum x( "(303) ","777-","1111" );
   Tnum y( "(303) ","444-","2222" );
   cout << x << y <<T<<T<<T<<T<<"\n__________________________\n";

   WorTN q( "Security" );
   WorTN r( "Library" );
   cout << q << r <<T<<T<<T<<T<<"\n__________________________\n";

   BTN s( 10 );
   BTN t( 8 );
   cout << s << t <<T<<T<<T<<T<<"\n__________________________\n";

system ("pause");      
return 0;              
}                      

Uh, nobody's going to give you that data.
You've already overloaded the << operator, but if all these classes are related, try creating a wrapper to manage them all. Then overload the << operator for that new wrapper class. Or you could just write a print function that takes one of each of those objects and prints them as you desire.
Topic archived. No new replies allowed.