Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

You must login to add post.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

mcqoptions.com

mcqoptions.com Logo mcqoptions.com Logo

mcqoptions.com Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 344119
Next
In Process
Ekbal Chandra Kara
Ekbal Chandra Kara
Asked: 3 years ago2022-11-09T17:40:10+05:30 2022-11-09T17:40:10+05:30In: Pointers

Imagine a publishing company that markets both books and audio-cassette versions of its works. Create a class called Publication that stores the title (a string) and price 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 class 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 a object of type Book or Tape to hold the data. Put the pointer to the object in the data for all books and tapes, display the resulting data for all the books and taps entered, using a for loop and a single statement such as

pubarr[i]->putdata();

to display the data from each object in the array.

Imagine a publishing company that markets both books and audio-cassette versions of its works. Create a class called Publication that stores the title (a string) and price 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 class 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 a object of type Book or Tape to hold the data. Put the pointer to the object in the data for all books and tapes, display the resulting data for all the books and taps entered, using a for loop and a single statement such as

pubarr[i]->putdata();

to display the data from each object in the array.

Waves
  • 0
  • 11
  • 4
  • 0
  • 0
    • Report
  • Share
    • Share on Facebook
    • Share on Twitter
    • Share on LinkedIn
    • Share on WhatsApp
Leave an answer

Leave an answer
Cancel reply

Browse

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 1cf0b
    2022-10-31T09:57:43+05:30Added an answer about 3 years ago

    #include<iostream.h>

    #include<string.h>

    class Publication

    {

    private:

     char title[20];

     float price;

    public:

     void getName()

     {

    cout<<“Enter Title: “; cin>>title;

    cout<<“Enter Price: $”; cin>>price;

     }

     void putName()

     {

    cout<<“\nTitle: “<<title;

    cout<<“, Price: $”<<price;

     }

     virtual void getData() = 0;

    };

    class Book : public Publication

    {

    private:

     int pages;

    public:

     void getData()

     {

     Publication::getName();

    cout<<“Enter Pages: “; cin>>pages;

     }

     void putData()

     {

     Publication::putName();

    cout<<“, Pages: “<<pages<<end1;

     }

    };

    class Tape : public Publication

    {

    private:

     float minutes;

    public:

     void getData()

     {

     Publication::getName();

    cout<<“Enter Minutes: “; cin>>minutes;

     }

     void putData()

     {

     Publication::putName();

    cout<<“, Minutes: “<<minutes<<end1;

     }

    };

    int main()

    {

     Publication* ptrPub[100];

     int n = 0;

     char choice;

     do

     {

    cout<<“Book or Tape? (b/t): “; cin>>choice;

    if(choice == ‘b’)

     { ptrPub[n] = new Book; ptrPub[n]->getData(); }

     else

     { ptrPub[n] = new Tape; ptrPub[n]->getData(); }

    n++; cout<<“Enter another? (y/n): “; cin>>choice;

     } while(choice == ‘y’);

     for(int i=0; i<n; i++)

     ptrPub[i]->putName();

     cout<<end1;

     return 0;

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
Yasmin Gajendra Nagar
Yasmin Gajendra Nagar
Asked: 3 years ago2022-11-01T12:06:46+05:30 2022-11-01T12:06:46+05:30In: Inheritance

Imagine a publishing company that markets both books and audio-cassette versions of its works. Create a class publication that stores the title (a string) ad 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 their data with getdata(), and then displaying the data with putdata().

Imagine a publishing company that markets both books and audio-cassette versions of its works. Create a class publication that stores the title (a string) ad 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 their data with getdata(), and then displaying the data with putdata().

Philosophy
  • 0
  • 11
  • 0
  • 0
  • 0
    • Report
  • Share
    • Share on Facebook
    • Share on Twitter
    • Share on LinkedIn
    • Share on WhatsApp
Leave an answer

Leave an answer
Cancel reply

Browse

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 301ce
    2022-11-05T23:12:54+05:30Added an answer about 3 years ago

    #include <iostream.h>

    #include<conio.h>

    #include<stdio.h>

    class publication

    {

    char title[20];

    float price;

    public: void getdata()

    {

    cout<<“Enter title: “; gets(title);

    cout<<“Enter price: “; cin>>price;

    }

    void putdata()

    {

    cout<<“Title: “<>page_count;

    }

    void putdata()

    { publication::putdata();

    cout<<“Page count: “<<page_count<<endl;

    }

    };

    class tape:public publication

    {

    float play_time;

     public:

    void getdata()

    { publication::getdata();

    cout<<“Enter Play time: “;

    cin>>play_time;

    }

    void putdata()

    { publication::putdata();

    cout<<“Play time: “<<play_time<<endl;

    }

    };

    void main()

    {  clrscr();

    book b;

    tape t;

    b.getdata();

    b.putdata(); 

    t.getdata();

    t.putdata();

    getch();\

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 500k
  • Answers 393k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Aditi Dugal

    How to approach applying for a job at a company ...

    • 7 Answers
  • Raghavan Prasad Hayer

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Ankita Dinesh Biswas

    What is a programmer’s life like?

    • 5 Answers
  • 47e0c
    47e0c added an answer Correct Answer - Increasing the yield of animals and improving… November 12, 2022 at 9:56 am
  • b6699
    b6699 added an answer Sender\'s addressDateReceivers name and addressSubjectContentYours faithfullyName November 12, 2022 at 9:56 am
  • 10eb8
    10eb8 added an answer Any uncertinity in measurment is known as errorDifference in true… November 12, 2022 at 9:56 am

Related Questions

  • C++ lets you pass a structure by value ...

    • 1 Answer
  • Write a function having this prototype:

    • 1 Answer
  • What is the advantage of passing arguments ...

    • 1 Answer
  • Suppose 7 names are stored in a ...

    • 1 Answer
  • Write a function substr() that will scan ...

    • 1 Answer

Top Members

Trending Tags

Class 11 Parabola Polity Polynomials Probability Projectile Protists Quadrilaterals Rario Reasoning Sampling Social Solutions Spectroscopy Switchgear Thermodynamic Tourism Transients Upsc Wbjee

Explore

  • Home
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Tags
  • Badges
  • Users

Footer

mcqoptions.com

About

MCQOptions.com

Here are the top interview questions, example answers, tips for giving the best response.

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Follow

© 2022 MCQOptions. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.