Problem Statement:
Imagine a publishing company that markets both book and audiocassette versions of its
works. Create a class publication that stores the title (a string) and price (type float)
of a publication. From this class derive two classes: book, which adds a page count (type
int), and tape, which adds a playing time in minutes (type float). Each of these three
classes should have a getdata() function to get its data from the user at the keyboard,
and a putdata() function to display its data.
Write a main() program to test the book and tape classes by creating instances of them,
asking the user to fill in data with getdata(), and then displaying the data with putdata().
Solution:
//Ahmad Furqan
//P9.1
#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 book :public publication
{
private:
int pagecount;
public:
void getdata(void)
{
publication::getdata(); //call publication class function to get data
cout << "Enter Book Page Count: "; //Acquire book data from user
cin >> pagecount;
}
void putdata(void)
{
publication::putdata(); //Show Publication data
cout << "Book page count: " << pagecount << endl; //Show book data
}
};
class tape :public publication
{
private:
float ptime;
public:
void getdata(void)
{
publication::getdata();
cout << "Enter tap's playing time: ";
cin >> ptime;
}
void putdata(void)
{
publication::putdata();
cout << "Tap's playing time: " << ptime << endl;
}
};
void main(void)
{
book b;
tape t;
b.getdata();
t.getdata();
b.putdata();
t.putdata();
_getch();
}
Sir thank you very much for helping me a lot.May God bless you with your aim of life
ReplyDeleteRun?
Deletebilal is very pretty ..
ReplyDeleteget lost
Deletethanks sir
ReplyDeleteThank you sir
ReplyDeleteConsider the question and enhance the program as:
ReplyDeletea) Augment the time class to include overloaded increment (++) and decrement (--) operators that operate in both prefix and postfix notation and return values. Add statements to main() to test these operators.
b) Add to the time class the ability to subtract two time values using the
overloaded (-) operator, and to multiply a time value by a number of type float, using
the overloaded (*) operator.
I also want the answer of this question
DeleteThis comment has been removed by the author.
Deletemuhammad tayyab plz give me the answer of this above question that u removed..
Deleteneed this one
Deletethanks
ReplyDeleteImagine the same publishing company described in Chapter 9 that markets both book and
ReplyDeleteaudiocassette versions of its works. As in that exercise, create a class called publication that
stores the title (a string) and price (type float) of a publication. From this class derive two
classes: book, which adds a page count (type int); and tape, which adds a playing time in
minutes (type float). Each of the three classes should have a getdata() function to get its data
from the user at the keyboard, and a putdata() function to display the data.
Write a main() program that creates an array of pointers to publication. In a loop, ask the
user for data about a particular book or tape, and use new to create an object of type book
or tape to hold the data. Put the pointer to the object in the array. When the user has finished
entering the data for all books and tapes, display the resulting data for all the books and
tapes entered, using a for loop and a single statement such as
pubarr[j]->putdata();
to display the data from each object in the array.
plese solve this
solution of this problem ???
DeleteFrom this class derive two classes: book, which adds a page count (type int), and DVD, which adds a playing time (type float). Each of these three classes should have a getdata() function to get its data from the user, and a putdata() function to display its data. Class book contains some classified/important data and you have to make sure that no one is able to accidently modify this class.
ReplyDeletesir isme void main(void) main error arha hai after run
ReplyDeleteREPLACE void WITH int
Deletei.e int main()
sir isme void main(void) main error arha hai after run
ReplyDeleteSir so nice of you your blog writting helped me alot . all paid wedsite have the answer of this question but here i got it , without any cost
ReplyDeletekeep up this work
Thanks Sir G Bari bari mehrbani bundle of thanks
ReplyDeleteThank You so Much Sir
ReplyDeletebhi nai ati to na kia kro ya kia chus mari ha app na
ReplyDeleteGood answer i really appreciate the autor
ReplyDelete