Book-Shop Program using C++
C++ Program for Book-Shop
#include<iostream>#include<string.h>
#include<stdlib.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 feeddata();
void editdata();
void showdata();
int search(char[],char[]);
void buybook();
};
void book::feeddata(){
cin.ignore();
cout << "\nEnter author name: "; cin.getline(author,20);
cout << "Enter Title Name: "; cin.getline(title,20);
cout << "Enter Price: "; cin>>*price;
cout << "Enter stock position: "; cin>>*stock;
}
void book::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 book::showdata(){
cout << "\nAuthor Name: "<<author;
cout << "\nTitle Name: "<<title;
cout << "\nPublisher Name: "<<publisher;
cout << "\nPrice: "<<*price;
cout << "\nStock Position: "<<*stock;
}
int book::search(char tbuy[20],char abuy[20]) {
if(strcmp(tbuy,title)==0 && strcmp(abuy,author)==0)
return 1;
else return 0;
}
void book::buybook(){
int count;
cout << "\nEnter number of books to buy: ";
cin>>count;
if(count<=*stock){
*stock=*stock-count;
cout << "\nBooks bought successfully";
cout << "\nAmount: Rs. "<<(*price)*count;
}
else
cout << "\nRequired copies not in stock";
}
int main(){
book *B[20];
int i=0,r,r,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 for book"
<<"\n5. Exit"
<<"\n\nEnter your choice: ";
cin>>choice;
switch(choice){
case 1: B[i] = new book;
B[i]->feeddata();
i++; break;
case 2: cin.ignore();
cout << "\nEnter Title of the 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,auhtorbuy)) {
B[t]->buybook();
break;
}
}
if(t==1)
cout << "\nThis book isn not in stock";
break;
case 3: cin.ignore();
cout << "\nEnter Title of Book: "; cin.getline(titlebuy,20);
cout << "\nEnter 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 the book: "; cin.getline(titlebuy,20);
cout << "\nEnter Author of book: "; cin.getline(authorbut,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;
}
Hello, could you explain what does it mean “void book::showdata()” ?
ReplyDelete