0% found this document useful (0 votes)
90 views3 pages

Book Structure

This code defines structures to store book and customer data. It then declares arrays of books and a customer variable. The main function contains a menu to allow the user to search for books by author, ISBN, or name. It also allows purchasing books where the user enters quantity and payment details are collected. The order is then confirmed or cancelled.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views3 pages

Book Structure

This code defines structures to store book and customer data. It then declares arrays of books and a customer variable. The main function contains a menu to allow the user to search for books by author, ISBN, or name. It also allows purchasing books where the user enters quantity and payment details are collected. The order is then confirmed or cancelled.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include<iostream>

#include<string>
#include<time.h>
using namespace std;
struct book
{
string bookname;
string authorname;
string isbn;
int pages;
double price;

};
struct customer
{
string firstname;
string lastname;
string address;
string country;
string email;
string city;
int postcode;
int phonenumber;
};
void main()
{
book b[10] = { {"english","esha","bw231",1000,300},{"islamiyat","ramsha","bw2561",500,600},
{"urdu","irsa","gf2311",690,200} ,{"mathematics","husna","hu420",1000,1200} ,{"drawing","irsa","tho544",200,450} ,
{"chemistry","minahil","cg2231",400,1300},{"physics","areej","bts321",800,1300},{"360
stories","eman","bts123",300,500},{"biology","azka & javeria","hte321",1500,1700},
{"computer","eza","gt23d",250,350} };
int choice;
do {
system("cls");
cout << "****MENUE****" << endl;
cout << "press 1.to seacrch book\npress 2. to purchase\npress 3.to exit" << endl;
cin >> choice;
if (choice == 1)
{
system("cls");
char choose;
cout << "****MENUE****" << endl;
cout << "choose any one method to search\na.Search by author name\nSerach by ISBN\
nSearch by book name" << endl;
cin >> choose;
if (choose == 'a' || choose == 'A')
{
string aname;
cout << "enter author name" << endl;
cin.ignore();
getline(cin, aname);

for (int i = 0; i <= 9; i++)


{
if (aname == b[i].authorname)
cout << "book name " << b[i].bookname << endl << "author
name " << b[i].authorname << endl << "pages " << b[i].pages << endl << "ISBN number " << b[i].isbn << endl << "price
" << b[i].price << endl;
}
}
else if (choose == 'b' || choose == 'B')
{
string Isbn;
cout << "enter isbn number" << endl;
cin.ignore();
getline(cin, Isbn);

for (int i = 0; i <= 9; i++)


{
if (Isbn == b[i].isbn)
cout << "book name " << b[i].bookname << endl << "author
name " << b[i].authorname << endl << "pages " << b[i].pages << endl << "ISBN number " << b[i].isbn << endl << "price
" << b[i].price << endl;

}
}
else if (choose == 'c' || choose == 'C')
{
string bname;
cout << "enter book name" << endl;
cin.ignore();
getline(cin, bname);

for (int i = 0; i <= 9; i++)


{
if (bname == b[i].bookname)
cout << "book name " << b[i].bookname << endl << "author
name " << b[i].authorname << endl << "pages " << b[i].pages << endl << "ISBN number " << b[i].isbn << endl << "price
" << b[i].price << endl;

}
}
else
cout << "invalid" << endl;
}
else if (choice == 2)
{
system("cls");
int quantity;
double total;
string cart;
cout << "which book you want to purchase" << endl;
cout << "enter ISBN number" << endl;
cin.ignore();
getline(cin, cart);
for (int i = 0; i <= 9; i++)
{
cout << "book name " << b[i].bookname << endl << "author name " <<
b[i].authorname << endl << "pages " << b[i].pages << endl << "ISBN number " << b[i].isbn << endl << "price " <<
b[i].price << endl;
cout << "enter quantity" << endl;
cin >> quantity;
total = b[i].price * quantity;
}
cout << "total price" << total << endl;
customer guest;
cout << "enter name;" << endl;
cin.ignore();
getline(cin, guest.firstname);
cout << "enter your last name" << endl;
getline(cin, guest.lastname);
cout << "enter your country" << endl;
getline(cin, guest.country);
cout << "enter your city" << endl;
getline(cin, guest.city);
cout << "enter your postcode" << endl;
cin >> guest.postcode;
cout << "enter your address" << endl;
getline(cin, guest.address);
cout << "enter your phone number" << endl;
cin >> guest.phonenumber;
cout << "enter your email" << endl;
getline(cin, guest.email);
int ch;
cout << "***PAYMENT OPTIIONS***\n1-alfalah\n2-esaypaisa\ncredit or debit card\ncash
on dilevery" << endl;
cin >> ch;
cout << "you choose " << ch << " payment options" << endl;
string comment;
cout << "ENTER COMMENT ABOUT ORDER" << endl;
getline(cin, comment);
cout << " first name " << guest.firstname << endl << "last name" << guest.lastname << endl
<< "address" << guest.address << endl << "phone number " << guest.phonenumber << endl << "city " << guest.city <<
"country " << guest.country << endl << "post code " << guest.postcode << "payment option you choose " << ch << endl;
char conf;
cout << "do you want to confirm order?yes or no" << endl;
cin >> conf;
if (conf == 'y')
{
int varaible;
srand(time(0));
cout << "your order is confirm" << endl;
varaible = 1 + (rand() % 20);
cout << "your order code is " << varaible << endl;
}
else if (conf == 'n') {
cout << "your program has been cancelled" << endl;
}
else
cout << "invalid" << endl;
}
else if (choice == 'e' || choice == 'E')
{
cout << "EXIT PROGRAM" << endl;
}
else
cout << "very goood question" << endl;
system("pause");
} while (choice != 'e' && choice != 'E');

You might also like