Menu

Thursday, 14 May 2015

Chapter 9,Problem 1:OOP by Robert Lafore


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();
}

23 comments:

  1. Sir thank you very much for helping me a lot.May God bless you with your aim of life

    ReplyDelete
  2. Consider the question and enhance the program as:
    a) 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.

    ReplyDelete
    Replies
    1. I also want the answer of this question

      Delete
    2. This comment has been removed by the author.

      Delete
    3. muhammad tayyab plz give me the answer of this above question that u removed..

      Delete
  3. Imagine the same publishing company described in Chapter 9 that markets both book and
    audiocassette 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

    ReplyDelete
    Replies
    1. solution of this problem ???

      Delete
  4. From 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.

    ReplyDelete
  5. sir isme void main(void) main error arha hai after run

    ReplyDelete
  6. sir isme void main(void) main error arha hai after run

    ReplyDelete
  7. Sir 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
    keep up this work

    ReplyDelete
  8. Thanks Sir G Bari bari mehrbani bundle of thanks

    ReplyDelete
  9. Faryad Khokahr20 May 2021 at 20:46

    Thank You so Much Sir

    ReplyDelete
  10. bhi nai ati to na kia kro ya kia chus mari ha app na

    ReplyDelete
  11. Good answer i really appreciate the autor

    ReplyDelete