1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#include <iostream>
#include<stdio.h>
#include<string.h>
#define MAX 100
using namespace std;
struct student
{
char name[25];
char surname[25];
int num;
int year;
float avg;
};
void search (struct student* array, int number)
{
int type, i, num, year, found=0;
char search[25];
printf("Write 1 to search by name/surname, write 2 to search by number, write 3 to search by year:");
scanf("%d",type);
if(type==1)
{
printf("Write name/ surname:");
scanf("%s",search);
for(i=0;i<number;i++)
{
int r;
r = strcmp(search, array[i].name);
int p;
p = strcmp(search, array[i].surname);
if((r==0) ||(p==0))
{
printf("%d. %s %s Num:%d Year:%d Avg:%f ",i+1,array[i].name, array[i].surname, array[i].num,array[i].year, array[i].avg);
found=1;
}
}
if(found==0)
printf("No result.\n");
}
else if (type==2)
{
printf("Write number: ");
scanf("%d",&num);
for(i=0;i<number;i++)
{
if(num==array[i].num)
{
printf("%d. %s %s Num:%d Year:%d Avg:%f", (i+1),&array[i].name, &array[i].surname, array[i].num,array[i].year, array[i].avg);
found=1;
}
}
if(found==0)
printf("No result.\n");
}
else if(type==3)
{
printf("Write year:\n");
scanf("%d",&year);
for(i=0;i<number;i++)
{
if(year==array[i].year)
{
printf("%d. %s %s Num:%d Year:%d Avg:%f",(i+1),&array[i].name, &array[i].surname, array[i].num,array[i].year, array[i].avg);
found=1;
}
}
if(found==0)
printf("No result.\n");
}
}
|