Enter the student number, to display the corresponding name (c ++)

#include <stdio.h>
#include <stdlib.h>
#include <iostream>

using namespace std;
const int MaxSize=8;

typedef struct
{
int stuno;
char stuname[20];
int stuage;
}TableElem;

TableElem stu[]={{1001,"zhangsan",20},{1002,"wangwu",18},{1003,"lisi",19},{1004,"zhaofeng",20},
{1005,"ligang",19},{1006,"wangjun",21},{1007,"chenguang",18},{1008,"zhangli",20}};

struct typedef
{
TableElem elem [the MaxSize];
int n-;
} Sqtable; // array Students

int searchsqtable(Sqtable T,int key)
{
T.elem[0].stuno=key; //岗哨
int i=T.n;
while(T.elem[i].stuno!=key)
i--;
return i;
}

main int ()
{
Sqtable SEQ;
for (int I = 0; I <the MaxSize; I ++)
{
seq.elem [I] = STU [I];
}
seq.n = the MaxSize;
int KK, mm;
the printf ( "Please I want to find school number: ");
cin >> kk;

mm=searchsqtable(seq,kk);
//cout<<mm<<endl;
cout<<"该序号的姓名是:"<<seq.elem[mm].stuname<<"\t"<<"年龄:"<<seq.elem[mm].stuage<<endl;
return 1;
}

operation result:

 

Guess you like

Origin www.cnblogs.com/duanqibo/p/11110843.html