打卡第三十二天
学生CPP成绩计算
一、
1.定义people类,建立数据成员年龄 姓名 构造输出函数
2.定义派生类 学生类 增加数据成员 学号 成绩
3.构造输出函数 输出学生类的信息
二、
三、
#include<string>
#include<iomanip>
#include <iostream>
using namespace std;
class Person {
protected:
string name;
int age;
public:
Person(){
};
Person (string p_name, int p_age){
name=p_name;
age=p_age;
};
void display () {cout<<name<<":"<<age<<endl;}
};
class Student:public Person{
int ID;
float cpp_score;
float cpp_count;
float cpp_grade;
public :
Student(){}
Student(string Name,int id,float a,float b){
name=Name;
ID=id;
cpp_score=a;
cpp_count=b; }
void print(){
cpp_grade=cpp_grade = cpp_score * 0.9 + cpp_count * 2;
cout<<ID<<" "<<name<<" "<<setiosflags(ios::fixed)<<setprecision(1)<<cpp_grade<<endl;
}
};
int main()
{ int ID;
string name;int age;
float cpp_score;
float cpp_count;
cin >> name ;
while(name!="0"){
cin >> ID >>age>> cpp_score >>cpp_count;
Student a(name,ID,cpp_score,cpp_count);
a.print();
cin >> name ;
}
return 0;
}
四、
#include<string>
#include<iomanip>
#include <iostream>
using namespace std;
class Person {
protected:
string name;
int age;
public:
Person(){
};
Person (string p_name, int p_age){
name=p_name;
age=p_age;
};
void display () {cout<<name<<":"<<age<<endl;}
};
class Student:public Person{
int ID;
float cpp_score;
float cpp_count;
float cpp_grade;
public :
Student(){}
Student(string Name,int id,float a,float b){
name=Name;
ID=id;
cpp_score=a;
cpp_count=b; }
void print(){
cpp_grade=cpp_grade = cpp_score * 0.9 + cpp_count * 2;
cout<<ID<<" "<<name<<" "<<setiosflags(ios::fixed)<<setprecision(1)<<cpp_grade<<endl;
}
};
int main()
{ int ID;
string name;int age;
float cpp_score;
float cpp_count;
cin >> name ;
while(name!="0"){
cin >> ID >>age>> cpp_score >>cpp_count;
Student a(name,ID,cpp_score,cpp_count);
a.print();
cin >> name ;
}
return 0;
}