多文件组织项目Student类
2012-05-10 23:27
141 查看
Student.h #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(); }; Student.cpp #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; } Main.cpp #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() << endl; return 0; }
运行结果:
user_name: xiaoming
pass_word: 123
456
Press any key to continue
作此项目之前的准备:
画类图:
Student |
string user_name string pass_word |
student (string user_name,string pass_word) |
string get_user_name() string get_pass_word() void set_name_word(string) void set_pass_word(string) void display() |
经验积累:
1.对数据成员赋初值时,所有参数必须与所对应的数据成员名称一致;
2.需要访问数据成员时用this指向;
3.画类图比写代码更为重要;
4.做一个项目最好多文件组织项目,良好的习惯需要逐步养成!!!
相关文章推荐
- 第二周-项目二-程序的多文件组织
- 任务五:一个项目多文件组织完成任务四
- 第二周项目1-多文件程序的组织(课程主页版)
- 第二周项目2-程序的多文件组织
- 【第二周项目2-程序的多文件组织】
- 第二周项目2-程序的多文件组织
- 第二周项目2 - 程序的多文件组织
- 第三周项目三:程序的多文件组织
- 第七周项目三 用多文件组织多个类的程序
- 第四周 项目三 程序的多文件组织
- 第三周项目五——多文件组织
- 第3周项目3-三角形类(程序的多文件组织)
- 第五周项目3 用文件组织多个类的程序
- 第十二周项目四银行系统任务三--将程序用多文件组织
- C语言项目中头文件/代码文件的组织问题(使用VC6.0)
- 第三周 项目4-多文件组织
- 第三周项目三程序的多文件组织
- 第五周项目三多文件组织
- 第3周项目3 程序的多文件组织
- 第3周项目3-程序的多文件组织