include <iostream>
using namespace std;
#include"time_user.h"
class student
{
public:
void display();
public:
int num;
string name;
char sex;
};
void student::display()
{
cout << "num: " << num << endl;
cout << "name: " << name << endl;
cout << "sex: " << sex << endl;
}
int main()
{
student stl1;
stl1.name = "gyg";
stl1.num = 1001;
stl1.sex = 'm';
stl1.display();
}
实验二
#include <iostream>
using namespace std;
#include"time_user.h"
class student
{
private:
int age;
string name;
public:
void input(int a, string str)
{
age = a;
name = str;
}
void output()
{
cout << "name: " << name << endl;
cout << "age: " << age << endl;
}
};
int main()
{
student s[3];
s[0].input(18, "gyg");
s[1].input(19, "guo");
s[2].input(20, "zy");
for (int i = 0; i < 3; i++)
{
s[i].output();
}
标签:cout,int,void,stl1,student,input,4.23 From: https://www.cnblogs.com/lml66/p/17347671.html