C++上机实验问题:类和对象

将如下代码改成多文件的程序,要求:
将类定义放在头文件 Student.h 中;
将成员函数定义放在源文件 Student.cpp 中;
将主函数的源文件放在“项目名”.cpp 中。
在类中增加一个对数据成员赋初值的成员函数 set_value

#include<iostream.h>
using namespace std;
class student
{public:
    void display();
private:
    int num;
    char name[20];
    char sex;}
void Student::display()
{
    cout << "num:" << num << endl;
    cout << "name:" << name << endl;
    cout << "sex:" << sex << endl;}
int main()
{
    Student studl;
    studl.display();
    return 0;}

前面几个,你复制粘贴下,自己弄
最后一个成员函数,稍等,我帮你写

#include<iostream.h>
using namespace std;
class Student
{
public:
    void display();
    void set_value(int n, char na[], char s);
private:
    int num;
    char name[20];
    char sex;
};

void Student::display()
{
    cout << "num:" << num << endl;
    cout << "name:" << name << endl;
    cout << "sex:" << sex << endl;
}

void Student::set_value(int n, char na[], char s)
{
    num = n;
    strcpy(name, na);
    sex = s;
}

int main()
{
    Student studl;
    studl.set_value(1, "John", 'M');
    studl.display();
    return 0;
}


不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^