0% found this document useful (0 votes)
89 views12 pages

Liberty Book With File Creation

This C++ program defines structures for books and guest checkout details. It initializes an array of books, provides functions for various shopping cart and checkout options, and contains a main loop that allows the user to search for books, add them to their cart, and checkout. The main function populates the book array, displays menus, gets user input, calls relevant functions, and writes order details to a file.

Uploaded by

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

Liberty Book With File Creation

This C++ program defines structures for books and guest checkout details. It initializes an array of books, provides functions for various shopping cart and checkout options, and contains a main loop that allows the user to search for books, add them to their cart, and checkout. The main function populates the book array, displays menus, gets user input, calls relevant functions, and writes order details to a file.

Uploaded by

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

#include<iostream>

#include<string>
#include<fstream>
using namespace std;
struct guestcheckout1
{
string first_name, last_name, telephone, e_mail, country, region, continue1,
confirmation, continue2, continue3, comment, agree, address, city, post_code,
billlig_delivery_address_choice;

};
struct book
{
string book;
string author;
int views;
int price;
int ranking;
int stock;
string publisher;
string isbn;
string category;

};

int items = 0; fstream MyFile;


int sum3; int count; int sum5 = 0;
string choicesearch1, category;
int j; int sum4; int count1 = 0;
book b[15];
void choice1(void);
void choicesearch(void);
void search(book b[15]);
void addtocart(void);
void copies(void);
void total(void);
void checkout(void);
void checkout1(void);
void choice2(void);
void guestcheckout(void);
void paymentmethod(void);
void commentaboutyourorder(void);
void termsandconditions(void);
void confirmation(void);
void confirmorder(void);
void finalconfirmation(void);
void notadded(void);
void invalid(void);
void selectcategory(void);
void categoryurdu(book b[15]);
void categorychildren(book b[15]);
void booknumber();
void main()
{

MyFile.open("DETAILS.txt", ios::app);
if (!MyFile)
{
cout << "File creation failed";
}
else
{
cout << "New file created";

int choice3, choicepaymemtmethod;


string billlig_delivery_address_choice, booknumber1;
string continue11;
string continue2, comment, agree, continue3, confirmation1; string add;

b[0] = { "Sehar Honay Tak 4","DR ABDUL QADEER KHAN",1,123,1,1,"urdu


books","97801419835610","urdu" };
b[1] =
{ "harry_potter_and_the_chamber_of_secrets","j_k_rrowling",1,123,1,1 ,"arslan","197
80141983561","children" };
b[2] =
{ "The_Lost_Symbol","Dan_Brown",1,123,1,1 ,"Harper_collins" ,"29780141983561","chil
dren" };
b[3] = { "Baburnama","Babur",1,123,1,1 ,"Penguin
Classics","39780141983561","children" };
b[4] = { "Permanent Record","Edward Snowden",1,123,1,1 ,"Macmillan
UK" ,"49780141983561","children" };
b[5] = { "The Hungry Ghost","H.S.Norup",1,123,1,1 ,"Puskin
Children" ,"59780141983561","children" };
b[6] = { "the mediator 5 grave doubts", "meg cabot",1,123,1,1 ,"Penguin
Classics" ,"69780141983561","children" };
b[7] = { "Real Life","Brandon Taylor",1,123,1,1 ,"Macmillan
UK" ,"79780141983561","children" };
b[8] = { "Daughter by court order","ratna vira",1,123,1,1 ,"Penguin Classics"
,"89780141983561","children" };
b[9] = { "The Fault In Our Stars","John Green",1,123,1,1 ,"Puskin
Children" ,"99780141983561","children" };
b[10] = { "The Economics Book","Niall kistainy",1,123,1,1 ,"Dorling
Kindersley USA" ,"109780141983561","children" };
b[11] = { "Last Witnesses","Svetlana Alexievich",1,123,1,1 ,"Penguin
Classics" ,"119780141983561","children" };
b[12] = { "AANGAN","Khadija Mastoor",1,123,1,1 ,"sang e
meel" ,"129780141983561","urdu" };
b[13] = { "Sham E Saraye", "Amjad Islam Amjad",1,123,1,1 ,"sang e
jahan" ,"139780141983561","urdu" };
b[14] = { "Hum Nay Suna Hum Nay Dekha", "Markings khudi",1,123,1,1 ,"marking
publishings" ,"1559780141983561","urdu" };
string choice;

do
{

choice1();
getline(cin, choice);
if (choice == "1")
{

choicesearch();
getline(cin, choicesearch1);
cin.ignore(-1);

search(b);
cin.ignore();
addtocart();

cin >> add;


cin.ignore(-1);
if (add == "Y")
{

copies();
cin >> ::count;
cin.ignore();
total();
checkout();
string d;
getline(cin, d);
cin.ignore(-1);
if (d == "Y")
{
checkout1();
choice2();
cin >> choice3;
if (choice3 == 1)
{

guestcheckout();

if (billlig_delivery_address_choice == "Y")
{

if (continue11 == "Y")
{

if (continue2 == "Y")
{
paymentmethod();
cin >> choicepaymemtmethod;
cin.ignore();

commentaboutyourorder();
getline(cin, comment);
cin.ignore(-1);

termsandconditions();
do {
cin >> agree;
cin.ignore(-1);
} while (agree != "Y");

if (choicepaymemtmethod == 3)
{
confirmation();
cin >> continue3;
cin.ignore(-1);

if (continue3 == "Y")
{
confirmorder();
cin >>
confirmation1;
if (confirmation1
== "Y")
{

finalconfirmation();
}
}

}
}
}
}

}
}
}
else if (add == "N")
{
notadded();
}
else
{
invalid();
}

else if (choice == "2")


{
selectcategory();
getline(cin, category);
cin.ignore(-1);
if (category == "urdu")
{
categoryurdu(b);
booknumber();
cin >> booknumber1;
addtocart();
cin >> add;
cin.ignore(-1);
if (add == "Y")
{

copies();
cin >> ::count;
cin.ignore();
total();
checkout();
string d;
getline(cin, d);
cin.ignore(-1);
if (d == "Y")
{
checkout1();
choice2();
cin >> choice3;
if (choice3 == 1)
{

guestcheckout();

if (billlig_delivery_address_choice ==
"Y")
{

if (continue11 == "Y")
{

if (continue2 == "Y")
{
paymentmethod();
cin >>
choicepaymemtmethod;
cin.ignore();

commentaboutyourorder();
getline(cin, comment);
cin.ignore(-1);

termsandconditions();
do {
cin >> agree;
cin.ignore(-1);
} while (agree != "Y");

if (choicepaymemtmethod
== 3)
{
confirmation();
cin >> continue3;
cin.ignore(-1);

if (continue3 ==
"Y")
{

confirmorder();
cin >>
confirmation1;
if
(confirmation1 == "Y")
{

finalconfirmation();
}
}

}
}
}
}

}
}
}
else if (add == "N")
{
notadded();
}
else
{
invalid();
}
}
if (category == "children")
{
categorychildren(b);
booknumber();
cin >> booknumber1;
addtocart();
cin >> add;
cin.ignore(-1);
if (add == "Y")
{

copies();
cin >> ::count;
cin.ignore();
total();
checkout();
string d;
getline(cin, d);
cin.ignore(-1);
if (d == "Y")
{
checkout1();
choice2();
cin >> choice3;
if (choice3 == 1)
{

guestcheckout();

if (billlig_delivery_address_choice ==
"Y")
{

if (continue11 == "Y")
{

if (continue2 == "Y")
{
paymentmethod();
cin >>
choicepaymemtmethod;
cin.ignore();
commentaboutyourorder();
getline(cin, comment);
cin.ignore(-1);

termsandconditions();
do {
cin >> agree;
cin.ignore(-1);
} while (agree != "Y");

if (choicepaymemtmethod
== 3)
{
confirmation();
cin >> continue3;
cin.ignore(-1);

if (continue3 ==
"Y")
{

confirmorder();
cin >>
confirmation1;
if
(confirmation1 == "Y")
{

finalconfirmation();
}
}

}
}
}
}

}
}
}
else if (add == "N")
{
notadded();
}
else
{
invalid();
}

} while (choice != "3");


MyFile.close();
}
system("pause");
}
void choice1(void)
{
cout << "***********Welcome to liberty book*******" << endl;
cout << "****Menu******" << endl;
cout << "Select the options kindly\n Enter 1 for searching\nEnter 2 for
selecting\nEnter 3 for exit" << endl;
}
void choicesearch(void)
{
cout << "Search by title,author,publisher,or ISBN " << endl;
}
void search(book b[15])
{
for (int i = 0; i < 15; i++)
if (choicesearch1 == b[i].author || choicesearch1 == b[i].book ||
choicesearch1 == b[i].publisher || choicesearch1 == b[i].isbn)
{

cout << "Book no " << i + 1 << endl;


int count1 = 0;
count1 = b[i].views + 1;
cout << "****Book Information****** " << endl;
cout << "Name: " << b[i].book << endl;
cout << "Author: " << b[i].author << endl;
cout << "Views: " << count1 << endl;
cout << "Ratings: " << b[i].ranking << endl;
cout << "price: " << b[i].price << endl;
cout << "Stock available: " << b[i].stock << endl;
cout << "publisher: " << b[i].publisher << endl;
cout << "ISBN: " << b[i].isbn << endl;
sum4 = b[i].price;

}
}
void addtocart(void)
{
cout << "Do you want to ADD TO CART?\n1.Enter Y for yes \n2.Enter N for no "
<< endl;
}
void copies(void)
{

cout << "Your selected book is added to cart" << endl;


cout << "How many copies of this book do you want to added to cart" << endl;

}
void total(void)
{

sum3 = sum4 * ::count;


sum5 = sum5 + sum3;
items = items + ::count;
MyFile << "Order Details" << endl;
cout << "Number of items \t" << items << endl;
MyFile << "Number of items \t" << items << endl;
cout << "Sub total \t" << sum5 << endl;
MyFile << "Sub total \t" << sum5 << endl;
cout << "Total \t" << sum5 << endl;
MyFile << "Total \t" << sum5 << endl;
}
void checkout(void)
{
cout << "****Check out*****\nEnter Y for yes \nEnter N for no" << endl;
}
void checkout1(void)
{
cout << "Quantity\t\tTotal price" << endl;
cout << ::count << "\t\t " << sum5 << endl;
}
void choice2(void)
{
cout << "Do you want to check it out or continue the shopping \n Enter 1 for
check it out \nEnter 2 for countinuing the shopping" << endl;
}
void guestcheckout(void)
{
string billlig_delivery_address_choice, continue11, continue2;
guestcheckout1 g;

cout << "*****Guest Check out****\n******Billing Details********" << endl;


MyFile << "*****Guest Check out****\n******Billing Details********" << endl;
cout << "Your personal details" << endl;
MyFile << "******Personal Detail***********s" << endl;

cout << "First Name*" << endl;


cin >> g.first_name;
cin.ignore();
MyFile <<"First name: "<<g.first_name<<endl;
cout << "Last Name*" << endl;
getline(cin, g.last_name);
MyFile << "Last Name: " << g.last_name << endl;
cout << "E-mail*" << endl;
getline(cin,g.e_mail);
cin.ignore(-1);
MyFile << "E-mail: " << g.e_mail << endl;
cout << "Telephone*" << endl;
getline(cin, g.telephone);
cin.ignore(-1);
MyFile << "Telephone: " << g.telephone << endl;
cout << "Your Address" << endl;
MyFile << "***********Address Details***********" << endl;
cout << "Address*" << endl;
getline(cin, g.address);
cin.ignore(-1);
MyFile << "Address: "<< g.address <<endl;
cout << "Country*" << endl;
getline(cin, g.country);
cin.ignore(-1);
MyFile << "Country: "<< g.country <<endl;
cout << "Region/ State*" << endl;
getline(cin,g.region);
cin.ignore(-1);
MyFile << "Region/ State: "<< g.region <<endl;
cout << "City*" << endl;
getline(cin,g.city);
cin.ignore(-1);
MyFile << "City: "<< g.city <<endl;
cout << "post code" << endl;
getline(cin, g.post_code);
cin.ignore(-1);
MyFile << " Post code"<< g.post_code <<endl;
cout << "My billing and delivery address are same.\nEnter Y for yes\n Enter N
for no" << endl;
cin >> billlig_delivery_address_choice;
cout << "Do you want to continue.\nEnter Y for yes\nEnter anythong for No."
<< endl;
cin >> continue11;
cout << "*******Delivery Details*********" << endl;
cout << "First Name: " << g.first_name << endl;
cout << "Last Name: " << g.last_name << endl;
cout << "Address: " << g.address << endl;
cout << "Country: " << g.country << endl;
cout << "Reigion/State: " << g.region << endl;
cout << "City: " << g.city << endl;
cout << "post code: " << g.post_code << endl;
cout << "Do you want to continue.\nEnter Y for yes\nEnter anythong for No."
<< endl;
cin >> continue2;
}
void paymentmethod(void)
{
cout << "Enter 1 for online payment powered by ALFALA\nEnter 2 for Easypaisa
\nEnter 3 for Cash on Delivery" << endl;

}
void commentaboutyourorder(void)
{
cout << "Add comment about you order" << endl;
}
void termsandconditions(void)
{
cout << "I have read and agree to the Terms & Conditions " << endl;
cout << "Enter Y ofor yes and N for no" << endl;
}
void confirmation(void)
{
cout << "Do you want to continue.\nEnter Y for yes\nEnter anything for No."
<< endl;
}
void confirmorder(void)
{
guestcheckout1 g;
cout << "********Confirm Order*******" << endl;
cout << "****Shipping Details*****" << endl;
MyFile << "********Confirm details*******" << endl;
cout << "Name" << g.first_name + " " + g.last_name;
MyFile << "Name" << g.first_name + " " + g.last_name;
cout << "Country: " << g.country << endl;
MyFile << "Country: " << g.country << endl;
cout << "City: " << g.city << endl;
MyFile << "City: " << g.city << endl;
cout << "Reigion/State: " << g.region << endl;
MyFile << "Reigion/State: " << g.region << endl;
cout << "Address: " << g.address << endl;
MyFile << "Address: " << g.address << endl;
cout << "Phone: " << g.telephone << endl;
MyFile << "Phone: " << g.telephone << endl;
cout << "****Payment Detail****" << endl;
MyFile << "****Payment Detail****" << endl;
cout << "Payment Method: Cash On Delivery" << endl;
MyFile << "Payment Method: Cash On Delivery" << endl;
cout << "Name" << g.first_name + " " + g.last_name;
MyFile << "Name" << g.first_name + " " + g.last_name;
cout << "Country: " << g.country << endl;
MyFile << "Country: " << g.country << endl;
cout << "City: " << g.city << endl;
MyFile << "City: " << g.city << endl;
cout << "Reigion/State: " << g.region << endl;
MyFile << "Reigion/State: " << g.region << endl;
cout << "Address: " << g.address << endl;
MyFile << "Address: " << g.address << endl;
cout << "Phone: " << g.telephone << endl;
MyFile << "Phone: " << g.telephone << endl;
cout << "Confirmed Order\nEnter Y for yes and N for no" << endl;

}
void finalconfirmation(void)
{
cout << "Your Order Has Been Placed!" << endl;
cout << "Your order # GS9-IBD-NF21 has been successfully processed!\nPlease
direct any questions you have to the store owner.\nThanks werdftgasdfg for shopping
with us online!" << endl;
}
void notadded(void)
{
cout << "OK Selected book is not added to cart" << endl;
}
void invalid(void)
{
cout << "Kindly Enter the right value" << endl;
}
void selectcategory(void)
{
cout << "Select the category\nEnter urdu for urdu books \nEnter children
for children books" << endl;

}
void categoryurdu(book b[15])
{
for (int i = 0; i < 15; i++)

if (b[i].category == "urdu")
{
cout << "\n\nBook no " << i + 1 << endl;
count1 = b[i].views + 1;
cout << "****Book Information****** " << endl;
cout << "Name: " << b[i].book << endl;
cout << "Author: " << b[i].author << endl;
cout << "Views: " << count1 << endl;
cout << "Ratings: " << b[i].ranking << endl;
cout << "price: " << b[i].price << endl;
cout << "Stock available: " << b[i].stock << endl;
cout << "publisher: " << b[i].publisher << endl;
cout << "ISBN: " << b[i].isbn << endl;
cout << "Category: " << b[i].category << endl;
sum4 = b[i].price;
}

}
void categorychildren(book b[15])
{

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


if (b[i].category == "children")
{

cout << "\n\nBook no " << i + 1 << endl;


count1 = b[i].views + 1;
cout << "****Book Information****** " << endl;
cout << "Name: " << b[i].book << endl;
cout << "Author: " << b[i].author << endl;
cout << "Views: " << count1 << endl;
cout << "Ratings: " << b[i].ranking << endl;
cout << "price: " << b[i].price << endl;
cout << "Stock available: " << b[i].stock << endl;
cout << "publisher: " << b[i].publisher << endl;
cout << "ISBN: " << b[i].isbn << endl;
cout << "Category: " << b[i].category << endl;
sum4 = b[i].price;
}

}
void booknumber(void)
{
cout << "Enter book number" << endl;

You might also like