Homework Help Question & Answers

I'm just a beginner in programming,how to make this program more simple without using #include<iostream> and #include<redex> here is the question Terms to know: If-else statement,for.....

I'm just a beginner in programming,how to make this program more simple without using #include<iostream> and #include<redex>

here is the question

Terms to know:

If-else statement,for..while..do while,loops,pointer,address,continue,return,break.

Create a C++ program which contain a function to ask user to enter user ID and password. The passwordmust contain at least 6 alphanumeric characters, 1 of the symbols [email protected],#,$,%,^,&,* and 1 capital letter.The maximum allowable password is 20. Save the information. Test the program by entering the User ID and password. The maximum number of trials is 3 and if the user has exceed this number,the program will terminate. Explain your program by using comments and please make program which codeblock can read it

#include <iostream>
#include<string.h>
#include <regex>
using namespace std;

//structure format store username and password
struct Data{
   string username;
   string password;
};

bool checkPassword(string pass){
   if(pass.length()>=6 && pass.length()<=20){
   return true;
   }
   return false;
}

int main() {
  
   //creating array of for 10 users
   Data data[10];
   int userCount=0;
   int choice=-1;
   while(choice!=0){
       cout<<endl;
       cout<<"choice\tdescription"<<endl;
       cout<<"1\tsignup\n";
       cout<<"2\t login\n";
       cout<<"0\t exit\n";
       cout<<"enter your choice: ";
       cin>>choice;
      
       if(choice==1){
           if(userCount<10){
               cout<<"enter username: ";
               cin>>data[userCount].username;
               cout<<"enter password: ";
               cin>>data[userCount].password;
               while(checkPassword(data[userCount].password)!=true){
                   cout<<"password does not matched the given format\n";
                   cout<<"Format is:The password must contain at least 6 alphanumeric characters, 1 of the symbols !,@,#,$,%,^,&,* and 1 capital letter.The maximum allowable password is 20"<<endl;
                   cout<<"enter password again: ";
                   cin>>data[userCount].password;
               }
           }
           else{
               cout<<"user database is full, cannot add new record\n";
           }
       }
       else if(choice==2){
           string user,pass;
           cout<<"enter user name: ";
           cin>>user;
          
           int flag=0;
           int count=3;
           for(int i=0;i<10;i++){
               if(data[i].username==user){
                   flag=1;
                   while(1){
                       count--;
                       cout<<"enter password: ";
                       cin>>pass;
                       if(data[i].password==pass){
                           cout<<"Login successfully\n";
                           flag=2;
                           break;
                       }
                       else{
                           if(count==0){
                               return 0;
                           }
                           cout<<"invalid password, please try again. Attempt left: "<<count<<endl;
                       }
                   }
               }
           }
       }
       else if(choice==0){
           break;
       }
   }
   return 0;
}

0 0
ReportAnswer #1

#include<iostream> IS needed for cin, cout. It just exposes for input and output. We need this

I have removed <regex>

---------------------------------------------------------------------------------------------------------------------------------------------------

#include <iostream>

using namespace std;

//structure format store username and password

struct Data{

string username;

string password;

};

bool checkPassword(string pass){

if(pass.length()>=6 && pass.length()<=20){

return true;

}

return false;

}

int main() {

//creating array of for 10 users

Data data[10];

int userCount=0;

int choice=-1;

while(choice!=0){

cout<<endl;

cout<<"choice\tdescription"<<endl;

cout<<"1\tsignup\n";

cout<<"2\t login\n";

cout<<"0\t exit\n";

cout<<"enter your choice: ";

cin>>choice;

if(choice==1){

if(userCount<10){

cout<<"enter username: ";

cin>>data[userCount].username;

cout<<"enter password: ";

cin>>data[userCount].password;

while(checkPassword(data[userCount].password)!=true){

cout<<"password does not matched the given format\n";

cout<<"Format is:The password must contain at least 6 alphanumeric characters, 1 of the symbols !,@,#,$,%,^,&,* and 1 capital letter.The maximum allowable password is 20"<<endl;

cout<<"enter password again: ";

cin>>data[userCount].password;

}

}

else{

cout<<"user database is full, cannot add new record\n";

}

}

else if(choice==2){

string user,pass;

cout<<"enter user name: ";

cin>>user;

int flag=0;

int count=3;

for(int i=0;i<10;i++){

if(data[i].username==user){

flag=1;

while(1){

count--;

cout<<"enter password: ";

cin>>pass;

if(data[i].password==pass){

cout<<"Login successfully\n";

flag=2;

break;

}

else{

if(count==0){

return 0;

}

cout<<"invalid password, please try again. Attempt left: "<<count<<endl;

}

}

}

}

}

else if(choice==0){

break;

}

}

return 0;

}


--------------------------------------------------------------------------------------------------------------------------------
See Output

main.cppsaved 2 using namespace std; 4 //structure format store username and password clang version 7.0.0-3-ubuntu0.18.04.1 (
Thanks, PLEASE COMMENT if there is any concern.

Add Homework Help Answer
Add Answer of:
I'm just a beginner in programming,how to make this program more simple without using #include<iostream> and #include<redex> here is the question Terms to know: If-else statement,for.....
Your Answer: Your Name: What's your source?
Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
More Homework Help Questions Additional questions in this topic.
Need Online Homework Help?
Ask a Question
Get FREE EXPERT Answers
WITHIN MINUTES
Related Questions