C program inventory for a bookstore. I need a system that will let you enter you
ID: 3916988 • Letter: C
Question
C program inventory for a bookstore.
I need a system that will let you enter your inventory and store it in a file. I also should be able to sort it, and update it. For the items in the inventory, I will be keeping track of its information (name, publisher, year, author, pages, price).
The system will allow you to keep track of who purchases the items from the store (name, address, telephone, what they bought, how much they paid). This information should also to be stored in a file that is seperate from the inventory file.
The program should open with a menu that allows me to see the inventory (provide at least 3 ways of looking at the inventory - unsorted, and 2 sorted views by title and author.
The program should let me search the inventory by 1- author, 2- year and 3-title.
The program should also let me then enter a customer's data and what they bought. I should then also be able to see the list of customer's (sorted and unsorted) and also search the customer list based upon city phone and their name.
I should also be able to delete inventory and customers.
C using stdio.h
Explanation / Answer
#include<fstream>
#include<string.h>
#include<conio.h>
#include<iomanip>
#include<iostream>
#include <stdlib.h>
#include<windows.h>
#include<dos.h>
using namespace std;
class BookStore
{
public:
char Code_of_Book[10],bookTitle[20],AuthourName[20];
float Price;
void GetContent()
{
cout<<" Enter Code of the book : ";
cin>>Code_of_Book;
cout<<" Enter Authors Name :";
cin>>AuthourName;
cout<<" Enter Book title:";
cin>>bookTitle;
cout<<" Enter Price of book:";
cin>>Price;
cout<<endl;
};
};
class fileBookClass:public BookStore
{
public:
AddTheBooks()
{
fstream fileBook("TotalBook.txt",ios::out|ios::app);
fileBook.width(20);
fileBook<<setFlags(ios::left);
fileBook<<bookTitle;
fileBook.width(20);
fileBook<<setFlags(ios::left);
fileBook<<AuthourName;
fileBook.width(10);
fileBook<<setFlags(ios::right);
fileBook<<Code_of_Book;
fileBook.width(10);
fileBook<<setFlags(ios::right);
fileBook<<Price<<endl;
fileBook.close();
}
void fileBook();
};
void fileBookClass::fileBook()
{
char fil[20];
GetContent();
strcpy(fil,Code_of_Book);
strcat(fil,".txt");
fstream fileBook(fil);
fileBook<<"Book Name :"<<bookTitle<<endl;
fileBook<<"Author Name :"<<AuthourName<<endl;
fileBook<<"Book Code_of_Book :"<<Code_of_Book<<endl;
fileBook<<"Price :"<<Price<<endl;
fileBook.close();
}
class Typ1:public fileBookClass
{
public:
void book_Record()
{
fstream b1_fileBook("Fiction.txt",ios::out|ios::app);
b1_fileBook<<endl;
b1_fileBook<<"Book's Name :"<<bookTitle<<endl;
b1_fileBook<<"Author's Name :"<<AuthourName<<endl;
b1_fileBook<<"Book's Code :"<<Code_of_Book<<endl;
b1_fileBook<<"Book's Price :"<<Price<<endl;
b1_fileBook.close();
}
};
class Typ2:public fileBookClass
{
public:
void book_Record()
{
fstream b1_fileBook("History.txt",ios::out|ios::app);
b1_fileBook<<endl;
b1_fileBook<<"Book Name :"<<bookTitle<<endl;
b1_fileBook<<"Author Name :"<<AuthourName<<endl;
b1_fileBook<<"Book Code_of_Book :"<<Code_of_Book<<endl;
b1_fileBook<<"Price :"<<Price<<endl;
b1_fileBook.close();
}
};
class Typ3:public fileBookClass
{
public:
void book_Record()
{
fstream b1_fileBook("Physics.txt",ios::out|ios::app);
b1_fileBook<<endl;
b1_fileBook<<"Book Name :"<<bookTitle<<endl;
b1_fileBook<<"Author Name :"<<AuthourName<<endl;
b1_fileBook<<"Book Code_of_Book :"<<Code_of_Book<<endl;
b1_fileBook<<"Price :"<<Price<<endl;
b1_fileBook.close();
}
};
class Typ4:public fileBookClass
{
public:
void book_Record()
{
fstream b1_fileBook("Computer.txt",ios::out|ios::app);
b1_fileBook<<endl;
b1_fileBook<<"Book Name :"<<bookTitle<<endl;
b1_fileBook<<"Author Name :"<<AuthourName<<endl;
b1_fileBook<<"Book Code_of_Book :"<<Code_of_Book<<endl;
b1_fileBook<<"Price :"<<Price<<endl;
b1_fileBook.close();
}
}; //Typ4 class ends
class AddToRecordsClass
{
public:
AddToRecordsClass();
};
AddToRecordsClass::AddToRecordsClass()
{
Typ1 Typ1;
Typ2 Typ2;
Typ3 Typ3;
Typ4 Typ4;
int opt;
while(1)
{
system("cls");
cout<<"....................Add Books to Inventory................";
cout<<" 1.Fiction Books 2.History books 3.Physics Books 4.Computer books 5.Exit ";
cout<<" opt:";
cin>>opt;
if(opt==1)
{
Typ1.fileBook();
Typ1.book_Record();
Typ1.AddTheBooks();
}
if(opt==2)
{
Typ2.fileBook();
Typ2.book_Record();
Typ2.AddTheBooks();
}
if(opt==3)
{
Typ3.fileBook();
Typ3.book_Record();
Typ3.AddTheBooks();
}
if(opt==4)
{
Typ4.fileBook();
Typ4.book_Record();
Typ4.AddTheBooks();
}
if(opt==5)
{
break;
}
}
}
class show
{
public:
show();
};
show::show()
{
int opt;
char Code_of_Book[10],ch;
while(1)
{
cout<<" ...................Display Inventory..................... ";
cout<<"1.All Books"<<endl;
cout<<"2.Fiction"<<endl;
cout<<"3.History"<<endl;
cout<<"4.Physics"<<endl;
cout<<"5.Computer"<<endl;
cout<<"6.Exit"<<endl;
//...................................................................
cout<<" WELCOME TO ALL NEW BOOK STORE Enter Ur opt:" ;
cin>>opt;
if(opt==1)
{
system("cls");
cout<<endl;
cout.width(20);
cout<<setFlags(ios::left);
cout<<"Book Name";
cout.width(20);
cout<<setFlags(ios::left);
cout<<"Author Name";
cout.width(10);
cout<<setFlags(ios::right);
cout<<"Code_of_Book";
cout.width(10);
cout<<setFlags(ios::right);
cout<<"Price"<<endl<<endl;
fstream fileBook("TotalBook.txt",ios::in);
fileBook.seekg(0);
while(fileBook)
{
fileBook.get(ch);
cout<<ch;
}
fileBook.close();
getch();
}
if(opt==2)
{
system("cls");
fstream fileBook("Fiction.txt",ios::in);
fileBook.seekg(0);
cout<<" ";
while(fileBook)
{
fileBook.get(ch);
Sleep(10);
cout<<ch;
}
fileBook.close();
getch();
}
if(opt==3)
{
system("cls");
fstream fileBook("History.txt",ios::in);
fileBook.seekg(0);
cout<<" ";
while(fileBook)
{
fileBook.get(ch);
Sleep(10);
cout<<ch;
}
fileBook.close();
getch();
}
if(opt==4)
{
system("cls");
fstream fileBook("Physics.txt",ios::in);
fileBook.seekg(0);
cout<<" ";
while(fileBook)
{
fileBook.get(ch);
Sleep(10);
cout<<ch;
}
fileBook.close();
getch();
}
if(opt==5)
{
system("cls");
fstream fileBook("d:\Computer.txt",ios::in);
fileBook.seekg(0);
cout<<" ";
while(fileBook)
{
fileBook.get(ch);
Sleep(10);
cout<<ch;
}
fileBook.close();
getch();
}
if(opt==6)
break;
}
}
class search
{
public:
search();
};
search::search()
{
int opt;
char fil[20];
char ch,Code_of_Book[10];
while(1)
{
system("cls");
cout<<" ....................SEARCH Inventory................... ";
cout<<"1.Search";
cout<<" 2.Exit ";
cout<<" Chioce:";
cin>>opt;
if(opt==1)
{
cout<<"Enter Code_of_Book:";
cin>>Code_of_Book;
cout<<endl;
strcpy(fil,Code_of_Book);
strcat(fil,".txt");
fstream fileBook(fil,ios::in);
while(fileBook)
{
fileBook.get(ch);
cout<<ch;
}
fileBook.close();
getch();
}
if(opt==2)
break;
}
}
class start
{
public:
start();
};
start::start()
{
int opt;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
while(1)
{
system("cls");
cout<<" .........Enter Your opt........ ";
cout<<"1.Add to Inventory ";
cout<<"2.View Inventory ";
cout<<"3.Search Inventory ";
cout<<"4.Exit ";
cout<<"Enter opt:";
cin>>opt;
if(opt==1)
{ AddToRecordsClass a;}
if(opt==2)
{ show d;}
if(opt==3)
{search s; }
if(opt==4)
{
cout<<":)
";
break;
}
}
}
int main()
{
start end;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.