《C++使用批量数据计算学生成绩》

本文介绍了一个C++程序,用于根据期末、期中考试和家庭作业成绩计算学生的最终成绩。程序利用<ios>和<iomanip>库,通过setprecision控制输出精度,持续读取文件直到文件结束标志,采用double类型确保计算精度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

设想有一个课程,学生的期末考试成绩占最终成绩的40%,期中考试成绩占20%,家庭作业的平均成绩占40%,下面这个程序便可以帮助学生计算他们的最终成绩:

#include<iostream>
#include<ios>
#include<iomanip>
#include<string>
using namespace std;
int main()
{
	//ask for and read the student's nname
	cout << "Please enter your first name:";
	string name;
	cin >> name;
	cout << "Hello," << name << "!" << endl;

	//ask for and read the midterm and final grades
	cout << "Please enter your midterm and final grades:";
	double midterm, final;
	cin >> midterm >> final;

	//ask for the homework grades
	cout << "Enter all your homework grades,"
		"followed by end-of-file:";

	//the number and sum of grades read so far
	int count = 0;
	double sum = 0;

	//a variable into which to read 
	double x;

	//invariant:
	//we have read count grades so far, and
	//sum is the sum of the first count grades
	while (cin >> x) {
		++count;
		sum += x;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值