期中·第二题

#include<iostream>
using namespace std;
int currentID=999;

class user{
    public:
        user();
        void print();
        void changepassword();
        void show();
    private:
    int id;
    string name,password;   
}; 

user::user():id(currentID+1){
    currentID++;
    cout<<"请输入你的名字:";
    cin>>name;
    password="111111";
}

void user::print()
{
    cout<<"ID:"<<id<<endl;
    cout<<"Name:"<<name<<endl;
    cout<<"Password:"<<password<<endl; 
} 

void user::changepassword(){
    int n=3;
    while(n){
     string expassword;
     cout<<"--密码修改--"<<endl; 
     cout<<"输入原密码:";
     cin>>expassword;
     if(password==expassword)
     {
         cout<<"输入新密码:";
         cin>>password;
     }else
     { 
     cout<<"Wrong Password"<<endl;
     if(n==1) cout<<"请稍后再试..."<<endl;
     n--;
     }
    }
}

void user::show(){
    cout<<"ID:"<<currentID<<endl;
}

int main()
{
    int num;
    cout<<"输入新用户个数:";
    cin>>num;
    while(num--)
    {
        user a;
        a.show();
        if(num==0)
        {
            a.print();
            a.changepassword();
            a.print();
        }
    }
}

运行截图:
1348246-20180510180802751-1754718211.png

转载于:https://www.cnblogs.com/zengiai/p/9020999.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值