打卡13

#include <bits/stdc++.h>
using namespace std;
ostream &amp;sp(ostream &amp;output);
class Person
{
protected:
    string name;
    int age;

public:
    Person() {}
    ~Person() {}
    Person(string p_name, int p_age) : name(p_name), age(p_age) {}
    void display() { cout << name << ":" << age << endl; }
};

class Student : public Person
{
public:
    int ID;              //学号
    float cpp_score;     //cpp上机成绩
    float cpp_count;     //cpp上机考勤
    float cpp_grade = 0; //cpp总评成绩
                         //总评成绩计算规则:cpp_grade = cpp_score * 0.9 + cpp_count * 2;
public:
    Student() {}
    ~Student() {}
    Student(string p1, int p2, int a, float b, float c) : Person(p1, p2), ID(a), cpp_score(b), cpp_count(c) {}

    void print();
    float count();
};

float Student::count()
{
    return cpp_score * 0.9 + cpp_count * 2;
}

void Student::print()
{
    cpp_score = count();
    cout << fixed << setprecision(1) << ID << sp << name << sp << cpp_score << endl;
}

class Teacher : public Person
{
private:
    int ID;                //教师工号
    Student stu[100];      //学生数组
    int count = 0;         //学生数目,最多不超过100
    float cpp_average = 0; //班级cpp平均分
public:
    Teacher() {}
    ~Teacher() {}
    Teacher(string a, int b, int c) : Person(a, c), ID(b) {}
    void Add(Student &amp;stu1); //在学生数组中增加一个学生记录
    void average();          //计算当前班级cpp平均成绩cpp_average
    void print();            //输出当前班级学生的信息
};

void Teacher::Add(Student &amp;stu1)
{
    stu[count++] = stu1;
}

void Teacher::average()
{
    for(int i = 0; i < count;++i)
    {
        stu[i].cpp_grade = stu[i].count();
        cpp_average += stu[i].cpp_grade;
    }
    cpp_average /= count;
}

void Teacher::print()
{
    average();
    cout <<fixed<<setprecision(1)<< ID<<sp<<name<<sp<<count<<sp<<cpp_average<<endl;
    for(int i =0; i < count;++i)
    {
        stu[i].print();
    }
}
int main()
{
    int id, age;
    string name;
    float cpp_score = 0, cpp_count = 0, cpp_grade = 0;
    cin >> name >> id >> age;
    Teacher ans(name, id, age);
    Student ans2;
    while (1)
    {
        cin >> name;
        if (name == "0")
            break;
        cin >> id >> age >> cpp_score >> cpp_count;
        ans2 = Student(name,age,id,cpp_score,cpp_count);
        ans.Add(ans2);
    }
    ans.print();
}
ostream &amp;sp(ostream &amp;output)
{
    return output << " ";
}
posted @ 2023-05-09 11:21  vvvcutee  阅读(28)  评论(0)    收藏  举报