zoukankan      html  css  js  c++  java
  • 输入学号,显示对应的姓名(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<<" "<<"年龄:"<<seq.elem[mm].stuage<<endl;
    return 1;
    }

    运行结果:

  • 相关阅读:
    Node.js Express 框架
    Node.js RESTful API
    vim中自动格式化代码
    如何去掉linux配置文件的注释行和空行
    ImmutableJS
    JavaScript的相关知识
    React容器组件和展示组件
    node.js
    svg学习
    Redux 基础概念
  • 原文地址:https://www.cnblogs.com/duanqibo/p/11110843.html
Copyright © 2011-2022 走看看