第二周上机任务项目3-用结构体数组做计算

博客内容涉及使用结构体数组进行一系列计算,展示了如何在编程中操作结构体数组以完成特定任务,通过实例呈现了运行结果。
摘要由CSDN通过智能技术生成
01./*       
02.* 程序的版权和版本声明部分       
03.* Copyright (c)2013, 烟台大学计算机学院学生       
04.* All rightsreserved.       
05.* 文件名称:read .cpp                                  
06.* 作    者:赵冠哲                                   
07.* 完成日期:2013年03月09日       
08.* 版本号: v1.0             
09.* 输入描述:       
10.* 问题描述:     
11.*/   
#include<fstream>
#include<iostream>
using namespace std;
struct Student
{
	char num[13]; 
	char name[14];
	int cpp;
	int math;
	int english;
	int total;
}student[300];
void reward(Student [],int );
void sort(Student [],int );
void output(Student [],int );
int main()
{    
	int i,stuNum=0;
	
	ifstream infile("score.txt",ios::in);
	if(!infile)
	{
		cerr<<"open error!"<<endl;
		exit(1);
	}
	while(!infile.eof())
	{
		infile>>student[stuNum].num>>student[stuNum].name>>student[stuNum].cpp>>student[stuNum].math>>student[stuNum].english;
		++stuNum;
	}
	infile.close();
	for(i=0;i<stuNum;i++)
	{
		student[i].total=student[i].cpp+student[i].math+student[i].english;
	}
	cout<<"获得奖学金学生的名单:"<<endl;
	reward(student,stuNum);
	cout<<endl;
	cout<<"按照总分排序为:"<<endl;
	sort(student,stuNum);
	output(student,stuNum);
	return 0;
}
void sort(Student [],int stuNum)
{
	int i,j;
	Student t;
	for(j=1;j<stuNum;j++)
		for(i=0;i<=stuNum-j-1;i++)
            if(student[i].total<student[i+1].total)
			{
				t=student[i];
			student[i]=student[i+1];
				student[i+1]=t;

		}	
			return;
}
void reward(Student [],int stuNum)
{
int i,j;
sort(student,stuNum);
for(i=0;i<stuNum;i++)
{
	if(student[i].cpp>=60&&student[i].math>=60&&student[i].english>=60)
		j++;
}
for(j=0;j<=30;j++)
{
cout<<student[j].name<<"     ";
}
return;
}


void output(Student [],int stuNum)
{
	for(int i=0;i<stuNum;i++)
	{
		cout<<student[i].num<<"   "
			<<student[i].name<<"   "
			<<student[i].cpp<<"    "
			<<student[i].math<<"    "
			<<student[i].english<<"   "
			<<student[i].total<<endl;
	}
	return;
}


运行结果:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值