// 实验二.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 << "\n";
}
//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 << "\n";
}
int main()
{
// inOutPut1(stu);
inOutPut2();
}
first output:
second output: