تبليغاتX
خانه ای اینترنتی برای برنامه نویسان
خانه | آرشیو | پست الکترونیک
++c سورس برنامه بانک اطلاعاتی از دانشجویان به زبان

#include
#include
#include
#include
#include
#define SIZE 100
struct student {
   char name [10] ;
   int stno, sex ;
   float grade ;
} list[SIZE] ;
int menu(void) ;
void init_list(void) , enter(void) ;
void display(void) , save(void) ;
void load(void) ;
int main()
{
  init_list();
  for(;;) {
      switch(menu()) {
  case 'e':  enter(); break;
  case 'd':  display(); break ;
  case 's' : save() ; break;
  case 'l' : load() ; break ;
  case 'q':  exit(0) ;
      }//end of switch
  } //end of for
}
//**********************
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("<< INPUT DATA >>");
    gotoxy(1, 3) ;
    printf("    name        stno      gread      sex(1, 2)" ) ;
    gotoxy(1,4) ;
    puts (" -------      -----     -------      -------") ;
    row = 5 ;
    for(;;)  {
     gotoxy(1, row);
     gets(list[i].name);
     if(! (*list[i].name))
 break ;
     gotoxy(16, row);
     gets(numstr) ;
     list[i].stno = atoi(numstr) ;
     gotoxy(28, row) ;
     gets(numstr) ;
     list[i].grade = atof(numstr) ;
     gotoxy(40, row) ;
     gets(numstr) ;
     list[i].sex = atoi(numstr) ;
     row ++ ;
     i ++ ;
    }
}
//***********************
void display(void)
   {
    register int t ;
    int row ;
    clrscr() ;
    gotoxy(10, 2) ;
    puts("<< OUTPUT DATA >> ") ;
    gotoxy(1, 3) ;
    printf("  name   stno      grade  sex(1,2)") ;
    gotoxy(1, 4);
    printf("-------  ----      -----  --------") ;
    row = 5 ;
    for(t = 0 ; t < SIZE ; t++)
       if(*list[t].name) {
      gotoxy(1, row) ;
      printf("%s", list[t].name);
      gotoxy(12, row) ;
      printf("%d", list[t].stno);
      gotoxy(20, row) ;
      printf("%5.2f", list[t].grade) ;
      gotoxy(30, row) ;
      printf("%d", list[t].sex) ;
      row ++ ;
      } //end of if
    gotoxy(5, row+2);
    printf(" press a key ...");
    getch() ;
}
//***********************
void save(void)
{
   FILE *fp ;
   register int i ;
   fp = fopen("st", "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("data saved.press a key.");
    getch() ;
  }
//************************
void load(void)
{
   FILE *fp ;
   register int i ;
   fp = fopen("st", "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("data loaded.press a key.");
 getch() ;
 return ;
     }//end of if
   }
}
//*****************
int menu(void)
{
    char s[10] ;
    clrscr();
    do {
 gotoxy(20, 4);
 printf("E) enter data ");
 gotoxy(20, 6);
 printf("D) display on screen");
 gotoxy(20, 8);
 printf("L) load file");
 gotoxy(20, 10);
 printf("S) save in file");
 gotoxy(20, 12);
 printf("Q) quit");
 gotoxy(20, 14);
 printf("enter your select:");
 gets(s) ;
    } while(!strchr("edlsq", tolower(*s)));
    return tolower(*s) ;
}

 

|+| نوشته شده توسط محمد رضا ابراهیمی در سه شنبه سی و یکم اردیبهشت 1387 و ساعت 22:57 | 
Powered By Blogfa - Designing & Supporting Tools By WebGozar