2301_78163545 2023-05-27 18:57 采纳率: 73.1%
浏览 127
已结题

创建一个Student类该类中具有学生姓名、学号、性别、年龄、班级、计算机成绩和英语成绩等属性

要求将数据成员定义为保护类型;
在该类中定义成员函数实现所有学生信息的输入
创建该类的两个学生对象,并将他们的信息以及各自两门课的平均成绩进行输出

img

  • 写回答

2条回答 默认 最新

  • threenewbee 2023-05-27 19:13
    关注
    #include <iostream>  
    using namespace std;
    
    class Student {  
    protected:  
        string name;  // 姓名  
        int id;      // 学号  
        string gender;  // 性别  
        int age;     // 年龄  
        string class;  // 班级  
        double computer_score;  // 计算机成绩  
        double english_score;  // 英语成绩  
    public:  
        Student() {  
            name = "";  
            id = 0;  
            gender = "";  
            age = 0;  
            class = "";  
            computer_score = 0;  
            english_score = 0;  
        }  
        string get_name() const { return name; }  
        int get_id() const { return id; }  
        string get_gender() const { return gender; }  
        int get_age() const { return age; }  
        string get_class() const { return class; }  
        double get_computer_score() const { return computer_score; }  
        double get_english_score() const { return english_score; }  
        void input_info() {  
            cout << "请输入学生姓名:" << endl;  
            cin >> name;  
            cout << "请输入学生学号:" << endl;  
            cin >> id;  
            cout << "请输入学生性别:" << endl;  
            cin >> gender;  
            cout << "请输入学生年龄:" << endl;  
            cin >> age;  
            cout << "请输入学生班级:" << endl;  
            cin >> class;  
            cout << "请输入学生计算机成绩:" << endl;  
            cin >> computer_score;  
            cout << "请输入学生英语成绩:" << endl;  
            cin >> english_score;  
        }  
        Student(string name, int id, string gender, int age, string class, double computer_score, double english_score) {  
            this->name = name;  
            this->id = id;  
            this->gender = gender;  
            this->age = age;  
            this->class = class;  
            this->computer_score = computer_score;  
            this->english_score = english_score;  
        }  
    };
    
    int main() {  
        Student student1("张三", 100, "男", 20, "一班", 80, 90);  
        Student student2("李四", 101, "女", 21, "二班", 90, 85);  
          
        cout << "学生 1 信息如下:" << endl;  
        cout << "姓名:" << student1.get_name() << endl;  
        cout << "学号:" << student1.get_id() << endl;  
        cout << "性别:" << student1.get_gender() << endl;  
        cout << "年龄:" << student1.get_age() << endl;  
        cout << "班级:" << student1.get_class() << endl;  
        cout << "计算机成绩:" << student1.get_computer_score() << endl;  
        cout << "英语成绩:" << student1.get_english_score() << endl;  
          
        cout << "学生 2 信息如下:" << endl;  
        cout << "姓名:" << student2.get_name() << endl;  
        cout << "学号:" << student2.get_id() << endl;  
        cout << "性别:" << student2.get_gender() << endl;  
        cout << "年龄:" << student2.get_age() << endl;  
        cout << "班级:" << student2.get_class() << endl;  
        cout << "计算机成绩:" << student2.get_computer_score() << endl;  
        cout << "英语成绩:" << student2.get_english_score() << endl;  
          
        return 0;  
    }
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 6月5日
  • 已采纳回答 5月28日
  • 创建了问题 5月27日

悬赏问题

  • ¥15 gojs 点击按钮node的position位置进行改变,再次点击回到原来的位置
  • ¥15 计算决策面并仿真附上结果
  • ¥20 halcon 图像拼接
  • ¥15 webstorm上开发的vue3+vite5+typeScript打包时报错
  • ¥15 vue使用gojs,需求在link中的虚线上添加方向箭头
  • ¥15 CSS通配符清除内外边距为什么可以覆盖默认样式?
  • ¥15 SPSS分类模型实训题步骤
  • ¥100 求ASMedia ASM1184e & ASM1187e 芯片datasheet/规格书
  • ¥15 求解决扩散模型代码问题
  • ¥15 工创大赛太阳能电动车项目零基础要学什么