首页 > 其他分享 >打卡12

打卡12

时间:2023-05-09 11:22:15浏览次数:38  
标签:count 12 name int float Student cpp 打卡

#include <bits/stdc++.h>
using namespace std;
ostream &sp(ostream &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 &stu1); //在学生数组中增加一个学生记录
void average(); //计算当前班级cpp平均成绩cpp_average
void print(); //输出当前班级学生的信息
};

void Teacher::Add(Student &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 &sp(ostream &output)
{
return output << " ";
}

标签:count,12,name,int,float,Student,cpp,打卡
From: https://www.cnblogs.com/bdsz/p/17384357.html

相关文章

  • 打卡 数据的最大值问题(重载+函数模板)
    两个类如下设计:类Time有三个数据成员,hh,mm,ss,分别代表时,分和秒,并有若干构造函数和一个重载-(减号)的成员函数。类Date有三个数据成员,year,month,day分别代表年月日,并有若干构造函数和一个重载>(<)(大于号或者小于号)的成员函数。要求设计一个函数模板template<classT>doublemaxn(Tx[]......
  • 每天打卡一小时 第二十二天
    【CPP0029】以圆类Circle及立体图形类Solid为基础设计圆锥类Cone分数 10全屏浏览题目切换布局作者 C++多态编程单位 石家庄铁道大学以点类Point及平面图形类Plane为基类公有派生圆类Circle,再以圆类Circle及立体图形类Solid为基类公有派生圆锥类Co......
  • flink Connecting to remote task manager 'localhost/127.0.0.1:44489
    问题:启动集群后,执行任务时失败:Causedby:org.apache.flink.runtime.io.network.partition.consumer.PartitionConnectionException:Connectionforpartition47d4a412246bdbbc3447e1968e07c821#1@04049d45261135a1a8bae9c8f62a1ba4_0a448493b4782967b150582570326227_1_0not......
  • 5.8打卡
     二、设计思路 三、代码实现#include<bits/stdc++.h>usingnamespacestd;intmain(){inti;doublemoney=0.0;for(i=0;i<5;i++)money=(money+1000.0)/(1+0.0063*12);printf("Ó¦´æÈëµÄÇ®ÊýΪ£º%0.2f\n",money);} ......
  • 5月8日打卡
    例4-8题目描述:使用联合体保存成绩信息,并且输出代码部分:#include<string>#include<iostream>usingnamespacestd;classExamInfo{private:stringname;enum{GRADE,PASS,PERCENTAGE}mode;union{chargrade;......
  • 打卡1
    问题描述:编写一个计算机个人所得税的程序,要求输入收入金额后,能够输出个人所得税,征收如下:起始点为3500元,征收3%1500~4500元,征收10%4500~9000元,征收20%9000~35000元,征收25%35000~55000元,征收30%55000~80000元,征收35%超出80000元,征收45%流程图:  伪代码:start[6]={0,150......
  • 编程打卡: C++ 语言程序设计
    编程打卡:C++语言程序设计#include<iostream>#include<array>usingnamespacestd;intmain(){intn;cin>>n;array<double,100000>scores;for(inti=0;i<n;i++){cin>>scores[i];}......
  • 1263. 推箱子
    题目链接:1263.推箱子方法:双端队列+BFS解题思路[Python3/Java/C++/Go/TypeScript]一题一解:双端队列BFS(清晰题解)代码classSolution{public:intminPushBox(vector<vector<char>>&grid){intm=grid.size(),n=grid[0].size();intsi,sj,......
  • 第十四天打卡
    一、问题描述一个口袋中放有12个球,已知其中3个是红色,3个是白色,6个是黑色,先从中任取8个,问共有多少种可能的颜色搭配?二、设计思路1.设m,n分别记录取出红的和白的,用8-m-n表示黑的;2.利用二重循环依次求出满足条件的m,n;3.在设计if条件满足8-m-n<=6,然后输出结果。三、程序流......
  • 2023.5.8编程一小时打卡
    一、问题描述:初始化int类型数组date1[]={1,3,5,7,9,11,13,15,17,19,2,4,6,8,10,12,14,16,18,20},应用本章的直接插入排序模板进行排序,对此函数模板稍作修改,加入输出语句,在每一个待排序元素后显示整个数组,观察排序过程中数据的变化,加深对插入排序算法的理解。二、解题思路:首先,定......