student.h
资源名称:c.rar [点击查看]
上传用户:puke2000
上传日期:2022-07-25
资源大小:912k
文件大小:1k
源码类别:
C#编程
开发平台:
Visual C++
- //=====================================
- // student.h
- //=====================================
- #ifndef HEADER_STUDENT
- #define HEADER_STUDENT
- //-------------------------------------
- #include<iostream>
- using namespace std;
- //-------------------------------------
- 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; }
- };//-----------------------------------
- #endif // HEADER_STUDENT