PDA

View Full Version : سوال: درخواست توضیحات برای یک برنامه



amirsaberi
یک شنبه 12 دی 1389, 17:11 عصر
با سلام خدمت دوستان گرامی

من یک باز این ور و اونور کپی کردم فردا هم باید به عنواع پروژه تحویل بدم اگر ممکن هست یک سری جاهاش رو برام معنی کنید که چیکار میکنه.

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <iostream.h>
#include <string.h>
#include <ctype.h>
#define SIZE 100
struct student {
char name [10] ;
int stno, jensiat ;
char book [10] ;
char name2 [20] ;
char nasher[20], nevisande[20] ;
int shabak ;
} list[SIZE];
struct book {
char name2 [20] ;
char nasher[20], nevisande[20] ;
} list2[SIZE];
int menu(void) ;
void init_list(void) , enter(void) ;
void display(void) , save(void) ;
void load(void);
void init_list2(void) , enter2(void) ;
void display2(void) , save2(void) ;
int main(){
init_list();
init_list2();
for(;;) {
switch(menu()) {
case 'e': enter(); break;
case 'b': enter2(); break;
case 'd': display(); break;
case 'n': display2(); break;
case 's': save() ; break;
case 'a': save2() ; break;
case 'l': load() ; break;
case 'q': exit(0) ;
}//end of switch
}//end of for
}//end of main
//*********
void init_list(void)
{
register int t;
for(t=0;t< SIZE;t++)
*(list[t].name)= '\0' ;
}
//********
void enter(void)
{
register int i;
int row;
char numstr[10];
for(i=0;i<SIZE;i++)
if(!(*list[i].name))
break;
if(i==SIZE){
printf("\n list is full press a key ...");
getch();
}
clrscr();
gotoxy(10,2);
puts(" << Gheytarie Library >>\n");
gotoxy(1,3);
printf(" First&Last Name shomare karbari books jens(1,2)");
gotoxy(1,4);
puts(" ------------- -------------- ----------- ------");
row = 5;
for(;;) {
gotoxy(5, row);
gets(list[i].name);
if(! (*list[i].name))
break ;
gotoxy(28, row);
gets(numstr);
list[i].stno = atoi(numstr);
gotoxy(49,row);
gets(list[i].book);
gotoxy(68, row) ;
gets(numstr);
list[i].jensiat = atoi(numstr);
row ++;
i ++;
}

}
///***************
void display(void)
{
register int t;
int row;
clrscr();
gotoxy(10,2);
puts(" << Gheytarie Library >>");
gotoxy(1,3);
printf(" First&Last Name shomare karbari books jens(1,2)");
gotoxy(1,4);
printf(" ------------- -------------- ----------- ------");
row = 5;
for(t=0;t< SIZE;t++)
if(*list[t].name) {
gotoxy(5,row);
printf("%s", list[t].name);
gotoxy(28,row);
printf("%d", list[t].stno);
gotoxy(49,row);
printf("%s", list[t].book);
gotoxy(68, row);
printf("%d", list[t].jensiat);
row ++;
}//end of if
gotoxy(5,row+2);
printf("press a key...");
getch();
}
//*************
void save(void)
{
FILE *fp;
register int i;
fp=fopen("person", "wb");
if(!fp) {
printf("\n cannot open file press a key...");
getch();
return;
}
for(i=0;i< SIZE;i++)
if(*list[i].name)
fwrite(&list[i], sizeof(struct student), 1, fp);
clrscr();
gotoxy(20, 10);
printf("User & Book File is saved. press a key.");
getch();
fp=fopen("book", "wb");
if(!fp) {
printf("\n cannot open file press a key...");
getch();
return;
}
for(i=0;i< SIZE;i++)
if(*list[i].name)
fwrite(&list[i], sizeof(struct book), 1, fp);
}
//**************
void load (void)
{
FILE *fp;
register int i;
fp=fopen("person", "rb");
if(!fp) {
printf("\n cannot open file press a key...");
getch();
return;
}
init_list();
for(i=0;i<SIZE;i++) {
fread(&list[i],sizeof(struct student), 1, fp);
if(feof(fp)) {
clrscr();
gotoxy(20,10);
printf("User & Book file is loaded.press a key.");
getch();
return;
}//end of if
}
fp=fopen("book", "rb");
if(!fp) {
printf("\n cannot open file press a key...");
getch();
return;
}
init_list();
for(i=0;i<SIZE;i++) {
fread(&list[i],sizeof(struct book), 1, fp);
if(feof(fp)) {
clrscr();
gotoxy(20,10);
printf("data loaded.press a key.");
getch();
return;
}//end of if
}
}
//****************************book**************
void init_list2(void)
{
register int t;
for(t=0;t< SIZE;t++)
*(list[t].name2)= '\0' ;
}
//********
void enter2(void)
{
register int i;
int row;
char numstr[10];
for(i=0;i<SIZE;i++)
if(!(*list[i].name2))
break;
if(i==SIZE){
printf("\n list is full press a key ...");
getch();
}
clrscr();
gotoxy(10,2);
puts(" << Gheytarie Library >>");
gotoxy(1,3);
printf(" Book name nasher nevisande shapa");
gotoxy(1,4);
puts(" ------------- -------------- ----------- ------");
row = 5;
for(;;) {
gotoxy(5, row);
gets(list[i].name2);
if(! (*list[i].name2))
break ;
gotoxy(28, row);
gets(list[i].nasher);
gotoxy(49,row);
gets(list[i].nevisande);
gotoxy(68, row) ;
gets(numstr);
list[i].shabak = atoi(numstr);
row ++;
i ++;
}

}
///***************
void display2(void)
{
register int t;
int row;
clrscr();
gotoxy(10,2);
puts(" << Books Library >>");
gotoxy(1,3);
printf(" Book name nasher nevisande shapa");
gotoxy(1,4);
printf(" ------------- -------------- ----------- ------");
row = 5;
for(t=0;t< SIZE;t++)
if(*list[t].name2) {
gotoxy(5,row);
printf("%s", list[t].name2);
gotoxy(28,row);
printf("%s", list[t].nasher);
gotoxy(49,row);
printf("%s", list[t].nevisande);
gotoxy(65,row);
printf("%d", list[t].shabak);
row ++;
}//end of if
gotoxy(5,row+2);
printf("press a key...");
getch();
}
//*************
void save2(void)
{
FILE *fp;
register int i;
fp=fopen("book", "wb");
if(!fp) {
printf("\n cannot open file press a key...");
getch();
return;
}
for(i=0;i< SIZE;i++)
if(*list[i].name)
fwrite(&list[i], sizeof(struct book), 1, fp);
clrscr();
gotoxy(20, 10);
printf("data saved. press a key.");
getch();
}
//*******
int menu(void)
{
char s[10];
clrscr();
do{
gotoxy(20, 4);
printf("E) Create a user ");
gotoxy(20, 6);
printf("B) enter book ");
gotoxy(20, 8);
printf("D) display on screen");
gotoxy(20, 10);
printf("n) display books on screen");
gotoxy(20,12);
printf("L) load user & book files");
gotoxy(20,14);
printf("S) Save user & book files");
gotoxy(20,16);
printf("Q) quit");
gotoxy(20, 18);
printf("enter your select:");
gets(s);
}while(!strchr("ebdnlaswq", tolower(*s)));
return tolower(*s);
}

1.س
2. list[SIZE]; چی هست؟
3. init_list();
init_list2(); اینا یعنی چی؟
4. کار این چیه؟ void init_list(void)
5. در اینجا register int t; کاره Register چی هست؟
6.numstr کارش چی هست؟
6. if(! (*list[i].name))
break ; این یعنی چی؟
7. atoi(numstr); در اینجا Atoi یعنی چی؟
8. fp=fopen("person", "wb"); در اینجا fp یعنی چی؟
9. FILE *fp; این چه کاری انجام میده؟

دوستان هرکسی تا هرجایش رو بتونه بگه خیلی لطف کرده. فقط یکم عجله دارم ممنون