设计一个绩点计算的程序
时间: 2023-04-04 20:02:26 浏览: 207
好的,我可以回答这个问题。绩点计算程序可以根据学生的成绩和学分来计算绩点。具体实现可以先输入学生的课程成绩和学分,然后根据学校的绩点计算规则,计算每门课程的绩点,最后将所有课程的绩点加权平均即可得到学生的绩点。需要注意的是,不同学校的绩点计算规则可能有所不同,需要根据具体情况进行调整。
相关问题
1)设计一个基类Course,包含private数据成员课程ID、学分credit;public函数get_credit用于读取credit的值,两个纯虚函数:总分计算totalS,课程绩点计算GPA (2)编写三个子类:高数AdvanceMathematic、英语English、C语言Cprogram公有继承基类Course。每个类都两个私有属性考试分数exam,平时分数dailywork。 (3)每门课程绩点的计算方法为:GPA=总分/10.0-5;平均绩点计算方法为: 平均绩点=Σ(学分*GPA)/Σ学分 (4)设计一个main函数,要求使用基类指针,并实现每门课程总分及平均绩点的计算并输出。
下面是使用 C++ 编写的代码实现:
```cpp
#include <iostream>
#include <string>
using namespace std;
// 基类 Course
class Course {
private:
string id; // 课程 ID
float credit; // 学分
public:
Course(string _id, float _credit): id(_id), credit(_credit) {}
float get_credit() { return credit; } // 读取学分
virtual float totalS() = 0; // 纯虚函数,计算总分
virtual float GPA() = 0; // 纯虚函数,计算课程绩点
};
// 子类 AdvanceMathematic
class AdvanceMathematic : public Course {
private:
float exam; // 考试分数
float dailywork; // 平时分数
public:
AdvanceMathematic(string _id, float _credit, float _exam, float _dailywork)
: Course(_id, _credit), exam(_exam), dailywork(_dailywork) {}
float totalS() { return exam + dailywork; } // 计算总分
float GPA() { return totalS() / 10.0 - 5; } // 计算课程绩点
};
// 子类 English
class English : public Course {
private:
float exam; // 考试分数
float dailywork; // 平时分数
public:
English(string _id, float _credit, float _exam, float _dailywork)
: Course(_id, _credit), exam(_exam), dailywork(_dailywork) {}
float totalS() { return exam + dailywork; } // 计算总分
float GPA() { return totalS() / 10.0 - 5; } // 计算课程绩点
};
// 子类 Cprogram
class Cprogram : public Course {
private:
float exam; // 考试分数
float dailywork; // 平时分数
public:
Cprogram(string _id, float _credit, float _exam, float _dailywork)
: Course(_id, _credit), exam(_exam), dailywork(_dailywork) {}
float totalS() { return exam + dailywork; } // 计算总分
float GPA() { return totalS() / 10.0 - 5; } // 计算课程绩点
};
int main() {
Course *courses[3];
courses[0] = new AdvanceMathematic("AdvanceMathematic", 4.0, 85.0, 90.0);
courses[1] = new English("English", 3.0, 75.0, 80.0);
courses[2] = new Cprogram("Cprogram", 3.0, 80.0, 85.0);
float total_credit = 0.0;
float total_GPA = 0.0;
for (int i = 0; i < 3; i++) {
total_credit += courses[i]->get_credit();
total_GPA += courses[i]->get_credit() * courses[i]->GPA();
cout << "Course ID: " << courses[i]->get_credit() << endl;
cout << "Total Score: " << courses[i]->totalS() << endl;
cout << "GPA: " << courses[i]->GPA() << endl;
cout << endl;
}
cout << "Average GPA: " << total_GPA / total_credit << endl;
for (int i = 0; i < 3; i++) {
delete courses[i];
}
return 0;
}
```
上述代码中,基类 `Course` 包含课程 ID 和学分两个私有数据成员,以及读取学分的公有成员函数 `get_credit` 和两个纯虚函数 `totalS` 和 `GPA`。三个子类 `AdvanceMathematic`、`English` 和 `Cprogram` 均公有继承基类 `Course`,并在构造函数中初始化私有属性 `exam` 和 `dailywork`。
在 `main` 函数中,使用基类指针数组 `courses` 存储三个子类的对象,并计算每个课程总分和课程绩点。最后输出每门课程的总分和课程绩点,以及三门课程的平均绩点。在程序结束时,使用 `delete` 释放动态分配的内存。
在mysql数据库中准备相应数据表,编写windows可视化界面程序•设计GUI程序,把这些coursecode、coursename、学分credit、成绩score展示在Listbox中。运行的程序界面如左图,要求界面设置button1=”查表显示”和button2=”计算平均绩点”。点击“查表显示”则select数据表的10条记录转换为10个String显示在Listbox,如右图,点击“计算平均绩点” 算出平均绩点,把平均绩点显示在文本框中。(select * from course_score)
好的,您需要在MySQL数据库中准备一张名为course_score的数据表,包含coursecode、coursename、credit和score这四个字段。然后,您需要编写一个Windows可视化界面程序,并设计GUI程序。界面中应该有一个Listbox用于展示coursecode、coursename、credit和score,以及两个按钮,一个是“查表显示”,另一个是“计算平均绩点”。
当用户点击“查表显示”按钮时,应该从数据表中选择10条记录,并将这10条记录转换为10个字符串显示在Listbox中,如右图所示。
当用户点击“计算平均绩点”按钮时,应该计算出平均绩点,并将其显示在文本框中。具体计算方法如下:
1. 计算每门课程的绩点,使用如下公式:绩点 = (score - 50) / 10,如果score小于60,则绩点为0。
2. 计算加权平均绩点,使用如下公式:加权平均绩点 = Σ(绩点 * credit) / Σcredit。
3. 将计算结果显示在文本框中。
最后需要注意的是,当用户点击“查表显示”按钮时,应该先清空Listbox中的内容,然后再将数据显示在Listbox中。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)