Home > C++ > The publication, book and tape classes , more advance….

The publication, book and tape classes , more advance….

Add another base class sales that holds and array of three floats it can record the sales of a particular publication for the last three months. Include getdata() function to get three sales amounts from the user , and a putdata() function to display the sales figures. Alter the book and tape classes so that they are derived from both publication and sales. An object of class book or tape should input or output sales along with its other data.

#include
using namespace std;

class sale
{
private:
float salerec[3];
public:
void getdata()
{
cout << " Enter the sales for the last three months :" << endl; for (int i = 0; i < 3 ; i++) { cout << " Enter sales for month : " << i+1 << " > “;
cin >> salerec[i];
}
}
void putdata()
{
cout << " The sale of the last three month " << endl; for(int i=0; i < 3; i++) { cout << " Month no : " << i+1 << " > ” << salerec[i] << endl; } } }; class publication { private: char title[50] ; float price; public: void getdata() { cout << " Enter publication title : " ; cin >> title;
cout << " Enter publication price : " ; cin >> price;
}

void putdata()
{
cout << " Publication title : " << title << endl; cout << " Publication price : " << price << endl; } }; // end of class publication class book : public publication, public sale { private: int pageCount ; public: void getdata() { publication::getdata(); cout << " Enter page count : " ; cin >> pageCount;
sale::getdata();
}
void putdata()
{
publication::putdata();
cout << " Page count : " << pageCount ; cout << endl; sale::putdata(); } }; class tape : public publication , public sale { private: int playingtime; public: void getdata() { publication::getdata(); cout << " Enter page count : "; cin >> playingtime;
sale::getdata();
}
void putdata()
{
publication::putdata();
cout << " Playing time : " << playingtime; cout << endl; sale::putdata(); } }; int main(int argc, char** argv) { book mybook; //tape mytape; // get the book data mybook.getdata(); //mybook.sale::getdata(); mybook.putdata(); //mybook.sale::putdata(); // get the tape data //mytape.getdata(); //mytape.putdata(); return (EXIT_SUCCESS); } [/sourcecode]

Categories: C++
  1. steerapong
    July 10, 2008 at 6:30 pm

    Something simple 😦

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: