#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
typedef struct date
{
int yr;
int mon;
int date;
};
typedef struct bookdate
{
char bname[20];
int bnum;
char nevi[30];
};
typedef struct pf
{
char name[30];
int idnum;
int bama[3];
date bdate[3];
};
void main()
{
bookdate book[30]={"",0,""};
pf stu[30]={{"",0,{0},{0}}};
void stud();
void stud1();
void stud2();
void stud3();
void stud4(bookdate *b,pf *s);
clrscr();
a:
int d=0;
clrscr();
printf("
-------------------------------------------");
printf("
| enter number (1) for daryafte ketab |""
| enter number (2) for sabte name danesamoz |""
| enter number (3) for sabte mojodi ketab |");
printf("
| enter number (4) for mahale ketab |""
| enter number (5) for list amaniti ketab |""
| enter number (6) for exit |");
printf("
-------------------------------------------");
scanf("%d",&d);
switch (d)
{
case 1:
stud();
break;
case 2:
stud1();
break;
case 3:
stud2();
break;
case 4:
stud3();
break;
case 5:
stud4(book,stu);
break;
case 6:
exit(0);
default:
{
printf("
--------------------------
");
printf(" menu antekhabi dorost nist");
printf("
--------------------------
");
}
}
getch();
goto a;
}
void stud()
{
bookdate b[30]={{"",0,""}};
pf s[30]={0,0,{0},{0}};
FILE *fs;
FILE *fb;
int m=1110,j=2,i=0,cbook=0;
fs = fopen ("d:\lib\student.txt","r+w");
if (fs==NULL)
{
printf("
cannot read file student");
getch();
exit(1);
}
fread(&s,sizeof(s[0]),30,fs);
idnum:
printf("
enter idnum for student:");
scanf("%d",&i);
for (j=30;j >= 0;j--)
{
if (i==s[j].idnum)
{
m=j;
printf("
name student: %s",s[j].name);
}
}
if (m==1110)
{
printf("
idnum vojod nadaran");
goto idnum;
}
// darkhaste daryafte ketab
fb = fopen ("d:\lib\books.txt","rb");
if (fs==NULL)
{
printf("
cannot read file books");
getch();
exit(1);
}
fread(&b,sizeof(b[0]),30,fb);
i=1110;
booknum:
printf("
enter number book: ");
scanf("%d",&cbook);
for (j=0;j < 30;j++)
{
if (cbook==b[j].bnum)
{
i=j;
printf("
name book: %s , %s",b[i].bname,b[i].nevi);
}
}
if (i==1110)
{
printf("
number book vojod nadaran");
goto booknum;
}
rewind(fs);
if ((s[m].bama[0]!=0) && (s[m].bama[1]!=0) && (s[m].bama[2]!=0))
printf("
!!!!!! 3 ketab ghabli avorde nashode ast ");
rewind(fs);
if ((s[m].bama[0])==0 )
{
printf("
enter date(sal,mah,roz):");
scanf("%d %d %d",&s[m].bdate[0].yr,&s[m].bdate[0].mon,&s[m].bdate[0].date);
s[m].bama[0]=cbook;
fseek(fs,m*(sizeof(s[m])),0);
fwrite(&s[m],sizeof(s[m]),1,fs);
goto a;
}
if (s[m].bama[1]==0 )
{
printf("
enter date(sal,mah,roz):");
scanf("%d %d %d",&s[m].bdate[1].yr,&s[m].bdate[1].mon,&s[m].bdate[1].date);
s[m].bama[1]=cbook;
fseek(fs,m*(sizeof(s[m])),0);
fwrite(&s[m],sizeof(s[m]),1,fs);
goto a;
}
if (s[m].bama[2]==0 )
{
printf("
enter date(sal,mah,roz):");
scanf("%d %d %d",&s[m].bdate[2].yr,&s[m].bdate[2].mon,&s[m].bdate[2].date);
s[m].bama[2]=cbook;
fseek(fs,m*(sizeof(s[m])),0);
fwrite(&s[m],sizeof(s[m]),1,fs);
}
a:
fclose(fs);
fclose(fb);
}
void stud1()
{
pf s[30]={0,0,{0},{0}};
FILE *fs;
fs = fopen ("d:\lib\student.txt","a+b");
if (fs==NULL)
{
printf("
cannot open file student");
getch();
exit(1);
}
int i=0,j=0;
fread(&s,sizeof(s[0]),30,fs);
for (i=0;i<30;i++)
{
if (s[i].idnum == 0)
{
printf("
enter name and idcode for student: ");
scanf("%s %d",&s[i].name,&s[i].idnum);
fwrite(&s[i],sizeof(s[0]),1,fs);
goto stexit;
}
else
printf("
%-15s = %d",s[i].name,s[i].idnum);
}
stexit:
fclose(fs);
}
void stud2()
{
bookdate b[30]={"",0,""};
FILE *fb;
fb = fopen ("d:\lib\books.txt","a+b");
if (fb==NULL)
{
printf("
cannot open file books");
getch();
exit(1);
}
fread(&b,sizeof(b[0]),30,fb);
int i=0,j=0;
for (i=0;i<30;i++)
{
if (b[i].bnum == 0)
{
printf("
enter name , code and navisandeh for book: ");
scanf("%s %d %s",&b[i].bname,&b[i].bnum,&b[i].nevi);
fwrite(&b[i],sizeof(b[0]),1,fb);
goto bexit;
}
else
printf("
%-15s = %d = %s",b[i].bname,b[i].bnum,b[i].nevi);
}
bexit:
fclose(fb);
}
void stud3()
{
FILE *fs;
FILE *fb;
int m=1110,j=2,i=1110,cbook=0;
bookdate b[30]={{"",0,""}};
pf s[30]={0,0,{0},{0}};
fs = fopen("d:\lib\student.txt","rb");
if (fs==NULL)
{
printf("
cannot open file student");
getch();
exit(1);
}
fb = fopen ("d:\lib\books.txt","rb");
if (fs==NULL)
{
printf("
cannot open file books");
getch();
exit(1);
}
booknum:
fread(&s,sizeof(s[0]),30,fs);
fread(&b,sizeof(b[0]),30,fb);
printf("
enter number book: ");
scanf("%d",&cbook);
for (j=30;j >= 0;j--)
{
if (cbook==b[j].bnum)
{
i=j;
printf("
name book: %s , %s",b[i].bname,b[i].nevi);
}
}
if (i==1110)
{
printf("
number book vojod nadaran");
goto booknum;
}
for (j=0;j < 30 ;j++)
{
if ((b[i].bnum == s[j].bama[0]) || (b[i].bnum == s[j].bama[1]) || (b[i].bnum == s[j].bama[2]))
{
printf("
ketab hast nazde: %s",s[j].name);
m=1;
goto ke;
}
}
if (m==1110)
printf("
-------------------------");
printf("
ketab hast dar ketabkhane");
printf("
-------------------------");
ke:
fcloseall();
getch();
}
void stud4(bookdate *b,pf *s)
{
int m=1110,j=2,i=0;
idnum:
printf("
enter idnum for student:");
scanf("%d",&i);
for (j=30;j >= 0;j--)
{
if (i==s[j].idnum)
{
m=j;
printf("
name student: %s",s[m].name);
}
}
if (m==1110)
{
printf("
idnum vojod nadaran");
goto idnum;
}
i=1110;
for (j=0;j < 30;j++)
{
if ((b[j].bnum==s[m].bama[0]) && (s[m].bdate[0].yr !=0))
{
i=j;
printf("
%-10s %-10s date %d/%d/%d ",b[i].bname,b[i].nevi,s[m].bdate[0].yr,s[m].bdate[0].mon,s[m].bdate[0].date);
}
if ((b[j].bnum==s[m].bama[1]) && (s[m].bdate[1].yr !=0))
{
i=j;
printf("
%-10s %-10s date %d/%d/%d ",b[i].bname,b[i].nevi,s[m].bdate[1].yr,s[m].bdate[1].mon,s[m].bdate[1].date);
}
if ((b[j].bnum==s[m].bama[2]) && (s[m].bdate[2].yr !=0))
{
i=j;
printf("
%-10s %-10s date %d/%d/%d ",b[i].bname,b[i].nevi,s[m].bdate[2].yr,s[m].bdate[2].mon,s[m].bdate[2].date);
}
}
if (i==1110)
printf("
ketabi dade nashode ast");
getch();
}
#include
void main()
{
int Baghimande = 0;
int KharejeGhesmat = 10;
int Mabna = 0;
int Adad = 0;
int i = 0;
int Counter = 0;
int Javab[50];
cout << "Adad ra vared konid : ";
cin >> Adad;
cout << "Mabna ra vared konid : ";
cin >> Mabna;
for(Counter=0;KharejeGhesmat>=Mabna;Counter++)
{
KharejeGhesmat = Adad / Mabna;
Baghimande = Adad % Mabna;
Adad = KharejeGhesmat;
Javab[Counter] = Baghimande;
}
Javab[Counter] = KharejeGhesmat;
for(i=Counter;i>=0;i--)
{
cout << Javab[i];
}
}