⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stud.cpp

📁 输入学生成绩 统计每门课的平均分 以及每个学生的总成绩和平均分
💻 CPP
字号:
#include <iostream.h>
#include <stdlib.h> 
#include <time.h> 
#include <math.h>


typedef struct student{
	//int num;
	//char name[20];
	float score[5];
	float total;
} stu;



int main(){
	stu stud[20];
	float aver[5],s[5];
	int i,j;
	float sum=0.0;
	
	
	//init(stud[20]);
	srand(time(NULL));
	for (i=0;i<20;i++){
		stud[i].total=0.0;
		for (j=0;j<5;j++){
			stud[i].score[j]=float(rand()%100);
			stud[i].total+=stud[i].score[j];
		} 
		cout<<"student"<<i+1<<"'s total score:"<<stud[i].total<<endl;
	} 



   //CompAver(stud[20]);
	for (i=0;i<5;i++){
		aver[i]=0.0;
		sum=0.0;
		for(j=0;j<20;j++){
			sum+=stud[j].score[i];
		} 
		aver[i]=sum/20;
		cout<<"the average score of course"<<i+1<<":"<<endl;
		cout<<aver[i]<<endl;
	} 

	
   //CompVariance(stud[20]);
	for (i=0;i<5;i++){
		s[i]=0.0;
		for(j=0;j<20;j++){
			s[i]+=(stud[j].score[i]-aver[i])*(stud[j].score[i]-aver[i]);
		} 
		cout<<"the variance of course"<<i+1<<":"<<endl;
		cout<<sqrt(s[i])<<"\n";
	}

	
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -