473,395 Members | 1,443 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

calling derived class objects simultaneously

"Close but no cigar" This code does everything great until the end where for many days I have been trying to maintain the current outputs but somehow add a display where WorTN q and Tnum x print together followed by WorTN q, Tnum x and BTN s printing together. Also, where WorTN r and Tnum y print together followed by WorTN r, Tnum y and BTN t printing together. Something like:

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


Any solution i.e... pointers etc. would be better than not getting 'er' done. Please advise. Thanks ~LS
Expand|Select|Wrap|Line Numbers
  1.  
  2. // W I P_2                   //Tnum.h interface 
  3.  
  4. #include <iostream>        
  5. #include <string>
  6. #include <cstring>
  7. using namespace std;      
  8.  
  9. class Tnum {               
  10.  
  11. public:                
  12.     string NPA, NXX, LINE, P_NUM;
  13.  
  14.     Tnum( ) {cout <<"\n Tnum default constructor proof\n";}
  15.  
  16.     Tnum( string a,string b,string c );
  17.  
  18.     void ph_num( );
  19.  
  20.    ~Tnum( );
  21.  
  22.     string GetNPA( ) const { return NPA; }
  23.     void SetNPA( string g ) { NPA = g; }
  24.  
  25.     string GetNXX( ) const { return NXX; }
  26.     void SetNXX( string h ) { NXX = h; }
  27.  
  28.     string GetLINE( ) const { return LINE; }
  29.     void SetLINE( string i ) { LINE = i; } 
  30. };
  31.  
  32. Tnum::Tnum( string a,string b,string c ) {
  33.  
  34.     NPA  = a;
  35.     NXX  = b;
  36.     LINE = c;
  37.     P_NUM = NPA + NXX + LINE;  }
  38.  
  39. void Tnum::ph_num( ) {
  40.  
  41.     cout <<" \n Tnum parameterized constructor proof\n\n Type 3 digit area code then press 'ENTER' key  ";
  42.     cin >> NPA;
  43.  
  44.     cout <<" \n Type 3 digit prefix then press 'ENTER' key  ";
  45.     cin >> NXX;
  46.  
  47.     cout <<" \n Type 4 digit line number then press 'ENTER' key  ";
  48.     cin >> LINE;
  49.  
  50.     P_NUM = NPA + NXX + LINE; cout <<" \n Telephone no#: "<< P_NUM <<"\n"; }       
  51.  
  52. Tnum::~Tnum( ) {
  53.  
  54.     cout <<" \n Tnum destructor fx flushed object containing variable value "<< P_NUM <<"\n\n_________________________________________________________________________"<<endl;}
  55.  
  56. //________________________________________________
  57.  
  58.                                //WorTN.h interface                              
  59.  
  60. class WorTN : public Tnum { 
  61.  
  62. public:
  63.    string CustName;    
  64.  
  65.    WorTN( ) {cout <<"\n WorTN default constructor proof\n";}
  66.  
  67.    WorTN( string d );
  68.  
  69.    void cust_num( );
  70.  
  71.    ~WorTN( );
  72.  
  73.    string GetCustName( ) const { return CustName; }
  74.    void SetCustName( string j ) { CustName = j; }
  75. };
  76.  
  77. WorTN::WorTN( string d ) { CustName = d; }
  78.  
  79. void WorTN::cust_num( ) {
  80.  
  81.    cout << " \n WorTN parameterized constructor proof\n\n Type customer name then press 'ENTER' key  ";
  82.  
  83.    cin >> CustName; cout <<" \n Customer name: "<< CustName <<endl;  }
  84.  
  85. WorTN::~WorTN( ) {
  86.  
  87.    cout <<" \n WorTN destructor fx flushed object containing variable value "<< CustName <<"\n\n_________________________________________________________________________"<<endl;}
  88.  
  89.  
  90. //____________________________________________________________________________
  91.  
  92.                                //BTN.h interface                              
  93.  
  94. class BTN : public WorTN { 
  95.  
  96. public:
  97.    int NumWrkLines;
  98.  
  99.    BTN( ) {cout <<"\n BTN default constructor proof\n";}
  100.  
  101.    BTN( int e );
  102.  
  103.    void cust_num_lines( );
  104.  
  105.   ~BTN( );
  106.  
  107.    int GetNumWrkLines( ) const { return NumWrkLines; }
  108.    void SetNumWrkLines( int k ) { NumWrkLines = k; }
  109. };
  110.  
  111. BTN::BTN( int e ) { NumWrkLines = e; }     
  112.  
  113. void BTN::cust_num_lines( ) { 
  114.  
  115.    cout << " \n BTN parameterized constructor proof\n\n Type number of lines then press 'ENTER' key  ";
  116.    cin >> NumWrkLines;
  117.  
  118.    cout <<" \n No# of lines: "<< NumWrkLines <<endl;  }
  119.  
  120. BTN::~BTN( ) {
  121.  
  122.    cout <<" \n BTN destructor fx flushed object containing variable value "<< NumWrkLines <<"\n\n_________________________________________________________________________"<<endl;}
  123.  
  124. //___________________________________________________________________________________
  125.  
  126.                        //Tnum_main.cpp utilization
  127.  
  128. ostream &operator<<(ostream &print1, Tnum m) {
  129.    print1 << "\n Telephone no#: (" << m.NPA << ") ";
  130.    print1 << m.NXX << "-" << m.LINE << "\n";   
  131.    return print1; }
  132.  
  133. ostream &operator<<(ostream &print2, WorTN n) {
  134.    print2 << "\n Customer: "<< n.CustName << "\n";
  135.    return print2; }
  136.  
  137. ostream &operator<<(ostream &print3, BTN o) {
  138.    print3 << "\n No# phone lines: "<< o.NumWrkLines << "\n"; 
  139.    return print3; }
  140.  
  141. ostream& T( ostream& p ) { return p <<'\a'; }   
  142.  
  143. int main( ) {
  144.  
  145.    Tnum xx;     xx.ph_num( );          xx.~Tnum( ); 
  146.    WorTN yy;    yy.cust_num( );        yy.~WorTN( );
  147.    BTN zz;      zz.cust_num_lines( );  zz.~BTN( );
  148.  
  149.    Tnum x( "(312) ","777-","1111" );
  150.    Tnum y( "(312) ","444-","2222" );
  151.    cout << x << y <<T<<T<<T<<T<<"\n__________________________\n";
  152.  
  153.    WorTN q( "Security" );
  154.    WorTN r( "Library" );
  155.    cout << q << r <<T<<T<<T<<T<<"\n__________________________\n";
  156.  
  157.    BTN s( 10 );
  158.    BTN t( 8 );
  159.    cout << s << t <<T<<T<<T<<T<<"\n__________________________\n";
  160.  
  161. system ("pause");     
  162. return 0;             
  163. }                     
Feb 1 '10 #1
3 1505
Your question is not understandable, please explain in detail
Feb 1 '10 #2
weaknessforcats
9,208 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. int main( ) { 
  2.  
  3.    Tnum xx;     xx.ph_num( );          xx.~Tnum( );  
  4.    WorTN yy;    yy.cust_num( );        yy.~WorTN( ); 
  5.    BTN zz;      zz.cust_num_lines( );  zz.~BTN( ); 
Why are you calling destructors? These functions are there for the compiler to call and not you. What you are doing is trashing the objects you have just created.

All you need is:

Expand|Select|Wrap|Line Numbers
  1. int main( ) { 
  2.  
  3.    Tnum xx;
  4.    WorTN yy; 
  5.    BTN zz;  
Feb 1 '10 #3
Thank you 'weaknessforcats' - i will give that a whirl
Feb 1 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Matthew Bell | last post by:
Hi, I've got a question about whether there are any issues with directly calling attributes and/or methods of a threaded class instance. I wonder if someone could give me some advice on this. ...
4
by: Brad Kartchner | last post by:
I'm attempting to write a program with several child classes derived from a single parent class. The parent class has a couple of variables that need to be present in each of the child classes. ...
9
by: justanotherguy63 | last post by:
Hi, I am designing an application where to preserve the hierachy and for code substitability, I need to pass an array of derived class object in place of an array of base class object. Since I...
4
by: Gibby Koldenhof | last post by:
Hiya, I'm setting up some code in the spirit of Design Patterns, OOP, etc. All nice and well, it handles pretty much all OO style things and serves my purposes well. There's one last final...
3
by: acg | last post by:
If you have a class with a public method, and another class which will want to call this method, is there a way to determine the type of the calling class within the method being called? For I...
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
8
by: Kannan | last post by:
Some amount of memory is allocated inside the Base Constructor using new. During the construction of a derived object an exception occurred in the constructor of the derived class. Will the...
2
by: Raider | last post by:
I have class hierarchy with virtual methods like this: class Base { public: virtual void Show(); ~Base(); }; class Derived : public Base
6
by: Rick | last post by:
Hi, Can anyone explain to me why the below fails to compile - seeing otherA->f(); as a call to a inaccessible function, while otherB->f(); is ok? It seems you can happily access protected...
10
by: Dom Jackson | last post by:
I have a program which crashes when: 1 - I use static_cast to turn a base type pointer into a pointer to a derived type 2 - I use this new pointer to call a function in an object of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.