#include<iostream>
#include<conio.h>
#include<string>
#include<vector>
#include<cstdlib>
#include<fstream>
using namespace std;
class shop
{
private:
int price;
string name,serial;
public:
void set_price(int p)
{
price=p;
}
int get_price()
{
return price;
}
void set_name(string n)
{
name=n;
}
string get_name()
{
return name;
}
void set_serial(string s)
{
serial=s;
}
string get_serial()
{
return serial;
}
};
void write()
{ int i=0;
shop temp[100];
char ch='y';
string s;
string n;
int p;
ofstream outfile("store.dat",ios::binary);
while(ch=='y')
{
cout<<"enter the name itom"<<endl;
cin>>n;
temp[i].set_name(n);
cout<<"enter the serial of itom"<<endl;
cin>>s;
temp[i].set_serial(s);
cout<<"enter the price of itom"<<endl;
cin>>p;
temp[i].set_price(p);
outfile.write(reinterpret_cast<char*>(&temp[i]),sizeof(temp[i]));
cout<<"enter y for continue"<<endl;
i++;
cin>>ch;
}
outfile.close();}
void bill()
{
string n;
int sum=0;
int qty;
int i=0;
shop temp;
ifstream infile("store.dat",ios::binary);
if(infile==NULL)
cout<<"null";
char ch='y';
while(ch=='y')
{
cout<<"enter the name of itom";
cin>>n;
while(i<=100)
{
infile.read(reinterpret_cast<char*>(&temp),sizeof(temp));
if(temp.get_name()==n)
{
cout<<"enter quantity";
cin>>qty;
sum=sum+(temp.get_price()*qty);
}
else
cout<<"not found";
i++;
}
cout<<"enter y";
cin>>ch;}
cout<<sum<<endl;
infile.close();}
int main()
{int option;
cout<<"if you are usin this programme 1st time then plz make a file first by entering 1"<<endl;
cout<<"enter 1 for writing new itoms an 2 for bill calculation"<<endl;
cin>>option;
switch(option)
{
case 1:
write();
break;
case 2:
bill();
break;
default:
cout<<"invalid output";
}
system("pause");
}
#include<conio.h>
#include<string>
#include<vector>
#include<cstdlib>
#include<fstream>
using namespace std;
class shop
{
private:
int price;
string name,serial;
public:
void set_price(int p)
{
price=p;
}
int get_price()
{
return price;
}
void set_name(string n)
{
name=n;
}
string get_name()
{
return name;
}
void set_serial(string s)
{
serial=s;
}
string get_serial()
{
return serial;
}
};
void write()
{ int i=0;
shop temp[100];
char ch='y';
string s;
string n;
int p;
ofstream outfile("store.dat",ios::binary);
while(ch=='y')
{
cout<<"enter the name itom"<<endl;
cin>>n;
temp[i].set_name(n);
cout<<"enter the serial of itom"<<endl;
cin>>s;
temp[i].set_serial(s);
cout<<"enter the price of itom"<<endl;
cin>>p;
temp[i].set_price(p);
outfile.write(reinterpret_cast<char*>(&temp[i]),sizeof(temp[i]));
cout<<"enter y for continue"<<endl;
i++;
cin>>ch;
}
outfile.close();}
void bill()
{
string n;
int sum=0;
int qty;
int i=0;
shop temp;
ifstream infile("store.dat",ios::binary);
if(infile==NULL)
cout<<"null";
char ch='y';
while(ch=='y')
{
cout<<"enter the name of itom";
cin>>n;
while(i<=100)
{
infile.read(reinterpret_cast<char*>(&temp),sizeof(temp));
if(temp.get_name()==n)
{
cout<<"enter quantity";
cin>>qty;
sum=sum+(temp.get_price()*qty);
}
else
cout<<"not found";
i++;
}
cout<<"enter y";
cin>>ch;}
cout<<sum<<endl;
infile.close();}
int main()
{int option;
cout<<"if you are usin this programme 1st time then plz make a file first by entering 1"<<endl;
cout<<"enter 1 for writing new itoms an 2 for bill calculation"<<endl;
cin>>option;
switch(option)
{
case 1:
write();
break;
case 2:
bill();
break;
default:
cout<<"invalid output";
}
system("pause");
}