无语了。。。 2021-06-24 12:38 采纳率: 100%
浏览 35
已结题

求解(指针没学明白)

 

  • 写回答

4条回答 默认 最新

  • CSDN专家-cpp_learner 2021-06-24 13:47
    关注

     

    如果解决你的问题,请点个采纳!

    #include <iostream>
    
    using namespace std;
    
    #define STU_SIZE	5
    
    
    struct Student {
    	int num;
    	char name[10];
    	float score[3];
    };
    
    
    void avr_max(Student *stu);
    void print(Student *stu);
    
    
    int main() {
    	Student stu[STU_SIZE];
    
    	for (int i = 0; i < STU_SIZE; i++) {
    		cout << "请输入第" << i + 1 << "名学生的号码:" << endl;
    		cin >> stu[i].num;
    
    		cout << "请输入第" << i + 1 << "名学生的名字:" << endl;
    		cin >> stu[i].name;
    
    		cout << "请输入第" << i + 1 << "名学生的三科分数:" << endl;
    		for (int k = 0; k < 3; k++) {
    			cin >> stu[i].score[k];
    		}
    	}
    
    
    	avr_max(stu);
    	print(stu);
    
    	return 0;
    }
    
    
    void avr_max(Student *stu) {
    	double avg[STU_SIZE] = { 0 };
    
    	// 计算平均分,并保存再avg数组中
    	for (int i = 0; i < STU_SIZE; i++) {
    		avg[i] = 0.0;
    		for (int j = 0; j < 3; j++) {
    			avg[i] += stu[i].score[j];
    		}
    
    		avg[i] /= 3;	// 计算平均分
    
    	}
    
    	int index = 0;
    	double max = avg[0];
    	for (int k = 1; k < STU_SIZE; k++) {
    		if (max < avg[k]) {
    			max = avg[k];
    			index = k;
    		}
    	}
    
    	cout << STU_SIZE << "名学生平均分最高的是:" << endl;
    	cout << "编号:" << stu[index].num << "\t" << "姓名:" << stu[index].name << "\t" << "平均分成绩:" << avg[index] << endl;
    }
    
    void print(Student *stu) {
    
    	cout << endl <<  STU_SIZE << "名学生的信息:" << endl;
    	
    	for (int i = 0; i < STU_SIZE;  i++) {
    		cout << "编号:" << stu[i].num << "\t" << "姓名:" << stu[i].name << "\t";
    		
    		for (int j = 0; j < 3; j++) {
    			cout << "第" << j + 1 << "科成绩:" << stu[i].score[j] << "\t";
    		}
    
    		cout << endl;
    	}
    }

     

     

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 7月13日

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应