Answer to Question #276010 in C++ for Asim

Question #276010

Start with the publication, book, and tape classes. Add a 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 sales


amounts from the user, and a putdata() function to display the sales figures. Alter the


book and tape classes so they are derived from both publication and sales. An object


of class book or tape should input and output sales data along with its other data. Write


a main() function to create a book object and a tape object and exercise their input/output


capabilities.

1
Expert's answer
2021-12-06T05:30:04-0500
#include <iostream>
#include <string>
#include <conio.h>
using ​namespace std;
class publication
{
private:
​string title;
​float price;
public:
​void getdata(void)
​{
 ​string t;
 ​float p;
 ​cout << "Enter title of publication: ";
 ​cin >> t;
 ​cout << "Enter price of publication: ";
 ​cin >> p;
 ​title = t;
 ​price = p;
​}
​void putdata(void)
​{
 ​cout << "Publication title: " << title << endl;
 ​cout << "Publication price: " << price << endl;
​}
};
class sales
{
private:
​float s1, s2, s3;
public:
​void getdata(void)
​{
 ​cout << "Enter month 1 sale: $";
 ​cin >> s1;
 ​cout << "Enter month 2 sale: $";
 ​cin >> s2;
 ​cout << "Enter month 3 sale: $";
 ​cin >> s3;
​}
​void putdata(void)
​{
 ​cout << "Month 1 sale: $" << s1 << endl;
 ​cout << "Month 2 sale: $" << s2 << endl;
 ​cout << "Month 3 sale: $" << s3 << endl;
​}
};
class book :public publication,public sales
{
private:
​int pagecount;
public:
​void getdata(void)
​{
 ​publication::getdata();
 ​sales::getdata();
 ​cout << "Enter Book Page Count: ";
 ​cin >> pagecount;
​}
​void putdata(void)
​{
 ​publication::putdata();
 ​sales::putdata();
 ​cout << "Book page count: " << pagecount << endl;
​}
};
class tape :public publication,public sales
{
private:
​float ptime;
public:
​void getdata(void)
​{
 ​publication::getdata();
 ​sales::getdata();
 ​cout << "Enter tap's playing time: ";
 ​cin >> ptime;
​}
​void putdata(void)
​{
 ​publication::putdata();
 ​sales::putdata();
 ​cout << "Tap's playing time: " << ptime << endl;
​}
};
void main(void)
{
​book b;
​tape t;
​b.getdata();
​t.getdata();
​b.putdata();
​t.putdata();
​_getch();

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment