0% found this document useful (0 votes)
620 views5 pages

Bookshop C++ OOP ASSIGNMENT SPPU

The document defines a C++ class called "book" that stores data about books such as the author, title, publisher, price, and stock. It includes methods to get, edit, and display book data, as well as search for a book and buy books. The main function uses book objects in an array to manage a bookstore menu allowing the user to add, search for, edit, and buy books.

Uploaded by

Aniket Lavand
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
620 views5 pages

Bookshop C++ OOP ASSIGNMENT SPPU

The document defines a C++ class called "book" that stores data about books such as the author, title, publisher, price, and stock. It includes methods to get, edit, and display book data, as well as search for a book and buy books. The main function uses book objects in an array to manage a bookstore menu allowing the user to add, search for, edit, and buy books.

Uploaded by

Aniket Lavand
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

#include<bits/stdc++.

h>
using namespace std;
class book
{
private:
char *author,*title,*publisher;
float *price;
int *stock;
public:
book()
{
author= new char[20];
title=new char[20];
publisher=new char[20];
price= new float;
stock=new int;

void getdata()
{
cin.ignore();
cout<<"\nEnter Author Name: ";
cin.getline(author,20);

cout<<"Enter Title Name: ";


cin.getline(title,20);

cout<<"Enter Publisher Name: ";


cin.getline(publisher,20);

cout<<"Enter Price: ";


cin>>*price;
cout<<"Enter Stock Position: ";
cin>>*stock;

void editdata()
{

cout<<"\nEnter Author Name: ";


cin.getline(author,20);
cout<<"Enter Title Name: ";
cin.getline(title,20);
cout<<"Enter Publisher Name: ";
cin.getline(publisher,20);
cout<<"Enter Price: ";
cin>>*price;
cout<<"Enter Stock Position: ";
cin>>*stock;

void showdata()
{
cout<<"\nAuthor Name: "<<author;
cout<<"\nTitle Name: "<<title;
cout<<"\nPublisher Name: "<<publisher;
cout<<"\nPrice: "<<*price;
cout<<"\nStock Position: "<<*stock;

int search(char tbuy[20],char abuy[20] )


{
if(strcmp(tbuy,title)==0 && strcmp(abuy,author)==0)
return 1;
else
return 0;

void buybook()
{
int count;
cout<<"\nEnter Number Of Books to buy: ";
cin>>count;
if(count<=*stock)
{
*stock=*stock-count;
cout<<"\nBooks Bought Sucessfully";
cout<<"\nAmount: Rs. "<<(*price)*count;
}
else

cout<<"\nRequired Copies not in Stock";


}

};

int main()
{
book *B[20];
int i=0,r,t,choice;
char titlebuy[20],authorbuy[20];
while(1)
{
cout<<"\n\n\t\tMENU"
<<"\n1. Entry of New Book"
<<"\n2. Buy Book"
<<"\n3. Search For Book"
<<"\n4. Edit Details Of Book"
<<"\n5. Exit"
<<"\n\nEnter your Choice: ";
cin>>choice;

switch(choice)
{
case 1: B[i] = new book;
B[i]->getdata();
i++;
break;

case 2: cin.ignore();
cout<<"\nEnter Title Of Book: ";
cin.getline(titlebuy,20);
cout<<"Enter Author Of Book: ";
cin.getline(authorbuy,20);
for(t=0;t<i;t++)
{
if(B[t]->search(titlebuy,authorbuy))
{
B[t]->buybook();
break;
}
}
if(t==1)
cout<<"\nThis Book is Not in Stock";
break;

case 3: cin.ignore();
cout<<"\nEnter Title Of Book: ";
cin.getline(titlebuy,20);
cout<<"Enter Author Of Book: ";
cin.getline(authorbuy,20);

for(t=0;t<i;t++)
{
if(B[t]->search(titlebuy,authorbuy))
{
cout<<"\nBook Found Successfully";
B[t]->showdata();
break;
}
}
if(t==i)
cout<<"\nThis Book is Not in Stock";
break;

case 4: cin.ignore();
cout<<"\nEnter Title Of Book: ";
cin.getline(titlebuy,20);
cout<<"Enter Author Of Book: ";
cin.getline(authorbuy,20);

for(t=0;t<i;t++)
{
if(B[t]->search(titlebuy,authorbuy))
{
cout<<"\nBook Found Successfully";
B[t]->editdata();
break;
}
}
if(t==i)
cout<<"\nThis Book is Not in Stock";
break;

case 5: exit(0);
default: cout<<"\nInvalid Choice Entered";

}
}

return 0;
}

OUTPUT-

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy