redone
redone
#include<stdlib.h>
#include<fstream>
#include<conio.h>
#include<stdio.h>
#include<iomanip>
class product{
private:
int productno;
char productname[40];
float price;
float discount;
public:
void add_product(){
cout<<"Enter the product no";
cin>>productno;
cout<<"Enter the product name";
cin>>productname;
cout<<"Enter the product price";
cin>>price;
cout<<"Enter the discount";
cin>>discount;
};
void display_product(){
cout<<"Product Number : "<<productno<<endl;
cout<<"Product Name : "<<productname<<endl;
cout<<"Product price : "<<price<<endl;
cout<<"Product discount : "<<discount<<endl;
};
int returnNo(){
return productno;
}
char* returnName(){
return productname;
}
float returnPrice(){
return price;
};
float returnDiscount(){
return discount;
};
public:
void writeProduct();
void displayAll();
void displaySpecific(int x);
void modifyProduct();
void deleteProduct();
}change;
void changes::writeProduct(){
fp.open("itemstore1.dat",ios::out|ios::app);
prodct.add_product();
fp.write((char*)&prodct,sizeof(product));
fp.close();
cout<<"The product has been added";
getch();
};
void changes::displayAll(){
system("cls");
cout<<"Display all record"<<endl;
cout<<endl;
fp.open("itemstore1.dat",ios::in);
while(fp.read((char*)&prodct,sizeof(product)))
{
prodct.display_product();
cout<<"\n====================================\n";
}
fp.close();
getch();
};
void changes::displaySpecific(){
int flag=0,x;
cout<<"Please enter the product number";
cin>>x;
fp.open("itemstore1.dat",ios::in);
while(fp.read((char*)&prodct,sizeof(product))){
if(prodct.returnNo()==x){
system("cls");
prodct.display_product();
flag=1;
}
}
fp.close();
if(flag==0){
cout<<"The product does not exist";
getch();
}
};
void changes::modifyProduct(){
int num,flag=0;
cout<<"Please enter the product number to modify the product";
cin>>num;
fp.open("itemstore1.dat",ios::in |ios::out);
while(fp.read((char*)&prodct,sizeof(product)) && flag==0){
if(prodct.returnNo()==num){
prodct.display_product();
cout<<"\nPlease enter the new details to be modified";
prodct.add_product();
int pos=-1*sizeof(product);
fp.seekp(pos,ios::cur);
fp.write((char*)&prodct,sizeof(product));
cout<<"\n\n\t Record Updated";
flag=1;
}
fp.close();
if(flag==0)
cout<<"Record is not available";
getch();
}
};
void changes::deleteProduct(){
int no;
system("cls");
cout<<"\n\n\n\tDelete Record";
cout<<"\n\nPlease Enter The product number You Want To Delete";
cin>>no;
fp.open("itemstore1.dat",ios::in|ios::out);
fstream fp2;
fp2.open("Temp.dat",ios::out);
fp.seekg(0,ios::beg);
while(fp.read((char*)&prodct,sizeof(product)))
{
if(prodct.returnNo()!=no)
{
fp2.write((char*)&prodct,sizeof(product));
}
}
fp2.close();
fp.close();
remove("itemstore1.dat");
rename("Temp.dat","itemstore1.dat");
cout<<"\n\n\tRecord Deleted ..";
getch();
}
void adminMain(){
int choice1;
int x;
if(choice1==1){
change.writeProduct();
}
else if(choice1==2){
change.displayAll();
}
else if(choice1==3){
change.displaySpecific(x);
}
else if (choice1==4){
change.modifyProduct();
}
else if (choice1==5){
change.deleteProduct();
}
}
class Customer{
public:
void DisplayMenu(){
system("cls");
cout << "
|-----------------------------------------|"<< endl;
cout << " | MAIN MENU
|"<< endl;
cout << "
|-----------------------------------------|"<< endl;
}p;
int main()
{
int choice;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout<<setprecision(2);
fstream tmp("temp.dat",ios::binary|ios::out);
system("pause");
p.DisplayMenu();
cout<<"Please enter your desired choice";
cin>>choice;