Start with the publication, book and tape classes. Add base class sales that holds an
array of three floats so that it can record the dollar sales of a particular publication for
the last three months. Include a getdata() function to get three sale amount from the
user and a putdata() function to display the sales figure.
Alter the book and tape classes, so they are derived from both publication and sales.
An object of book or tape should should input and output ans sales data along with
other data.
Write a main function to create a book and tape object and exercise their input/output
capabilities.
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
class publication
{
public:
string publication_title;
float publication_price;
void getdata()
{
string titl;
float pub;
cout << "Enter publication title : ";
cin >> titl;
cout << "Enter publication price: ";
cin >> pub;
publication_title = titl;
publication_price = pub;
}
void putdata()
{
cout << "Publication title is : " << publication_title << endl;
cout << "Publication price is : " << publication_price << endl;
}
};
class sales
{
public:
float sale1, sale2, sale3;
void getdata()
{
cout << "Enter sale 1: $";
cin >> sale1;
cout << "Enter sale 2 : $";
cin >> sale2;
cout << "Enter sale 3 : $";
cin >> sale3;
}
void putdata(void)
{
cout << "Sale 1: "<<sale1 <<" $"<< endl;
cout << "Sale 2 : " <<sale2<<" $" << endl;
cout << "Sale 3: "<<sale3<<" $" << endl;
}
};
class book :public publication,public sales
{
public:
int page;
void getdata()
{
publication::getdata();
sales::getdata();
cout << "Input Book Page Count: ";
cin >> page;
}
void putdata()
{
publication::putdata();
sales::putdata();
cout << "Page count is : " << page<< endl;
}
};
class tape : public publication,public sales
{
public:
float playing_time;
void getdata(void)
{
publication::getdata();
sales::getdata();
cout << "Enter the playing time of the tape: ";
cin >> playing_time;
}
void putdata(void)
{
publication::putdata();
sales::putdata();
cout << "Tap's playing time: " << playing_time << endl;
}
};
int main()
{
book bk;
tape tp;
bk.getdata();
tp.getdata();
bk.putdata();
tp.putdata();
_getch();
}
Comments
Leave a comment