标签:using public int ace bsp change font testing system
一、题目描述
每个用户有用户编号(id),用户名(name),密码(passwd)三个属性。其中:
二、解答内容
//user.h
1 #ifndef HEADER_U 2 #define HEADER_U 3 #include<string> 4 #include<iostream> 5 using namespace std; 6 7 //User类声明 8 class User { 9 public: 10 void setInfo(string name0, string passwd0 = "111111", int id0 = 1);//支持设置用户信息 11 void changePasswd(); //支持修改密码 12 void printInfo(); //支持打印用户信息 13 private: 14 int id; 15 static int CurrentID; 16 string name; 17 string passwd; 18 }; 19 int User::CurrentID = 999; //静态成员初始化 20 21 void User::setInfo(string name0, string passwd0, int id0) { 22 id = ++CurrentID; 23 name = name0; 24 passwd = passwd0; 25 } 26 27 void User::changePasswd() { 28 string passwd1, passwdN; 29 int n = 1; 30 cout << "Enter the old passwd:"; 31 cin >> passwd1; 32 while (n <= 3) { 33 if (User::passwd == passwd1) { 34 cout << "Enter the new passwd:"; 35 cin >> passwdN; 36 break; 37 } 38 else if (n < 3 && (User::passwd != passwd1)) { 39 cout << "passwd input error,Please re-Enter again:"; 40 cin >> passwd1; 41 n++; 42 } 43 else if (n == 3 && (User::passwd != passwd1)) { 44 cout << "Please try after a while." << endl; 45 break; 46 } 47 } 48 } 49 50 void User::printInfo() { 51 cout << "CurrentID:\t" << CurrentID << endl; 52 cout << "id:\t\t" << id << endl; 53 cout << "name:\t\t" << name << endl; 54 cout << "passwd:\t\t" << "******" << endl; 55 } 56 57 #endif
//User.cpp
1 #include<iostream> 2 #include"user.h" 3 using namespace std; 4 5 int main() { 6 cout << "testing 1......" << endl << endl; 7 User user1; 8 user1.setInfo("Leonard"); 9 user1.printInfo(); 10 11 cout << endl << "testing 2......" << endl << endl; 12 User user2; 13 user2.setInfo("Jonny", "92197"); 14 user2.printInfo(); 15 16 system("pause"); 17 return 0; 18 }
三、题后小结
标签:using public int ace bsp change font testing system
原文地址:https://www.cnblogs.com/zuiyankh/p/10693428.html