classes problem

Imagine a publishing company that markets both book and audio cassette versions of its works.
Create a class called publication that stores the title(a string) and price(a float) of a publication. From this class derive two classes:book class, which contains a page count (type int); and tape class, which contains playing time(type int) in minutes. Each of these classes should have getdata() function to get its data from the user, and a putdata() function to display its data.

write a main () function to test the book and tape classes by creating instances of them, asking the user to fill data with getdata(), and the displaying the data with putdata() through menus.

write a main ()function that displays a menu as below.

main menu: a) enter data
b)view data
c) exit

after taking the option for 'a' and 'b' options, another menu is to be displayed as data item is book/tape(b/T):

make program is attached below please correct the problem i am having.

#include <iostream>
#include <string>
using namespace std;

class publication
{
private:
string title;
float price;

public:
publication(); //constructor
void getData()
{
system ("cls");
cout<<"\nEnter the title:";
getline(cin,title);

cout<<"Enter the price:";
cin>>price;
}

void putData()const
{
system ("cls");
cout<<"The Title:"<<title;
cout<<"The Price:"<<price;
}
};

class book: public publication
{
private:

int pCount;

public:
book();
void getData()
{
cout<<"Enter number of pages:";
cin>> pCount;
}
void putData()
{
cout<<"The total number of pages:"<<pCount;
}
};

class tape: public publication
{
private:
int playTime;
public:
tape();
void getData()
{
cout << "Play time in minutes: ";
cin >> playTime;
}
void putData() const
{
cout << "\nPlaying time: " << playTime;
}

};

int main()
{
book playbook;
tape playtape;
char choice;

//set data
cout << "\nBOOK\n";
cout << "=====\n";
playbook.publication::getData();
playbook.book::getData();
getchar();

cout << "\nTAPE\n";
cout << "=====\n";
playtape.publication::getData();
playtape.tape::getData();


//output data according to choice
cout << "\n\nDISPLAY MENU\n";
cout << "------------\n";
cout << "1 - Book\n";
cout << "2 - Tape\n";
cout << "\nAny other key to Exit==>";

getchar(); //buffer
choice = getchar();

if (choice == '1'){ //display book info
playbook.publication::putData();
playbook.book::putData();
}
else
if (choice == '2'){ //display tape info
playtape.publication::putData();
playtape.tape::putData();
}
else
cout << "\n\nGoodbye!";

cout << endl << endl;
system("pause");
return 0;
}

make program is attached below please correct the problem i am having.
What problem?

Be more specific and please use [code][/code] tags when posting code.
Last edited on
I don't know what the problem is, but the system("pause") and system("cls") lines could be compromised which could delete your system32.
Topic archived. No new replies allowed.