enter your score and get average score...

本文介绍了一个使用C++编写的简单程序,该程序能够接收用户输入的成绩并计算平均分数。程序通过循环读取成绩,检查输入的有效性,并利用函数进行模块化设计。
#include<iostream>
using namespace std;

const int ARSIZE = 10;

void show_mark(float s)
{
    cout << "Your average score is: "<< s << endl;
}

float avg(float arg[], int n)
{
    float sum = 0;
    for (int i = 0; i < n; i++)
        sum += arg[i];
    return sum/n;
}

int main()
{
    float mark[ARSIZE];
    float score;
    float total = 0;
    for (int i = 0; i < ARSIZE; i++)
    {
        cout <<"Please enter #" << i + 1 << " mark: "<< endl;
        cin >> score;
        if(!cin)
        {
            cin.clear();
            if(cin.get() != '\n')
                continue;
            cout << "Bad input! Please enter your mark correctly." << endl;
            break;
        }
        else if(mark[i] < 0)
            break;
        mark[i] = score;
    }

    total = avg(mark, ARSIZE);
    show_mark(total);
    return 0;
}
View Code

只是自己练个熟练度,大神们不要点开,免得瞎眼睛。。。

转载于:https://www.cnblogs.com/TadGuo/p/7856651.html

c++。学生成绩管理系统V4.0 某班有最多不超过30人(具体人数由键盘输入)参加期末考试,考试科目最多不超过6门(具体门数有键盘输入)。参考例8.12,用二维数组作函数参数编程实现如下菜单驱动的学生成绩管理系统: (1)录入每个学生的学号、姓名和考试成绩; (2)计算每门课程的总分和平均分; (3)计算每个学生的总分和平均分; (4)按每个学生的总分由高到低排出名次表; (5)按每个学生的总分由低到高排出名次表; (6)按学号由小到大排出成绩表; (7)按姓名的字典顺序排出成绩表; (8)按学号查询学生排名及其各科考试成绩; (9)按姓名查询学生排名及其各科考试成绩; (10)按优秀(90~100)、良好(80~89)、中等(70~79)、及格(60~69)、不及格(0~59)5个类别,统计每个类别的人数以及所占的百分比; (11)输出每个学生的学号、姓名、各科考试成绩、总分和平均分,以及每门课程的总分和平均分。 要求程序运行后先显示如下菜单,并提示用户输入选项: 1.Input record 2.Caculate total and average score of every course 3. Caculate total and average score of every student 4.Sort in descending order by total score of every student 5.Sort in ascending order by total score of every student 6.Sort in ascending order by number 7.Sort in dictionary by name 8.Search by number 9.Search by name 10.Statistic analysis for every course 11.List record 0.Exit Please enter your choice:
06-26
在3.0基础上继续写c++代码实现下面的要求。学生成绩管理系统V4.0 某班有最多不超过30人(具体人数由键盘输入)参加期末考试,考试科目最多不超过6门(具体门数有键盘输入)。参考例8.12,用二维数组作函数参数编程实现如下菜单驱动的学生成绩管理系统: (1)录入每个学生的学号、姓名和考试成绩; (2)计算每门课程的总分和平均分; (3)计算每个学生的总分和平均分; (4)按每个学生的总分由高到低排出名次表; (5)按每个学生的总分由低到高排出名次表; (6)按学号由小到大排出成绩表; (7)按姓名的字典顺序排出成绩表; (8)按学号查询学生排名及其各科考试成绩; (9)按姓名查询学生排名及其各科考试成绩; (10)按优秀(90~100)、良好(80~89)、中等(70~79)、及格(60~69)、不及格(0~59)5个类别,统计每个类别的人数以及所占的百分比; (11)输出每个学生的学号、姓名、各科考试成绩、总分和平均分,以及每门课程的总分和平均分。 要求程序运行后先显示如下菜单,并提示用户输入选项: 1.Input record 2.Caculate total and average score of every course 3. Caculate total and average score of every student 4.Sort in descending order by total score of every student 5.Sort in ascending order by total score of every student 6.Sort in ascending order by number 7.Sort in dictionary by name 8.Search by number 9.Search by name 10.Statistic analysis for every course 11.List record 0.Exit Please enter your choice:
06-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值