编写一个标准类—Student
Main函数:
#include <iostream>
#include <string>
#include "Student.h"
using namespace std;
int main()
{
Student student("xiaoming", "123");
student.display();
student.set_pass_word("456");
cout << student.get_pass_word();
return 0;
}
头文件:
#include <string>
using namespace std;
class Student
{
private:
string user_name;
string pass_word;
public:
Student(string user_name, string pass_word);
string get_user_name();
string get_pass_word();
void set_user_name(string user_name);
void set_pass_word(string pass_word);
void display();
};
源文件:
#include <string>
#include <iostream>
#include "student.h"
using namespace std;
Student::Student(string user_name, string pass_word)
{
this->user_name = user_name;
this->pass_word = pass_word;
}
string Student::get_user_name()
{
return this->user_name;
}
string Student::get_pass_word()
{
return this->pass_word;
}
void Student::set_user_name(string user_name)
{
this->user_name = user_name;
}
void Student::set_pass_word(string pass_word)
{
this->pass_word = pass_word;
}
void Student::display()
{
cout << "user_name: " << this->user_name << endl;
cout << "pass_word: " << this->pass_word << endl;
}