#include <iostream>
#include <string>
using namespace std;
struct Book{
int id;
string type;
string bookName;
string authorName;
double price;
};
void addNewBook(struct Book bookstore[],int* totalBooks);
int main(){
//10 bookstore
struct Book bookstore[10];
int totalBooks=0;
int choice=0;
while(choice!=8){
cout<<"1. Add a new book in a bookstore\n";
cout<<"2. Count and display the number of bookstore in a bookstore\n";
cout<<"3. Exit\n";
cout<<"Your choice: ";
cin>>choice;
switch (choice)
{
case 1:
{
addNewBook(bookstore,&totalBooks);
}
break;
case 2:
if(totalBooks>0){
cout<<"The number of bookstore in a bookstore: "<<totalBooks<<"\n\n";
for(int i=0;i<totalBooks;i++){
cout<<"The book id: "<<bookstore[i].id<<"\n";
cout<<"The book type: "<<bookstore[i].type<<"\n";
cout<<"The book book name: "<<bookstore[i].bookName<<"\n";
cout<<"The book author name: "<<bookstore[i].authorName<<"\n";
cout<<"The book price: "<<bookstore[i].price<<"\n\n";
}
}else{
cout<<"\nThe bookstore is empty.\n";
}
break;
case 3:
//exit
break;
default:
break;
}
}
return 0;
}
void addNewBook(struct Book bookstore[],int* totalBooks){
cout<<"Enter the book id: ";
cin>>bookstore[*totalBooks].id;
cin.ignore();
cout<<"Enter the book type: ";
getline(cin,bookstore[*totalBooks].type);
cout<<"Enter the book name: ";
getline(cin,bookstore[*totalBooks].bookName);
cout<<"Enter the book author name: ";
getline(cin,bookstore[*totalBooks].authorName);
cout<<"Enter the book price: ";
cin>>bookstore[*totalBooks].price;
*totalBooks=*totalBooks+1;
cout<<"\nA new book has been added.\n";
}
Comments
Leave a comment