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
19.5k views
in Computer by (64.1k points)

A book shop maintains the inventory of books that are being sold at the shop. The list includes details such as author, title, price, publisher and stock position. Whenever a customer wants a book, the sales person inputs the title and author and the system searches the list and displays whether it is available or not. If it is not, an appropriate message is displayed. If it is, then the system displays the book details and requests for the number of copies required. If the requested copies are available, the total cost of the required copies is displayed, otherwise the message “Sorry! These many copies are not in stock” is displayed. Design a system using a class called stock with suitable member functions and constructors.

1 Answer

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

#include<iostream.h>

#include<conio.h>

#include<stdio.h>

#include<string.h>

class stock

{

char author[50];

char title[50];

char pub[50];

double price;

int numcopies;

public:

stock();

int access_title(char a[]);

int access_author(char b[]); 

 void input();

void display();

void getdata(int);

};

stock::stock()

{

char author[50]={"abc"};

char title[50]={"efg"};

char pub[50]={"hij"};

price=500;

numcopies=50;

}

int stock::access_title(char a[])

{

if(strcmp(title,a)) return 0; else return 1;

}

int stock::access_author(char b[ ])

if(strcmp(author,b))

 return 0;

 else return 1;

}

void stock::getdata(int num)

{

 if(numcopies>=num)

 cout<<"\nCost of "<<num<<" books is Rs. "<<(price*num);

 else

 cout<<"\nSorry! These many copies are not in stock!";

}

void stock::input()

{

cout<<"\nTitle: ";

gets(title);

cout<<"\nAuthor:";

gets(author);

cout<<"\nPublisher:";

gets(pub);

cout<<"\nPrices:";

cin>>price; cout<<"\ncopies available:"; cin>>numcopies;

}

void stock::display()

{

cout<<"Title: "<<title<<end1;

cout<<"Author: "<<author<<end1;

cout<<"Publisher: "<<pub<<end1;

cout<<"Prices: "<<price<<end1;

cout<<"copies available: "<<numcopies<<end1;

}

void main()

{

 clrscr();

 stock obj[2];

 int n;

 char ttle[50];

 char auth[50];

 cout<<"Enter details of 3 books";

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

 obj[i].input();

 cout<<end1;

cout<<"\n Enter title of required book\n";

gets(ttle);

cout<<"\n Enter author of required book\n";

gets(auth);

for(i=0;i<2;i++)

{

if((obj[i].access_title(ttle))&&(obj[i].access_author(auth)))

{

obj[i].display();

cout<<"\nHow many copies? ";

cin>>n; obj[i].getdata(n);

}

else

cout<<"\nBook unavailable";

}

getch();

}

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

...