zoukankan      html  css  js  c++  java
  • 数据结构:实验二

    // 实验二.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:
    这里写图片描述

  • 相关阅读:
    python内置函数枚举 enumerate()
    python内置函数map的介绍
    什么是lambda函数
    python urllib库 加密及解析url中中文汉字
    python解决高并发思路
    后端文件保存的两种方式
    matplotlib基本用法
    自编码器
    数据增强
    卷积神经网络
  • 原文地址:https://www.cnblogs.com/cnsec/p/13286840.html
Copyright © 2011-2022 走看看