• 数据结构:实验二


    // 实验二.cpp ://
    /*
    1.定义student结构体,包含姓名、学号、C成绩、VB成绩、数学成绩和英语成绩,并计算平均成绩,
    通过调用函数输出平局成绩。
    2.函数完成二维数组的最小值查找,并在主函数中输出(用指针实现)。
    */
    #include "stdafx.h"
    #include "string"
    #include "iostream"
    using namespace std;
    //score struct
    struct score
    {
        int c;
        int vb;
        int math;
        int music;
    };
    //student struct
    struct student
    {
        string name;
        int num;
        struct score score;
        float aver;
    }stu;
    //Input and Output Function(First question )
    void inOutPut1(struct student stu)
    {
        cout << "Input Name:";
        cin >> stu.name;
        cout << "Input Number:";
        cin >> stu.num;
        cout << "Input C score:";
        cin >> stu.score.c;
        cout << "Input VB score:";
        cin >> stu.score.vb;
        cout << "Input Math score:";
        cin >> stu.score.math;
        cout << "Input Music score:";
        cin >> stu.score.music;
        float anvagerScore = (stu.score.c + stu.score.vb + stu.score.math + stu.score.music)/4.0;
        cout << "anvagerScore:";
        cout << anvagerScore;
        cout << "
    ";
    }
    //Find Min Value(Second question)
    int min(int (*p)[2])
    {
        int min = (*p)[0];
        for (int i = 0; i < 2; i++)
            for (int j = 0; j < 2; j++)
                if ((*(p + i))[j] < min)
                    min = (*(p + i))[j];
        return min;
    }
    //Input and Output Function(Second question )
    void inOutPut2()
    {
        int(*p)[2];//two-dimensional array point,equivalent to int [][2]
        int arr[2][2];//two-dimensional array
        for (int i = 0; i < 2; i++)
            for (int j = 0; j < 2; j++)
                cin >> arr[i][j];//input elements
        p = arr;//point to the arr's first(arr[0][0]) element address
        cout << "min=";
        cout << min(&p[0]);//output min vaule
        cout << "
    ";
    }
    int main()
    {
        // inOutPut1(stu);
        inOutPut2();
    
    }
    
    
    
    

    first output:
    这里写图片描述
    second output:
    这里写图片描述

  • 相关阅读:
    pyqt笔记1模块 信号和插槽
    pyqt5 eric6 pyqt5-tools
    转入Python3.5
    ARM伪指令
    ARM MOV PC加8
    所有JTAG集成电路都应该支持菊花链
    冯诺依曼存储子系统的改进
    [分享]Active-HDL 9.2 安装
    运行python脚本后台执行
    scala实验 模拟图形绘制
  • 原文地址:https://www.cnblogs.com/cnsec/p/13286840.html
Copyright © 2020-2023  润新知