Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
69.2k views
in Computer by (64.1k points)

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().

1 Answer

+1 vote
by (69.4k points)
selected by
 
Best answer

#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();\

}

by (10 points)
class Publication
{
String Title;
float Price;
Scanner sc= new Scanner(System.in);

public void  getdata( )
{

System.out.println("Enter the Title:") ;
Title = sc.nextLine();
System.out.println("Enter the Price:") ;
Price = sc.nextFloat();
}
public void putdata()
{
System.out.println("Title:"+Title);
System.out.println("Price:"+Price);
}
}
class Book extends Publication
{
int page_count;

public void disp()
{
System.out.println("Enter Book Details");
}
public void getdata()
{
super.getdata();//call publication class function to get data
System.out.println("Enter Book Page Count") ;
page_count = sc.nextInt();
}
void show()
{
System.out.println("Details of Book is:");
}
public void putdata()//call publication class function to put data
{
super.putdata();
System.out.println("Page_count:"+page_count);
}
}
class Tape extends Publication
{
float playing_time;
public void disp()
{
System.out.println("Enter Tape Details:");
}
public void getdata()
{

super.getdata();//call publication class function to get data
System.out.println("Enter Playing time OF Tape:") ;
playing_time = sc.nextFloat();
}
void show()
{
System.out.println("Details of Tape is:");
}
public void putdata()//call publication class function to put data
{
super.putdata();
System.out.println("Playing_Time:"+playing_time);
}
}
public class Publication2 {
public static void main(String[] args) {
Book obj1=new Book();
Tape obj2=new Tape();
obj1.disp();
obj1.getdata();
obj2.disp();
obj2.getdata();
obj1.show();
obj1.putdata();
obj2.show();
obj2.putdata();
}}

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...