c++基础题

设计一一个名为 student 学生类,其中有数据成员:姓名( name )、性别( sex )、学号( num )、分数( score );类中的成员函数:设置带有3个参数的构造函数和无参构造函数、输出学生信息的函数 display (),更改学生信息的函数 modify 

(1)完成 student 类的定义和相应成员函数的实现;

(2)创建﹣个 student 对象st1。 st 的信息为"张三,男,1234567",将st1学生分数更新为78,显示更新后学生的信息。

(3)创建一﹣个 student 对象st2,实现学生st2=st1;并输出st2的信息。

 

#include <iostream>
#include <string>
using namespace std;

class student {
private:
    string name;
    string sex;
    string num;
    int score;

public:
    student() {}
    student(string n, string s, string no, int sc) {
        name = n;
        sex = s;
        num = no;
        score = sc;
    }

    void display() {
        cout << "姓名:" << name << ",性别:" << sex << ",学号:" << num << ",分数:" << score << endl;
    }

    void modify(int sc) {
        score = sc;
    }
};

int main() {
    student st1("张三", "男", "1234567", 0);
    st1.modify(78);
    st1.display();

    student st2 = st1;
    st2.display();

    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

李烁.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值