Online Courses
Free Tutorials  Go to Your University  Placement Preparation 
Artificial Intelligence(AI) & Machine Learning(ML) Training in Jaipur
Online Training - Youtube Live Class Link
0 like 0 dislike
4.2k views
in ASTU B.Tech (CSE-III Sem) Object Oriented Programming using C++ Lab by Goeduhub's Expert (7.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 required copies are available, the total cost of the requested copies is displayed; otherwise the message "Required copies not in stock" is displayed. Design a system in C++ using a class called “books” with suitable member functions and constructors. Use new operator in constructors to allocate memory space required.

Goeduhub's Online Courses @Udemy

For Indian Students- INR 570/- || For International Students- $12.99/-

S.No.

Course Name

Apply Coupon

1.

Tensorflow 2 & Keras:Deep Learning & Artificial Intelligence

Apply Coupon

2.

Computer Vision with OpenCV | Deep Learning CNN Projects

Apply Coupon

3.

Complete Machine Learning & Data Science with Python Apply Coupon

4.

Natural Language Processing-NLP with Deep Learning in Python Apply Coupon

5.

Computer Vision OpenCV Python | YOLO| Deep Learning in Colab Apply Coupon

6.

Complete Python Programming from scratch with Projects Apply Coupon

1 Answer

0 like 0 dislike
by Goeduhub's Expert (7.1k points)
edited by
 
Best answer

In this program we are going to create a class called "books". Data members of this class are author, title, price, publisher and stock position.

To learn about Class and Object in C++ programming Click Here.

Program :

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>

//declaration of class books
class books
{

//data members of books class
public:
char author[20];
char title[20];
char publisher[50];
int price;
int copies;
int stock;

//setData() function to set data of books
void setData()
{
cout<<"\nEnter the following details:\nAuthor's Name:";
gets(author);
cout<<"\nTitle :";
gets(title);
cout<<"\nPublisher :";
gets(publisher);
cout<<"\nPrice :";
cin>>price;
cout<<"\nNumber of copies:";
cin>>copies;
stock=1;
}

//check() function to check if a book is available or not
void check()
{
char t[20],aut[20];
int cop;
cout<<"\nEnter the following details to search for book:\n";
cout<<"\nTitle of the book:";
gets(t);
cout<<"\nEnter Author's Name :";
gets(aut);
cout<<"\nNumber of copies:";
cin>>cop;
if(strcmp(t,title) & strcmp(aut,author) & (cop<=copies))
{
cout<<"\nBook is availabe in store\nPrice = "<<cop*price;
copies-=cop;
}
else
{
cout<<"Not available";
}
}
};


void main()
{
clrscr();
books bk;
bk.setData();
bk.check();
getch();
}

Output :

Output of above program showing author, price and title


For More ASTU Object Oriented Programming Using C++ Lab Experiments Click Here

Ezoicreport this ad

Our Mentors(For AI-ML)


Sharda Godara Chaudhary

Mrs. Sharda Godara Chaudhary

An alumna of MNIT-Jaipur and ACCENTURE, Pune

NISHA (IIT BHU)

Ms. Nisha

An alumna of IIT-BHU

Related questions

0 like 0 dislike
1 answer 8.8k views
Ezoicreport this ad

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy || Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 
...