Answer to Question #272344 in C++ for Imran

Question #272344

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.

1
Expert's answer
2021-11-29T18:46:30-0500
#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();
}

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

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS