f1001.cpp
资源名称:c.rar [点击查看]
上传用户:puke2000
上传日期:2022-07-25
资源大小:912k
文件大小:1k
源码类别:
C#编程
开发平台:
Visual C++
- //=====================================
- // f1001.cpp
- // 继承
- //=====================================
- #include<iostream>
- using namespace std;
- //-------------------------------------
- class Advisor{
- int noOfMeeting;
- };//-----------------------------------
- class Student{
- string name;
- int semesterHours;
- double average;
- public:
- Student(string pName="noName"):name(pName),average(0),semesterHours(0){}
- void addCourse(int hours, double grade){
- double totalGrade = (semesterHours * average + grade); //总分
- semesterHours += hours; //总修学时
- average = semesterHours ? totalGrade/semesterHours : 0; //平均分
- }
- void display(){
- cout<<"name=""<<name<<"""<<", hours="<<semesterHours
- <<", average="<<average<<"n";
- }
- int getHours(){ return semesterHours; }
- double getAverage(){ return average; }
- };//-----------------------------------
- class GraduateStudent : public Student{
- Advisor advisor;
- int qualifierGrade;
- public:
- int getQualifier(){ return qualifierGrade; }
- };//-----------------------------------
- int main(){
- Student ds("Lo lee undergrade");
- GraduateStudent gs;
- ds.addCourse (3, 2.5);
- ds.display();
- gs.addCourse(3, 3.0);
- gs.display();
- }//====================================