<C>.班级成绩输入输出

描述

输入一个班级5个学生各5科成绩,输出5个学生各5科成绩及总分。

输入描述:

五行,每行输入一个学生各5科成绩(浮点数表示,范围0.0~100.0),用空格分隔。

输出描述:

五行,按照输入顺序每行输出一个学生的5科成绩及总分(小数点保留1位),用空格分隔

示例1

输入:

98.5 96.0 100 99 88
60.5 77 88.5 99 60
80 80.5 89 91 92
93 94 95.5 96 97.5
100 98 88.5 88 78.5

复制输出:

98.5 96.0 100.0 99.0 88.0 481.5
60.5 77.0 88.5 99.0 60.0 385.0
80.0 80.5 89.0 91.0 92.0 432.5
93.0 94.0 95.5 96.0 97.5 476.0
100.0 98.0 88.5 88.0 78.5 453.0

解答:
 

#include<stdio.h>
int main()
{
    float arr[5]={0};
    int j=0;
    int i=0;
    for(i=0;i<5;i++)
    {
        float sum=0;
    for(j=0;j<5;j++)
    {
        scanf("%f",&arr[j]);
        sum=sum+arr[j];
    }
    for(j=0;j<5;j++)
    {
        printf("%.1f ",arr[j]);
    }
    printf("%.1f\n",sum);
    }
    return 0;
}

 

 

帮我改对#include<iostream> #include<fstream> #include<string> #include<vector> #include <algorithm> using namespace std; enum Grade { E=0,D,C,B,A }; class Student { public: int number; string name; double score; }; ostream& operator<<(ostream& out, Student& p) { return out; } bool compare(const Student& a, const Student& b) { return a.number < b.number; } void printVector(vector<Student>&students) { for (vector<Student>::iterator it = students.begin(); it != students.end(); it++) { cout << *it << " "; } cout << endl; } void test01() { vector<Student>students; printVector(students); } int main() { // 学生信息导入 ifstream infile; infile.open("student.txt",ios::in); if (!infile.is_open()) { cout << "文件打开失败" << endl; } vector<Student> students(27); char buf[] = { 0 }; while (infile>>buf) { cout << buf << endl; } infile.close(); // 成绩查询 int choice = 0; while (choice != 4) { cout << "请输入您要进行的操作:\n"; cout << "1. 按学号查询\n"; cout << "2. 按姓名查询\n"; cout << "3. 统计班级成绩\n"; cout << "4. 退出程序\n"; cin >> choice; if (choice == 1) { int number; cout << "请输入学号:\n"; cin >> number; auto it = find_if(students.begin(), students.end(), [number](const Student& s) { return s.number == number; }); if (it != students.end()) { cout << "学号\t姓名\t成绩\n"; cout << it->number << "\t" << it->name << "\t" << it->score << "\n"; } else { cout << "查无此人!\n"; } } else if (choice == 2) { string name; cout << "请输入姓名:\n"; cin >> name; auto it = find_if(students.begin(), students.end(), [name](const Student& s) { return s.name == name; }); if (it != students.end()) {
05-30
优化以下代码,要求:班级成绩管理系统 (1)利用结构体和简单的链表,实现一个班学生成绩的管理,至少可以输入20个学生成绩。 (2)成绩管理功能包括:输入、输出,利用new和delete运算符添加和删除班级成绩 (1)利用结构体和简单的链表(关于链表的知识,自己查阅资料学习),实现一个班学生成绩的管理。#include<stdio.h> #include<iostream> #include<windows.h> using namespace std; typedef struct student { char name[20]; int score; student* next; }stu; stu* head; void input() { stu* p1, * p2; p1 = (stu*)new stu; head = p1; while (p1 != NULL) { cout << "输入姓名" << endl; cin >> p1->name; cout << "输入成绩" << endl; cin >> p1->score; cout << "是否继续输入?(1.是 2.否)"; int a; cin >> a; if (a == 1) { p2 = p1; p1 = (stu*)new stu; p2->next = p1; continue; } else if (a == 2) { p1->next = NULL; break; } } } void listprint() { stu* p1 = head; while (p1 != NULL) { cout << 1; cout << "姓名: " << p1->name << " 成绩:" << p1->score << endl; p1 = p1->next; } } void shanchu() { char c[20]; cout << "请输入删除的学生姓名" << endl; cin >> c; stu* p1 = head, * p2; while (p1 != NULL) { p2 = p1->next; if (strcmp(p2->name, c) == 0) { p1->next = p2->next; break; }p1 = p1->next; } } int main() { int a = 0; while (1) { cout << "1.输入成绩 2.输出成绩 3.删除" << endl;cin >> a; switch (a) { case 1: { input(); system ("cls"); continue; } case 2: { listprint(); continue; } case 3: { shanchu(); continue; } default: { break; } } break; } }
03-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值