Создание базы данных "Стадионы города" на языке C
Курсовой проект - Компьютеры, программирование
Другие курсовые по предмету Компьютеры, программирование
eturn;
}
void add () {
tm *T; time_t tt; tt=time (NULL); T=localtime (&tt);
Count++;
clrscr ();
printf ("\n\t\t\t\tADD RECORD\n");
printf ("Enter Name stadium (no more 15 symbols): ");
scanf ("%s",s [Count-1]. Name);
strupr (s [Count-1]. Name);
do {
printf ("Enter Date of construction: ");
scanf ("%d",&s [Count-1]. D_cr);
}while ( (s [Count-1]. D_crtm_year+1900)));
do {
printf ("Enter sapacity of stadium: ");
scanf ("%d",&s [Count-1]. Sapacity);
}while (s [Count-1]. Sapacity<1);
do {
printf ("Enter Amount platforms (no more 10): ");
scanf ("%d",&s [Count-1]. C_pl);
} while (s [Count-1]. C_pl10);
for (int i=0; i<s [Count-1]. C_pl; i++) {
printf ("Enter sport%d (no more 15 symbols): ", i+1);
scanf ("%s",s [Count-1]. N_sp [i]);
strupr (s [Count-1]. N_sp [i]);
}
alf ();
printf ("New record is added\n"); getch ();
return;
}
void remov () {
int num=0;
clrscr ();
printf ("\n\t\t\t\tREMOVE RECORD\n");
prin_all ();
while (numCount) {
printf ("Enter number record for edit: ");
scanf ("%d",&num);
}
printf ("You have chosen record: \n");
prin_head ();
prin (num-1);
printf ("Do you want remove record? (Y\\N) \n");
if ( (getch () ==y) || (getch () ==Y)) {
strcpy (s [num-1]. Name,\0);
s [num-1]. D_cr=0;
s [num-1]. Sapacity=0;
for (int i=0; i<s [num-1]. C_pl; i++)
strcpy (s [num-1]. N_sp [i],\0);
s [num-1]. C_pl=0;
alf ();
Count--;
printf ("Record is removed\n"); getch ();
}
return;
}
void edit () {
tm *T; time_t tt; tt=time (NULL); T=localtime (&tt);
stadiums temp;
int num=0, i;
clrscr ();
printf ("\t\t\tEDIT RECORD\n");
prin_all ();
while (numCount) {
printf ("Enter number record for edit: ");
scanf ("%d",&num);
}
clrscr ();
printf ("You have chosen record: \n");
prin_head ();
prin (num-1);
printf ("Enter new Name stadium (no more 15 symbols): ");
scanf ("%s",temp. Name);
strupr (temp. Name);
do {
printf ("Enter new Date of construction: ");
scanf ("%d",&temp. D_cr);
} while ( (temp. D_crtm_year+1900)));
do {
printf ("Enter new Sapacity of stadium: ");
scanf ("%d",&temp. Sapacity);
} while (temp. Sapacity<1);
do {
printf ("Enter new Amount platforms (no more 10): ");
scanf ("%d",&temp. C_pl);
} while (temp. C_pl10);
for (i=0; i<temp. C_pl; i++) {
printf ("Enter new sport%d (no more 15 symbols): ", i+1);
scanf ("%s",temp. N_sp [i]);
strupr (temp. N_sp [i]);
}
printf ("Do you want change record? (Y\\N) \n");
if ( (getch () ==y) || (getch () ==Y)) {
strcpy (s [num-1]. Name,temp. Name);
s [num-1]. D_cr=temp. D_cr;
s [num-1]. Sapacity=temp. Sapacity;
s [num-1]. C_pl=temp. C_pl;
for (i=0; i<temp. C_pl; i++)
strcpy (s [num-1]. N_sp [i],temp. N_sp [i]);
alf ();
printf ("Record is changed\n"); getch ();
}
return;
}
void prin_vmes () {int i, cap;
clrscr ();
printf ("\t\t\tSEAL ON CAPACITY\n");
printf ("Choose a kind: \n");
printf ("1. =\n");
printf ("2. >\n");
printf ("3. <\n");
printf ("4. >=\n");
printf ("5. <=\n");
switch (getch ()) {
case 1: printf ("Enter capacity (=): ");
scanf ("%d",&cap);
prin_head ();
for (i=0; i<Count; i++)
if (s [i]. Sapacity==cap) prin (i);
break;
case 2: printf ("Enter capacity (>): ");
scanf ("%d",&cap);
prin_head ();
for (i=0; i<Count; i++)
if (s [i]. Sapacity>cap) prin (i);
break;
case 3: printf ("Enter capacity (<): ");
scanf ("%d",&cap);
prin_head ();
for (i=0; i<Count; i++)
if (s [i]. Sapacity<cap) prin (i);
break;
case 4: printf ("Enter capacity (>=): ");
scanf ("%d",&cap);
prin_head ();
for (i=0; i<Count; i++)
if (s [i]. Sapacity>=cap) prin (i);
break;
case 5: printf ("Enter capacity (<=): ");
scanf ("%d",&cap);
prin_head ();
for (i=0; i<Count; i++)
if (s [i]. Sapacity<=cap) prin (i);
break;
}
getch ();
return;
}
void find () { char sport [15] ; int i,j;
clrscr ();
printf ("\t\t\tSEAL KIND OF SPORT\n");
printf ("Enter sport (no more 15 symbols): ");
scanf ("%s",sport);
prin_head ();
for (i=0; i<Count; i++)
for (j=0; j<s [i]. C_pl; j++)
if (strcmp (strupr (s [i]. N_sp [j]),strupr (sport)) ==0) prin (i);
getch ();
return;
}
int main ()
{
clrscr ();
FILE* f; char c;
Count=0;
if ( (f=fopen ("C: \\Student\\05IS\\db. kp","rb")) ==NULL) {
printf ("The file does not exist\n");
fclose (f);
printf ("You want continue? (Y\\N) \n");
c=getch ();
if ( (c==n) || (c==N)) return 1;
}
else {
fread (&s,sizeof (s),1,f);
for (int i=0; s [i]. D_cr! =0; i++) Count=i+1;
alf ();
}
fclose (f);
while (1) {
clrscr ();
printf ("---------------------------------\n");
printf ("| Academic year project |\n");
printf ("| on Computer science |\n");
printf ("| - -----------------------------|\n");
printf ("| To create a database |\n");
printf ("| \"Stadiums of city\" |\n");
printf ("| Variant #8 |\n");
printf ("| Okunev Stanislav has executed |\n");
printf ("---------------------------------\n");
printf ("Menu: \n");
printf ("1. Add record\n");
printf ("2. Remove record\n");
printf ("3. Edit record\n");
printf ("4. Show all stadiums\n");
printf ("5. Show stadiums on capacity\n");
printf ("6. Search of stadiums by kinds of sports\n");
printf ("7. Exit\n");
printf ("Press key: ");
c=getch ();
switch (c) {
case 1: add (); break;
case 2: remov (); break;
case 3: edit (); break;
case 4: prin_all (); getch (); break;
case 5: prin_vmes (); break;
case 6: find (); break;
case 7: printf ("\nYou really want to leave? (Y\\N) \n");
c=getch ();
if ( (c==y) || (c==Y)) {save (); return 1; }
}
}
return 0;
}
Приложение 3
Результаты выполнения программы:
Главное меню:
Добавление записи:
Вывести на экран список всех стадионов:
Вывести на экран стадионы по вместимости:
Вывести на экран стадионы по указанному виду спорта: