void enter();
void report();
void edit();
void del();
int menu();
struct store
{
char s_name[21];//stamp name
char p_name[21];//procedure name
long int code; //code stamp
float cost;//cost stamp
float supply;//Monthly supply stamp in last year
float sale; //Monthly sale stamp
} st;
//************
int main(){
int c;
for(;;){
clrscr();
c=menu();
switch(c){
case 1: enter();break;
case 2: edit();break;
case 3: del();break;
case 4: report();break;
case 5: exit(0);
}
}
}
//***********
int menu()
{
int p;
cout<<“1:Enter data.\n”;
cout<<“2:Edit the record.\n”;
cout<<“3:Delete the record.\n”;
cout<<“4:Report the file.\n”;
cout<<“5:Terminate program.\n”;
cout<<“Enter your select(1-5):\n”;
cin>>p;
cin.get();
return p;
}
//**************
void enter()
{
int r=2;
int n;
clrscr();
cout<<“Enter Nember Of Stamp:”;
cin>>n;
cout<<“\n”;
clrscr();
ofstream out(“store2.txt”);
if(!out){
cout<<“cannot open file.”;
getch();
exit(0);
}
gotoxy(1,1);
cout<<“StampName”;
gotoxy(20,1);
cout<<“ProcedureName”;
gotoxy(35,1);
cout<<“code”;
gotoxy(45,1);
cout<<“cost”;
gotoxy(55,1);
cout<<“Supply”;
gotoxy(65,1);
cout<<“sale\n”;
for(int k=0;k<n;k++)
{
gotoxy(1,r);
cin>>st.s_name;
gotoxy(20,r);
cin>>st.p_name;
gotoxy(35,r);
cin>>st.code;
gotoxy(45,r);
cin>>st.cost;
gotoxy(55,r);
cin>>st.supply;
gotoxy(65,r);
cin>>st.sale;
out<<st.s_name<<“\t”;;
out<<st.p_name<<“\t”;;
out<<st.code<<“\t”;;
out<<st.cost<<“\t”;
out<<st.supply<<“\t”;
out<<st.sale<<“\n”;
r++;
}
out.close();
}
//*************
void report(){
int r=3;
clrscr();
ifstream in(“store2.txt”);
if(!in){
cout<<“cannot open file.”;
getch();
exit(0);
}
gotoxy(1,1);
cout<<“StampName”;
gotoxy(20,1);
cout<<“ProcedureName”;
gotoxy(35,1);
cout<<“code”;
gotoxy(45,1);
cout<<“cost”;
gotoxy(55,1);
cout<<“Supply”;
gotoxy(65,1);
cout<<“sale\n***************\n”;
while(in>>st.s_name>>st.p_name>>st.code>>st.cost>>st.supply>>st.sale){
gotoxy(1,r);
cout<<st.s_name;
gotoxy(20,r);
cout<<st.p_name;
gotoxy(35,r);
cout<<st.code;
gotoxy(45,r);
cout<<st.cost;
gotoxy(55,r);
cout<<st.supply;
gotoxy(65,r);
cout<<st.sale<<“\n”;
r++;
}
in.close();
getch();
}
//*****************
void edit(){
long int cd;
int r=2;
cout<<“Enter a stamp code:”;
cin>>cd;
ofstream fout(“store1.txt”,ios::out);
while(fin>>st.s_name>>st.p_name>>st.code>>st.cost>>st.supply>>st.sale){
if(st.code!=cd){
fout<<st.s_name<<‘\t’;
fout<<st.p_name<<‘\t’;
fout<<st.code<<‘\t’;
fout<<st.cost<<‘\t’;
fout<<st.supply<<‘\t’;
fout<<st.sale<<‘\n’;
}
else{
cout<<” StampName:”;
gets(st.s_name);
fout<<st.s_name<<‘\t’;
cout<<” ProcedureName:”;
gets(st.p_name);
fout<<st.p_name<<‘\t’;
cout<<” code:”;
cin>>st.code;
fout<<st.code<<‘\t’;
cout<<” cost:”;
cin>>st.cost;
fout<<st.cost<<‘\t’;
cout<<” supply:”;
cin>>st.supply;
fout<<st.supply<<‘\t’;
cout<<” sale:”;
cin>>st.sale;
fout<<st.sale<<‘\n’;
cin.getline(st.s_name,20);
}
}
fin.close();
remove(“store2.txt”);
rename(“store1.txt”,”store2.txt”);
}
//***************
void del(){
long int cd;
string l;
cout<<“Enter a stamp code:”;
cin>>cd;
ifstream inf(“store2.txt”,ios::in);
ofstream outf(“store.txt”,ios::out);
while(inf>>st.s_name>>st.p_name>>st.code>>st.cost>>st.supply>>st.sale){
if(st.code!=cd){
outf<<st.s_name<<‘\t’;
outf<<st.p_name<<‘\t’;
outf<<st.code<<‘\t’;
outf<<st.cost<<‘\t’;
outf<<st.supply<<‘\t’;
outf<<st.sale<<‘\n’;
}
}
inf.close();
outf.close();
remove(“store2.txt”);
rename(“store.txt”,”store2.txt”);
}
|
دیدگاهتان را بنویسید