سورس فروشگاه به زبان C++

Sarp

مدیر بازنشسته
کد:
[LEFT]#include <iostream.h>
#include <conio.h>
#include <io.h>
#include <string.h>
#include <stdio.h>
#include <process.h>

typedef struct sandogh
{
int input1;
char date1[30];
};
typedef struct factor
{
int code_k;
int code_c;
int count;
};

typedef struct input_p_k
{
    char name_k[30];
    char type_k[30];
    char date[30];
    int price_all;
    int price_k;
    int price_k_kh;
    int count_k;
    int code_k;
    int resid_f;
    int resid_a;

};//end of structure vorodi
typedef struct input_p_c
{
    char name_c[30];
    char type_c[30];
    char tell_c[30];
    int code_c;

};//end of structure vorodi
class input_customer
{
private:
input_p_c v_input_c,t;
public:
void input_c();
void fac();
};//end of class input
void input_customer::input_c()
{
clrscr();
cout<<"\nPlease Insert Name Of Your Customer: ";
cin>>v_input_c.name_c;
cout<<"\nPlease Insert Type Of Your Customer: ";
cin>>v_input_c.type_c;
cout<<"\nPlease Insert Tell Of Your Customer: ";
cin>>v_input_c.tell_c;
cout<<"\nPlease Insert Code Of Your Customer: ";
cin>>v_input_c.code_c;
if (v_input_c.name_c=="" && v_input_c.code_c==0)
{
cout<<"You Must Give All Information For Save In Bank";
}
else
{
FILE *f;
int y;
f=fopen("Customer.txt","a+b");
if (f!=NULL)
{
while (!feof(f))
{
fread(&t,sizeof(struct input_p_c),1,f);
if (v_input_c.code_c==t.code_c)
{
y=1;
break;
}
}
if (y!=1)
{
fwrite(&v_input_c,sizeof(struct input_p_c),1,f);
fclose(f);
}
else
{
cout<<"Code Is Valid IN Bank,You Can't Save This Code";
getch();
}
}
else
{
cout<<"The Program Can't Creat File And Saved Information";
}
}
}

class input_anbar
{
private:
input_p_k v_input_k;
public:
void input_k();
void fac();
};//end of class input

void input_anbar::input_k()
{
clrscr();
cout<<"\nPlease Insert Name Of Your Product: ";
cin>>v_input_k.name_k;
cout<<"\nPlease Insert Type Of Your Product: ";
cin>>v_input_k.type_k;
cout<<"\nPlease Insert Count Of Your Product: ";
cin>>v_input_k.count_k;
cout<<"\nPlease Insert Price Buy  Of Your Product: ";
cin>>v_input_k.price_k_kh;
cout<<"\nPlease Insert Price Forosh Of Your Product: ";
cin>>v_input_k.price_k;
cout<<"\nPlease Insert Date Of Save Product: ";
cin>>v_input_k.date;
cout<<"\nPlease Insert Code Of Your Product: ";
cin>>v_input_k.code_k;
cout<<"\nPlease Insert Shomareh Resid Foroshandeh: ";
cin>>v_input_k.resid_f;
cout<<"\nPlease Insert Shomare Resid Anbar: ";
cin>>v_input_k.resid_a;
if (v_input_k.name_k=="" && v_input_k.code_k==0)
{
cout<<"You Must Give All Information For Save In Bank";
}
else
{
FILE *f,*f1,*f2,*f3;
input_p_k i;
sandogh s,v;
int u;
v_input_k.price_all=(v_input_k.count_k)*(v_input_k.price_k_kh);

f2=fopen("Sandogh.txt","rb");
if (f2==NULL)
{
cout<<"\nMojodi Anbar Kamtar AZ minane kharide shomast";
getch();
}
else
{
f=fopen("Anbar.txt","a+b");
f1=fopen("Factorbuy.txt","a+b");
f3=fopen("Sandogh1.txt","a+b");
rewind(f2);
//do
//{
fread(&s,sizeof(struct sandogh),1,f2);
//}while (!feof(f2));
strcpy(v.date1,s.date1);
v.input1=(s.input1)-(v_input_k.price_all);
if (v.input1<0)
{
cout<<"\nMojodi Anbar Kamtar AZ minane kharide shomast";
fclose(f);
fclose(f1);
fclose(f2);
fclose(f3);
getch();
}
else
{
while (!feof(f))
{
fread(&i,sizeof(struct input_p_k),1,f);
if (v_input_k.code_k==i.code_k)
{
u=1;
break;
}
}
if (u!=1)
{
if (f!=NULL)
{
clrscr();
fwrite(&v,sizeof(struct sandogh),1,f3);
fwrite(&v_input_k,sizeof(struct input_p_k),1,f);
fwrite(&v_input_k,sizeof(struct input_p_k),1,f1);
fclose(f);
fclose(f1);
fclose(f2);
fclose(f3);
remove("Sandogh.txt");
rename("Sandogh1.txt","Sandogh.txt");
gotoxy(25,11);
cout<<"Fi";
gotoxy(43,11);
cout<<"Noe Jens";
gotoxy(29,11);
cout<<"tedad";
gotoxy(38,30);
cout<<"Emza Kharidar";
gotoxy(30,13);
cout<<v_input_k.count_k;
gotoxy(20,30);
cout<<v_input_k.price_k_kh*v_input_k.count_k;
gotoxy(37,13);
cout<<v_input_k.name_k;
gotoxy(22,6);
cout<<"Forosh Gahe Zanjireie Isfahan";
gotoxy(20,8);
cout<<"Resid Anbar:"<<v_input_k.resid_a;
gotoxy(35,8);
cout<<"Resid Kharid:"<<v_input_k.resid_f;
gotoxy(20,13);
cout<<v_input_k.price_k_kh;
fac();
}
else
{
cout<<"The Program Can't Creat File And Saved Information";
}
}
else
{
fclose(f);
fclose(f1);
fclose(f2);
fclose(f3);
cout<<"Code Is Valid In bank";
getch();
}
}
}
}
remove("Sandogh1.txt");
}//function program
void sandogh_v();
void sod();
void show();
void buy_k();
void factor_p();
void report_buy();
void report_p();
void add_c();
void main()
{
textbackground(1);
textcolor(6);
clrscr();
int i;
input_customer c;
input_anbar a;
while (100){
clrscr();

cout<<"\n1-Add Product In Bank";
cout<<"\n2-Add Customer In bank";
cout<<"\n3-Add Money In Bank";
cout<<"\n4-Add Count Of Product";
cout<<"\n5-Buy Product";
cout<<"\n6-Factor Of Product";
cout<<"\n7-Report Of Product";
cout<<"\n8-Report Of Customer That Buy This Product";
cout<<"\n9-Mohasebe Sod Product";
cout<<"\n10-Exit";
cout<<"\nInsert Parametr: ";
cin>>i;
switch (i)
{
case 1:
a.input_k();
break;
case 2:
c.input_c();
break;
case 3:
sandogh_v();
break;
case 4:
add_c();
break;
case 5:
buy_k();
break;
case 6:
factor_p();
break;
case 7:
report_p();
break;
case 8:
report_buy();
//show();
//clrscr();
//a.fac();
break;
case 9:
sod();
break;
case 10:
exit(0);
break;
}
}
}//end main
void sod()
{
clrscr();
FILE *f,*f1;
input_p_k a;
factor fact;
int i,j,x,y,c,s,z,sod,h,m,n;
i=j=x=c=y=0;
f1=fopen("FactorF.txt","rb");
f=fopen("FactorBuy.txt","rb");
cout<<"Insert Code Of Product: ";
cin>>i;
if (i!=0)
{
while (!feof(f))
{
fread(&a,sizeof(struct input_p_k),1,f);
if (i==a.code_k)
{
x=x+a.price_k_kh;
y=y+a.price_k;
n=n+a.count_k;
c++;
while (!feof(f1))
{
fread(&fact,sizeof(struct factor),1,f1);
if (i==fact.code_k)
{
j=j+fact.count;
continue;
}//end if
}//end while
}//end if
}//while
if (c==0)
{
cout<<"Code Is Not Valid";
}
else
{
x=x/c;//miyangin kharid
y=y/c;//miyangin forosh
s=x*(j-fact.count);//tedadf*kharid
z=y*(j-fact.count);//tedadf*forosh
m=n*y;//kole kala
h=z-s;//sod poli
sod=(h*100)/m;
cout<<"Sod Kala be Darsad:%"<<sod<<endl;
cout<<"Sod Kala be Pol: "<<h;
}
}
fcloseall();
getch();
}
void factor_p()
{
clrscr();
FILE *f;
input_p_k a;
input_anbar t;
int i,j;
f=fopen("FactorBuy.txt","rb");
cout<<"Insert Code Of Product For Factor: ";
cin>>i;
if (i!=0)
{
while (!feof(f))
{
fread(&a,sizeof(struct input_p_k),1,f);
if (i==a.code_k)
{
j=1;
clrscr();
gotoxy(25,11);
cout<<"Fi";
gotoxy(43,11);
cout<<"Noe Jens";
gotoxy(29,11);
cout<<"tedad";
gotoxy(38,30);
cout<<"Emza Kharidar";
gotoxy(30,13);
cout<<a.count_k;
gotoxy(20,30);
cout<<a.price_k_kh*a.count_k;
gotoxy(37,13);
cout<<a.name_k;
gotoxy(22,6);
cout<<"Forosh Gahe Zanjireie Isfahan";
gotoxy(20,8);
cout<<"Resid Anbar:"<<a.resid_a;
gotoxy(35,8);
cout<<"Resid Forosh:"<<a.resid_f;
gotoxy(20,13);
cout<<a.price_k_kh;
t.fac();
continue;
}//end if in while
}//end while 1
}//end if 1
if (j==1)
{

}
else
{
cout<<"The Code Is Not Valid";
getch();
}
}
void report_p()
{
clrscr();
FILE *f,*f2;
input_p_k a;
input_p_c b;
input_anbar t;
factor fact;
int i,mande,forokhte=0;
f=fopen("FactorF.txt","rb");
f2=fopen("Anbar.txt","rb");
cout<<"Insert Code Of Product: ";
cin>>i;
int flag=1;
if (i!=0)
{
while (!feof(f2))
{
fread(&a,sizeof(struct input_p_k),1,f2);
if (i==a.code_k)
{
mande=a.count_k;
flag=0;
break;
}//end if
else
{
flag=1;
}
}//end while
}//end if
if (i!=0)
{
while (!feof(f))
{
fread(&fact,sizeof(struct factor),1,f);
if (i==fact.code_k)
{
forokhte=fact.count+forokhte;
}//end if
}//end while
}//end if
clrscr();
if (flag!=1)
{
cout<<"\nTedade Mandeh: "<<mande;
if ((forokhte-fact.count)<=0)
{
forokhte=0;
cout<<"\nTedade Forokhtehe Shode: "<<forokhte;
}
else
{
cout<<"\nTedade Forokhtehe Shode: "<<forokhte-fact.count;
}
}
else
{
cout<<"The Code Is Not Valid";
}



getch();
fcloseall();
}

void report_buy()
{
clrscr();
FILE *f,*f1,*f2;
input_p_k a;
input_p_c b;
input_anbar t;
factor fact;
int i,j;
f=fopen("FactorF.txt","rb");
f1=fopen("Customer.txt","rb");
f2=fopen("Anbar.txt","rb");
cout<<"Insert Code Of Product: ";
cin>>i;
if (i!=0)
{
while (!feof(f))
{
fread(&fact,sizeof(struct factor),1,f);
if (i==fact.code_k)
{
rewind(f1);
while (!feof(f1))
{
fread(&b,sizeof(struct input_p_c),1,f1);
if (fact.code_c==b.code_c)
{
rewind(f2);
while (!feof(f2))
{
fread(&a,sizeof(struct input_p_k),1,f2);
if (a.code_k==fact.code_k)
{
clrscr();
gotoxy(25,11);
cout<<"Fi";
gotoxy(43,11);
cout<<"Noe Jens";
gotoxy(29,11);
cout<<"tedad";
gotoxy(30,30);
cout<<"Name Kharidar: "<<b.name_c;
gotoxy(30,13);
cout<<fact.count;
gotoxy(20,30);
cout<<a.price_k*fact.count;
gotoxy(37,13);
cout<<a.name_k;
gotoxy(22,6);
cout<<"Forosh Gahe Zanjireie Isfahan";
gotoxy(20,8);
cout<<"Resid Anbar:"<<a.resid_a;
gotoxy(35,8);
cout<<"Resid Forosh:"<<a.resid_f;
gotoxy(20,13);
cout<<a.price_k;
t.fac();
break;
}//end if
}//end while
break;
}
}
}//end if in while
}//end while 1
}//end if 1
fcloseall();
}
void add_c()
{
clrscr();
FILE *f,*f1,*f2,*f3,*f4;
input_p_k k;
sandogh s;
input_anbar t;
int i,j,x,y,m,m1,n,b;
y=0;
x=0;
cout<<"Insert Code Of Your Product :";
cin>>i;
cout<<"Insert Count Of Your Product :";
cin>>j;
cout<<"Insert New Money Of Buy Your Product :";
cin>>m;
cout<<"Insert New Money Of Forosh Your Product :";
cin>>m1;
cout<<"Insert Shomare Resid Foroshandeh :";
cin>>n;
cout<<"Insert Shomare Resid Anbar:";
cin>>b;
if (i!=0)
{
f=fopen("Anbar.txt","rb");
f1=fopen("Sandogh.txt","rb");
f2=fopen("Anbar1.txt","a+b");
f3=fopen("Sandogh1.txt","a+b");
f4=fopen("Factorbuy.txt","a+b");
if (f!=NULL)
{
while (!feof(f))
{
fread(&k,sizeof(struct input_p_k),1,f);
if (k.code_k==i)
{
x=1;
rewind(f1);
fread(&s,sizeof(struct sandogh),1,f1);
if (s.input1>(m*j))
{

k.count_k=j+k.count_k;
k.price_k_kh=m;
k.price_k=m1;
fwrite(&k,sizeof(struct input_p_k),1,f2);
s.input1=(s.input1)-(m*j);
rewind(f3);
k.resid_a=b;
k.resid_f=n;
k.count_k=j;
fwrite(&k,sizeof(struct input_p_k),1,f4);
fwrite(&s,sizeof(struct sandogh),1,f3);
break;
}
else
{
y=1;
}//else if 2 in while 1  mojodi kamtar

}//on ife
else
{
fwrite(&k,sizeof(struct input_p_k),1,f2);
}//end of else in while 1 if 1
}//end while 1
}//end if 2
}//end if 1
if (x==1 && y==0)
{
remove("Anbar.txt");
rename("Anbar1.txt","Anbar.txt");
remove("Sandogh.txt");
rename("Sandogh1.txt","Sandogh.txt");
clrscr();
gotoxy(25,11);
cout<<"Fi";
gotoxy(43,11);
cout<<"Noe Jens";
gotoxy(29,11);
cout<<"tedad";
gotoxy(38,30);
cout<<"Emza Kharidar";
gotoxy(30,13);
cout<<j;
gotoxy(20,30);
cout<<m*j;
gotoxy(37,13);
cout<<k.name_k;
gotoxy(22,6);
cout<<"Forosh Gahe Zanjireie Isfahan";
gotoxy(20,8);
cout<<"Resid Anbar:"<<k.resid_a;
gotoxy(35,8);
cout<<"Resid Forosh:"<<k.resid_f;
gotoxy(20,13);
cout<<k.price_k_kh;
t.fac();
}
else
{
if (y==1)
{
cout<<"Mojodi Sandogh Kamtar Az Mizane Kharide Shomast";
getch();
}
else
{
cout<<"The Code Is Not Valid";
getch();
}

}
fclose(f);
fclose(f1);
fclose(f2);
fclose(f3);
remove("Anbar1.txt");
remove("Sandogh1.txt");
fcloseall();
}// end of fuction
void sandogh_v()
{
clrscr();
sandogh s;
sandogh t;
FILE *f,*f1;
cout<<"Insert Money Vorodi: ";
cin>>t.input1;
cout<<"Insert Money Vorodi: ";
cin>>t.date1;
f=fopen("Sandogh.txt","rb");
f1=fopen("Sandogh1.txt","a+b");
//rewind(f);
fread(&s,sizeof(struct sandogh),1,f);
if (!f)
{
fclose(f);
f=fopen("Sandogh.txt","a+b");
fwrite(&t,sizeof(struct sandogh),1,f);
remove("Sandogh1.txt");
}
else
{
t.input1=s.input1+t.input1;
fwrite(&t,sizeof(struct sandogh),1,f1);
remove("Sandogh.txt");
rename("Sandogh1.txt","Sandogh.txt");
cout<<"Information Saved In Bank";
getch();
fclose(f1);

}
fclose(f);
}
void buy_k()
{
clrscr();
factor fact;
input_p_c c1,c2;
input_p_k k1,k2;
int u=0,kl=0;
int g,g1,flag,flag1;
FILE *f,*f1,*f2,*f3,*f4,*f5;
cout<<"\nInsert Code Of Product For Buy: ";
cin>>fact.code_k;
cout<<"\nInsert Code Of Customer: ";
cin>>fact.code_c;
cout<<"\nInsert Count Of Product For Buy: ";
cin>>fact.count;
if (fact.code_k!=0 && fact.code_c!=0 && fact.count!=0)
{
sandogh t;
f=fopen("Customer.txt","rb");
f1=fopen("Anbar.txt","rb");
f2=fopen("Anbar1.txt","a+b");
f3=fopen("FactorF.txt","a+b");
f4=fopen("Sandogh.txt","rb");
f5=fopen("Sandogh1.txt","a+b");
g=0;
flag1=0;
g1=0;
do
{
fread(&c1,sizeof(struct input_p_c),1,f);
if (u==11)
{
break;
}
if (fact.code_c==c1.code_c)
{

g=1;
flag=1;
kl=0;
do
{

fread(&k1,sizeof(struct input_p_k),1,f1);
if (fact.code_k==k1.code_k)
{
k1.count_k=k1.count_k-(fact.count);
kl=1;
flag1=1;
if (k1.count_k>=0)
{
fwrite(&k1,sizeof(struct input_p_k),1,f2);
k2.count_k=k1.count_k;
k2.price_k=k1.price_k;
strcpy(k2.name_k,k1.name_k);
strcpy(c2.tell_c,c1.tell_c);
strcpy(c2.name_c,c1.name_c);
u=1;
g1=1;
}
else
{
g1=0;
}
rewind(f4);
fread(&t,sizeof(struct sandogh),1,f4);
t.input1=t.input1+(fact.count*k1.price_k);
fwrite(&t,sizeof(struct sandogh),1,f5);
}//end if
else
{
fwrite(&k1,sizeof(struct input_p_k),1,f2);
}
 }while (!feof(f1));//end while2
  }//end if
  else
 {
 //g=0;
 }
  //end else

 }while (!feof(f)); //end while
fclose(f1);
fclose(f);
fclose(f2);
fclose(f4);
fclose(f5);
    }//end if 1
clrscr();
if (g==0)
{
cout<<"Your Customer Code Is Not Valid";
}
else
{
if ((kl==0 || flag==0) && flag1==0)
{
cout<<"Your Product Code Is Not Valid";
}
}
if (g1==0 && flag1==1)
{
cout<<"Mojodi Anbar Kamtar Az Mizane Kharide Shomast";
}
if (u==1)
{
remove("Anbar.txt");
rename("Anbar1.txt","Anbar.txt");
remove("Sandogh.txt");
rename("Sandogh1.txt","Sandogh.txt");
fwrite(&fact,sizeof(struct factor),1,f3);
input_anbar t;
gotoxy(25,11);
cout<<"Fi";
gotoxy(43,11);
cout<<"Noe Jens";
gotoxy(29,11);
cout<<"tedad";
gotoxy(38,30);
cout<<c2.name_c;
gotoxy(30,13);
cout<<fact.count;
gotoxy(20,30);
cout<<(k2.price_k*fact.count);
gotoxy(37,13);
cout<<k2.name_k;
gotoxy(22,6);
cout<<"Forosh Gahe Zanjireie Isfahan";
gotoxy(20,8);
cout<<"Name: "<<c2.name_c;
gotoxy(35,8);
cout<<"Tell: "<<c2.tell_c;
gotoxy(20,13);
cout<<k2.price_k;
t.fac();
}
remove("Anbar1.txt");
remove("Sandogh1.txt");
getch();
fclose(f3);
//fcloseall();
} //end function

void input_anbar::fac()
{
gotoxy(19,5);
cout<<"----------------------------------";
gotoxy(19,10);
cout<<"----------------------------------";
gotoxy(19,12);
cout<<"----------------------------------";
gotoxy(20,32);
cout<<"---------------------------------";
gotoxy(20,28);
cout<<"---------------------------------";
for (int i=5;i<=32;i++)
{
gotoxy(19,i);
cout<<"-";
}
for (i=6;i<=32;i++)
{
gotoxy(53,i);
cout<<"-";
}
for (i=10;i<=32;i++)
{
gotoxy(28,i);
cout<<"-";
}
for (i=11;i<=27;i++)
{
gotoxy(33,i);
cout<<"-";
}
gotoxy(25,10);
cout<<"-";
getch();
};

[/LEFT]
 

Similar threads

بالا