Vous êtes sur la page 1sur 6

// Header Files Used in the Program

#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<fstream.h>
// Class used in the Program
class product
{
int pno;
char name[50];
float price,dis;
public:
void create_product()
{
cout<<"\nEnter Product Number:";
cin>>pno;
cout<<"\n\nEnter Name of The Product: ";
gets(name);
cout<<"\nEnter the Price of The Product (in ruppees): ";
cin>>price;
cout<<"\nEnter The Discount (%): ";
cin>>dis;
}
void show_product()
{
cout<<"\nProduct Number: "<<pno;
cout<<"\nName of The Product : ";
puts(name);
cout<<"\nPrice of The Product : "<<price;
cout<<"\nDiscount (varies) : "<<dis<<" %";
}
int returnbatch()
{return pno;}
float retprice()
{return price;}
char* retname()
{return name;}
int retdis()
{return dis;}
};
// Global Stream Object
fstream file;
// Global Class Object
product obj;
// Functions Used in the Program
// (i) Function to Write The Product

void write_product()
{
file.open("DATABASE.DAT",ios::out|ios::app);
obj.create_product();
file.write((char*)&obj,sizeof(product));
file.close();
cout<<"\n\nThe Product Has Been Created ";
getch();
}
// (ii) Function to Read The Records
void display_all()
{
clrscr();
cout<<"\n\n\n\t\tDisplaying All the Products Available!\n\n";
file.open("DATABASE.DAT",ios::in);
while(file.read((char*)&obj,sizeof(product)))
{
obj.show_product();
cout<<"\n\n*******************************\n";
getch();
}
file.close();
getch();
}
// (iii) Function to Read The Specific Records
void display_sp(int n)
{
int flag=0;
file.open("DATABASE.DAT",ios::in);
while(file.read((char*)&obj,sizeof(product)))
{
if(obj.returnbatch()==n)
{
clrscr();
obj.show_product();
flag=1;
}
}
file.close();
if(flag==0)
cout<<"\n\nThe record entered doesn't exist.";
getch();
}
// (iv) Function to Read The Specific Records
void modify_product()
{
int no,found=0;
clrscr();
cout<<"\n\n\tModifying Existing Record!";
cout<<"\n\n\tEnter The Product Number: ";
cin>>no;
file.open("DATABASE.DAT",ios::in|ios::out);
while(file.read((char*)&obj,sizeof(product)) && found==0)
{
if(obj.returnbatch()==no)
{

obj.show_product();
cout<<"\nEnter The New Details of Product!"<<endl;
obj.create_product();
int pos=-1*sizeof(obj);
file.seekp(pos,ios::cur);
file.write((char*)&obj,sizeof(product));
cout<<"\n\n\t Record Updated";
found=1;
}
}
file.close();
if(found==0)
cout<<"\n\n Record Entered doesn't exist...\nPress Any Key to Proceed!";
getch();
}
// (v) Function to Remove Records from the Database
void delete_product()
{
int no;
clrscr();
cout<<"\n\n\n\tATTENTION: Deleting a Record";
cout<<"\n\nEnter the Product Number to be deleted: ";
cin>>no;
file.open("DATABASE.DAT",ios::in|ios::out);
fstream file2;
file2.open("Temp.dat",ios::out);
file.seekg(0,ios::beg);
while(file.read((char*)&obj,sizeof(product)))
{
if(obj.returnbatch()!=no)
{
file2.write((char*)&obj,sizeof(product));
}
}
file2.close();
file.close();
remove("DATABASE.DAT");
rename("Temp.dat","DATABASE.DAT");
cout<<"\n\n\tRecord Deleted ..";
getch();
}
// (vi) Function to Display all Records in the Database
void menu()
{
clrscr();
file.open("DATABASE.DAT",ios::in);
if(!file)
{
cout<<"ERROR404: Database doesn't exist!\n\n Please crea
te database in Administrator's Menu!";
cout<<"\n\n\n Program will exit now...\n\nPress any key
to exit!";
getch();
exit(0);
}
cout<<"\n\n\t\t\t\tPRODUCTS MENU:\n\n";
cout<<"=========================================================

============\n";
cout<<"Product Number\t\tProduct Name\t\tPrice (in ruppees)\n";
cout<<"=========================================================
============\n";
while(file.read((char*)&obj,sizeof(product)))
{
cout<<obj.returnbatch()<<"\t\t\t"<<obj.retname()
<<"\t\t\t"<<obj.retprice()<<endl;
}
file.close();
}
// (vii) Function to Place the order from the entered Records
void place_order()
{
int order_arr[50],quan[50],c=0;
float amt,damt,total=0;
char ch='Y';
menu();
cout<<"\n============================";
cout<<"\n Placing Your Order";
cout<<"\n============================\n";
do
{
cout<<"\n\nEnter Product Number: ";
cin>>order_arr[c];
cout<<"\nQuantity in number : ";
cin>>quan[c];
c++;
cout<<"\nDo You Want To Order Another Product ? (y/n): "
;
cin>>ch;
}
while(ch=='y' ||ch=='Y');
cout<<"\n\nThank You For Purchasing from us...";getch();clrscr()
;
cout<<"\n\n============================== [INVOICE] ============
==================\n";
cout<<"\nPr No.\tPr Name\tQuantity \tPrice \tAmount \tDiscounted
Amount\n";
for(int i=0;i<=c;i++)
{
file.open("DATABASE.DAT",ios::in);
file.read((char*)&obj,sizeof(product));
while(!file.eof())
{
if(obj.returnbatch()==order_arr[i])
{
amt=obj.retprice()*quan[i];
damt=amt-(amt*obj.retdis()/100);
cout<<"\n"<<order_arr[i]<<"\t"<<
obj.retname()
<<"\t"<<quan[i]<<"\t\t"<<obj.ret
price()<<"\t"<<amt<<"\t\t"<<damt;
total+=damt;
}
file.read((char*)&obj,sizeof(product));
}
file.close();

}
cout<<"\n\n\t\t\t\t\tTotal Amt. = "<<total;
getch();
}
// (viii) Function display introduction of the project
void intro()
{
clrscr();
gotoxy(22,6);
cout<<"**********************************";
gotoxy(23,8);
cout<<"[ MEDIPOINT CHEMIST & DRUGGIST ]";
gotoxy(26.5,10);
cout<<"BILLING & STOCK MANAGEMENT";
gotoxy(35,12);
cout<<"PROJECT";
gotoxy(22,14);
cout<<"**********************************";
gotoxy(30,16);
cout<<"Made by Rohan Taneja";
getch();
}
// (ix) Administrator's Menu
void admin_menu()
{
clrscr();
char ch2;
cout<<"\n*********************************";
cout<<"\n Welcome to Administrator's Menu";
cout<<"\n*********************************\n\nWarning: For Staff
Members only!";
cout<<"\n\n\t1) Add a Product";
cout<<"\n\n\t2) Show all the Products";
cout<<"\n\n\t3) Query of the Specific Record";
cout<<"\n\n\t4) Modify existing Record";
cout<<"\n\n\t5) Delete unwanted/outdated Record";
cout<<"\n\n\t6) Show Product Menu";
cout<<"\n\n\t7) Return to Main Menu";
cout<<"\n\n\tPlease Enter Your Choice (1-7): ";
ch2=getche(); // getche -> accepts single character and proceeds
switch(ch2)
{
case '1': clrscr();
write_product();
break;
case '2': display_all();break;
case '3':
int num;
clrscr();
cout<<"\n\n\tEnter The Product No. ";
cin>>num;
display_sp(num);
break;
case '4': modify_product();break;
case '5': delete_product();break;
case '6': menu();getch();

case '7': break;


default:cout<<"\a";admin_menu();
}
}
// (x) Declaration of main function - here code executes
void main()
{
char ch;
intro();
do
{
clrscr();
cout<<"\n\n\n\tMAIN MENU";
cout<<"\n\n\t1) Customers Menu";
cout<<"\n\n\t2) Administrator's Menu";
cout<<"\n\n\t3) Exit the Program";
cout<<"\n\n\tPlease Select Your Option (1-3): ";
ch=getche();
switch(ch)
{
case '1': clrscr();
place_order();
getch();
break;
case '2': admin_menu();
break;
case '3':exit(0);
default :cout<<"\a";
}
}while(ch!='3');
}
/*
***************************
Welcome to End of Project!
Really nuts of me to write this in the end :p
Thanks for getting all the way down!
Yours Truly!
Rohan Taneja.
***************************
*/

Vous aimerez peut-être aussi