多文件组织项目Student类
来源:互联网 发布:公司oa软件哪款好 编辑:程序博客网 时间:2024/05/18 01:54
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.做一个项目最好多文件组织项目,良好的习惯需要逐步养成!!!
- 多文件组织项目Student类
- 利用多文件组织项目
- 利用多文件组织项目
- 利用多文件组织项目
- 多文件组织项目
- 一个项目多文件组织
- 项目5,多文件组织
- 项目四--学生类Student
- C++第6周项目5 - 多文件组织三角形类
- C++第6周项目5 - 多文件组织三角形类
- 第三周项目三 多文件组织三角形类
- 第三周 项目3 类的多文件组织
- 第5周项目多文件组织三角形类
- 第7周项目3多文件组织类的程序
- 第七周项目(3)-多文件组织角色类
- 项目3——多文件组织游戏类
- 第7周项目3-用多文件组织角色类
- 多文件组织---三角形类
- ORACLE的数据类型
- composition pattern
- qt程序调试
- ubuntu 忘记root用户及密码的恢复方法
- fedora15 播放音频视频
- 多文件组织项目Student类
- 为啥是我得癌症?(不管什么行业,请耐心读完)
- 黑马程序员_枚举,结构,数组,方法
- 未公开的Oracle数据库秘密
- windows终端下mysql无法正常关闭
- 如何手动将jar文件加入到Maven 3的local repository中
- 我的第一篇博客
- memcache 的配置
- inet_ntoa的实现