• C++实训(2.2)


    源程序:

    #include <iostream>
    #include <stdlib.h>
    const int MaxSize = 8;
    using namespace std;

    typedef struct
    {
    int stuno;
    string stuname;
    int stuage;
    }TableElem;

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

    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]; //给elem[]数组初始化
    }
    seq.n = MaxSize;
    int num, mm;
    printf("请输入要查找的学号:");
    cin >> num;

    mm = searchsqtable(seq,num);
    cout << "该学号的姓名为:" << seq.elem[mm].stuname << " " <<"年龄为:"<< seq.elem[mm].stuage << endl;

    return 1;
    }

    运行结果:

  • 相关阅读:
    Samba服务器配置
    Showdoc
    wkhtmltoimage(网页剪切功能)
    GTID数据库备份
    awstats日志分析
    docker桥接
    php的opcache缓存扩展(php页面代码刷新速度)
    Pureftp SSL/TLS配置
    ssh-keygen配置
    systemctl使用
  • 原文地址:https://www.cnblogs.com/duanqibo/p/13127135.html
Copyright © 2020-2023  润新知