0% found this document useful (0 votes)
26 views

redone

redone code
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)
26 views

redone

redone code
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/ 6

#include <iostream>

#include<stdlib.h>
#include<fstream>
#include<conio.h>
#include<stdio.h>
#include<iomanip>

using namespace std;

fstream fp;//file object;

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;
};

}prodct;//end of class product;


class changes{

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;

cout<<"1)Add new product"<<endl;


cout<<"2)Display all products"<<endl;
cout<<"3)Display product details"<<endl;
cout<<"4)Edit product details"<<endl;
cout<<"5)Delete product"<<endl;
cin>>choice1;

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;

cout << "\n(1) Customer Login"<< endl;


cout << "\n(2) Administrator Login"<< endl;
cout << "\n(3) Exit"<< 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);

cout << " ,--. ,--. ,--. ,--------.


" << endl;
cout << " | | | | ,---. | | ,---. ,---. ,--,--,--. ,---. '--. .--',---.
" << endl;
cout << " | |.'.| || .-. :| || .--'| .-. || || .-. : | | | .-. |
" << endl;
cout << " | ,'. |\ --.| |\ `--.' '-' '| | | |\ --. | | ' '-' '
" << endl;
cout << " '--' '--' `----'`--' `---' `---' `--`--`--' `----' `--' `---'
" << endl;
cout << " ,---. ,--. ,--. ,--.
,--. " << endl;
cout << " ' .-' ,--.,--. ,---. ,---. ,--.--. | `.' | ,--,--.,--.--.|
|,-. ,---. ,-' '-. " << endl;
cout << " `. `-. | || || .-. || .-. :| .--' | |'.'| |' ,-.
|| .--'| /| .-. :'-. .-' " << endl;
cout << " .-' |' '' '| '-' '\ --.| | | | | |\ '-' || |
| \ \\ --. | | " << endl;
cout << " `-----' `----' | |-' `----'`--' `--' `--' `--`--'`--'
`--'`--'`----' `--' " << endl;
cout << " `--'
" << endl;
cout << " ,-----. ,--.,--.,--.
" << endl;
cout << " | |) /_ `--'| || | ,---. ,--.--.
" << endl;
cout << " | .-. \,--.| || || .-. :| .--'
" << endl;
cout << " | '--' /| || || |\ --.| |
" << endl;
cout << " `------' `--'`--'`--' `----'`--'
" << endl;

system("pause");
p.DisplayMenu();
cout<<"Please enter your desired choice";
cin>>choice;

while((choice!=1 )&& (choice!=2)&&(choice!=3)){

cout<<"Please enter the valid input";


cin>>choice;
}
switch(choice)
{
case 1:
system("cls");
case 2:
system("cls");
adminMain();
break;
case 3:
system("cls");
exit(0);
}

You might also like