//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
//author:rushikesh sanjay palke
//class : SE comp
//roll no: 237
//subject: object oriented programming
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
/*
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 book details and requests for the number of copies required. If the requested 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 using a class called books with suitable member functions and Constructors. Use new operator in constructors to allocate memory space required. Implement C++ program for the system.
*/
#include <iostream>
#include<string>
#include<cstring>
#include <iomanip>
using namespace std;
typedef struct b_shop
{
char author[20],title[20],pub[20];
int price,copies;
}b_shop;
class bookshop
{
int sum,count;
b_shop *B;
public:
bookshop()
{
B=new b_shop[1000];
sum=0;count=0;
}
void initial()
{
char ch;
cout<<"\n\nEnter Author of Book:-";
cin>>B[count].author;
cout<<"Enter Title of Book:-";
cin>>B[count].title;
cout<<"Enter Publication of Book:-";
cin>>B[count].pub;
cout<<"Enter Price of Book:-";
cin>>B[count].price;
cout<<"Enter no. of copies of Book:-";
cin>>B[count].copies;
sum=sum+B[count].copies*B[count].price;
count++;
}
int search()
{
char author[20],title[20];
cout<<"Enter Book title and its Author name respectively to Search in stock\n";
cin>>title>>author;
for(int i=0;i<count;i++)
{
int j=strcmp(B[i].title,title);
int k=strcmp(B[i].author,author);
if(!j&&!k)
{
cout<<"\n\nBook is In Stock\n";
cout<<"It Cost Rs "<<B[i].price<<endl;
return i;
}
}
cout<<"\n\nSEARCH IS NOT IN STOCK\n";
return 0;
}
void display()
{
cout<<setw(10)<<"Book Title"<<setw(25)<<"Author of Book"<<setw(25)<<"Publication"<<setw(20)<<"Price"<<setw(10)<<"Copies"<<endl<<endl;
for(int i=0;i<45;i++)
cout<<"=*";
cout<<endl;
for(int i=0;i<count;i++)
{
cout<<setw(10)<<B[i].title<<setw(25)<<B[i].author<<setw(25)<<B[i].pub<<setw(20)<<B[i].price<<setw(10)<<B[i].copies<<endl;
}
}
void stock()
{
cout<<"\n\n\n\tTotal Number of Books in Stock is "<<count<<endl;
cout<<"\tPurchase Price of Total Stock is "<<sum<<endl;
}
void purchase()
{
int copies;
int i=search();
if(i!=0)
{
cout<<"enter no of copies you want to purcase: ";
cin>>copies;
if(B[i].copies>copies)
{
cout<<"copies are available\n";
B[i].copies=B[i].copies-copies;
}
else
cout<<copies<<" are not available\n";
}
}
};
int main()
{
int c;
char ch;
bookshop o;
do
{
cout<<"^^^^^^^^^^^BookStore^^^^^^^^^^^^\n";
cout<<"1]New entry\n";
cout<<"2]Display\n";
cout<<"3]search book\n";
cout<<"4]Purchase book\n";
cout<<"5]stock\n";
cout<<"6]Exit\n";
cin>>c;
switch(c)
{
case 1:
o.initial();
break;
case 2:
o.display();
break;
case 3:
o.search();
break;
case 4:
o.purchase();
break;
case 5:
o.stock();
break;
case 6:
break;
}
cout<<"do you want to continue(y/n): ";
cin>>ch;
}while(ch=='y'||ch=='Y');
return 0;
}
//author:rushikesh sanjay palke
//class : SE comp
//roll no: 237
//subject: object oriented programming
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
/*
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 book details and requests for the number of copies required. If the requested 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 using a class called books with suitable member functions and Constructors. Use new operator in constructors to allocate memory space required. Implement C++ program for the system.
*/
#include <iostream>
#include<string>
#include<cstring>
#include <iomanip>
using namespace std;
typedef struct b_shop
{
char author[20],title[20],pub[20];
int price,copies;
}b_shop;
class bookshop
{
int sum,count;
b_shop *B;
public:
bookshop()
{
B=new b_shop[1000];
sum=0;count=0;
}
void initial()
{
char ch;
cout<<"\n\nEnter Author of Book:-";
cin>>B[count].author;
cout<<"Enter Title of Book:-";
cin>>B[count].title;
cout<<"Enter Publication of Book:-";
cin>>B[count].pub;
cout<<"Enter Price of Book:-";
cin>>B[count].price;
cout<<"Enter no. of copies of Book:-";
cin>>B[count].copies;
sum=sum+B[count].copies*B[count].price;
count++;
}
int search()
{
char author[20],title[20];
cout<<"Enter Book title and its Author name respectively to Search in stock\n";
cin>>title>>author;
for(int i=0;i<count;i++)
{
int j=strcmp(B[i].title,title);
int k=strcmp(B[i].author,author);
if(!j&&!k)
{
cout<<"\n\nBook is In Stock\n";
cout<<"It Cost Rs "<<B[i].price<<endl;
return i;
}
}
cout<<"\n\nSEARCH IS NOT IN STOCK\n";
return 0;
}
void display()
{
cout<<setw(10)<<"Book Title"<<setw(25)<<"Author of Book"<<setw(25)<<"Publication"<<setw(20)<<"Price"<<setw(10)<<"Copies"<<endl<<endl;
for(int i=0;i<45;i++)
cout<<"=*";
cout<<endl;
for(int i=0;i<count;i++)
{
cout<<setw(10)<<B[i].title<<setw(25)<<B[i].author<<setw(25)<<B[i].pub<<setw(20)<<B[i].price<<setw(10)<<B[i].copies<<endl;
}
}
void stock()
{
cout<<"\n\n\n\tTotal Number of Books in Stock is "<<count<<endl;
cout<<"\tPurchase Price of Total Stock is "<<sum<<endl;
}
void purchase()
{
int copies;
int i=search();
if(i!=0)
{
cout<<"enter no of copies you want to purcase: ";
cin>>copies;
if(B[i].copies>copies)
{
cout<<"copies are available\n";
B[i].copies=B[i].copies-copies;
}
else
cout<<copies<<" are not available\n";
}
}
};
int main()
{
int c;
char ch;
bookshop o;
do
{
cout<<"^^^^^^^^^^^BookStore^^^^^^^^^^^^\n";
cout<<"1]New entry\n";
cout<<"2]Display\n";
cout<<"3]search book\n";
cout<<"4]Purchase book\n";
cout<<"5]stock\n";
cout<<"6]Exit\n";
cin>>c;
switch(c)
{
case 1:
o.initial();
break;
case 2:
o.display();
break;
case 3:
o.search();
break;
case 4:
o.purchase();
break;
case 5:
o.stock();
break;
case 6:
break;
}
cout<<"do you want to continue(y/n): ";
cin>>ch;
}while(ch=='y'||ch=='Y');
return 0;
}
Hello sir how to defend thos
ReplyDelete