输入学号,显示对应的姓名(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}};

typedef struct
{
TableElem elem[MaxSize];
int n;
}Sqtable; //学生的数组

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

int main()
{
Sqtable seq;
for(int i=0;i<MaxSize;i++)
{
seq.elem[i]=stu[i];
}
seq.n=MaxSize;
int kk,mm;
printf("请输入要查找的学号:");
cin>>kk;

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

运行结果:

输入学号,显示对应的姓名(c++)

 

原文链接: https://www.cnblogs.com/duanqibo/p/11110843.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    输入学号,显示对应的姓名(c++)

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/298033

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月15日 下午7:12
下一篇 2023年2月15日 下午7:13

相关推荐