Home > C++ > Inheritance , Classroom Exercise, NIIT student

Inheritance , Classroom Exercise, NIIT student

Create a class called publication that store the title ( a string ) and price ( type float ) of a publication. From this class, derive two class: book which adds a page count ( type int ); and tape , which adds a playing time (type int ) in minutes. Each of these classes should have a getdata() function to get its data from the user, and a putdata() to display its data.

//———————————————————

#include
using namespace std;
class publication
{
private:
char title[50] ;
float price;
public:
void getdata()
{
cout << " Enter publication title : " ; cin >> title;
cout << " Enter publication price : " ; cin >> price;
}

void putdata()
{
cout << " Publication title : " << title << endl; cout << " Publication price : " << price << endl; } }; // end of class publication class book : public publication { private: int pageCount ; public: void getdata() { publication::getdata(); cout << " Enter page count : " ; cin >> pageCount;
}
void putdata()
{
publication::putdata();
cout << " Page count : " << pageCount ; cout << endl; } }; class tape : public publication { private: int playingtime; public: void getdata() { publication::getdata(); cout << " Enter page count : "; cin >> playingtime;
}
void putdata()
{
publication::putdata();
cout << " Playing time : " << playingtime; cout << endl; } }; int main(int argc, char** argv) { book mybook; tape mytape; // get the book data mybook.getdata(); mybook.putdata(); // get the tape data mytape.getdata(); mytape.putdata(); return (EXIT_SUCCESS); } [/sourcecode] .. That what i've done with the exercise ...

Categories: C++
  1. steerapong
    July 10, 2008 at 6:12 pm

    May be there are those who have a good idea than this , share it

  2. January 7, 2009 at 6:20 pm

    NIITer.com is a Community website specially dedicated to NIIT Students from all around the world. All the NIIT Students are welcome to join NIITer and have some fun with your friends. By joining to NIITer you can make new friends also.

    NIITer.com
    NIIT Student Community
    Be more Socialized!

  1. No trackbacks yet.

Leave a comment