ComputerUserAccess 1

Users of the computer have profile which consists of Name, Password, and Access Rights. Access rights take on values X, R, W, and A. It is possible to have default values for Password and Access rights which are the first three letters of the Name and ALL respectively. Users can change their password and access rights. Write a class User in C++ and create a user named Rajesh.

Input Format

First line containg the name of the user as a string Second line contains the choice on the user as an integer (0 to enter your details, 1 to edit your details, 2 to display your details, otherwise any integer to exit) Third line contains the password as string Fourth line contains the access right as a charecter

Constraints

Access rights take on values X, R, W, and A

Output Format

Display “-1”, if access right has values other than X, R, W, and A, otherwise display user name, password and access right

Sample Input 0

Sample Output 0

Sample Input 1

Sample Output 1

 include <cmath>
 include <cstdio>
 include <vector>
 include <iostream>
 include <algorithm>
 using namespace std;
 
 class User
 {
 public:
     int temp;
     string name;
     string password;
     char access;
     User(string nm)
     {
        name=nm;
        password=name.substr(0,3);
        access='A';
        temp=1;
     }
     void show()
     {
         if(temp==-1)
         {cout<<temp;
         }
         else{
             cout<<name<<endl<<password<<endl<<access;
         }
     }
     void edit()
     {
         char a;
         cin>>password;
         cin>>a;
         if (a=='A' || a=='W' || a=='X' || a=='R')
         {
             access=a;
         }
         else
         {
             temp=-1;
         }
     }
 };
 int main()
 {
     int choice;
     string na;
     cin>>na;
     User m(na);
     cin>>choice;
     switch(choice)
     {
            case 0:m.edit();
         m.show();
         break;
         case 1:m.edit();
         m.show();
         break;
         case 2:m.show();
         break;
         default:
             m.show();
             break;
     }
     return 0;
 }          

Leave a comment

Create a website or blog at WordPress.com

Up ↑

Design a site like this with WordPress.com
Get started