为什么想要的all是随机数 应该怎么改

#include<iostream>
using namespace std;
class Emplotee
{
protected:
    int id;
    int name;
    int basic_salary;
};
class Staff :public Emplotee
{
    int bonus;
    int all;
public:
    Staff();
    Staff(int a, int b, int c, int d);
    friend void addgod(Staff &s);
    void display();
};
Staff::Staff()
{
    bonus = 0;all = 0;
}
Staff::Staff(int a, int b, int c, int d)
{
    id = a;name = b;basic_salary = c;bonus = d;
}
void  addgod(Staff& s)
{
    s.all = s.basic_salary + s.bonus;
}
void Staff::display()
{
    cout << id << " " << name << " " << "with salary " << all;
}
int main()
{
    int a = 0;
    Staff s1;
    addgod(s1);
    s1 = Staff(101, 222, 400, 600);
    s1.display();
}

#include<iostream>
using namespace std;
class Emplotee
{
protected:
    int id;
    int name;
    int basic_salary;
};
class Staff :public Emplotee
{
    int bonus;
    int all;
public:
    Staff();
    Staff(int a, int b, int c, int d);
    friend void addgod(Staff &s);
    void display();
};
Staff::Staff()
{
    bonus = 0;all = 0;
}
Staff::Staff(int a, int b, int c, int d)
{
    id = a;name = b;basic_salary = c;bonus = d;
}
void  addgod(Staff& s)
{
    s.all = s.basic_salary + s.bonus;
}
void Staff::display()
{
    cout << id << " " << name << " " << "with salary " << all;
}
int main()
{
    Staff s1;
    // 你的顺序放错了,先初始化,再调用方法
    s1 = Staff(101, 222, 400, 600);
    addgod(s1);
    s1.display();
}

用代码段贴代码不好吗?这样都不是很想看呢。

初始化那里用rand生成一个随机数赋值给它就行啊

您好,我是有问必答小助手,你的问题已经有小伙伴为您解答了问题,您看下是否解决了您的问题,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632