Question

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 !.@,#,$,%,^,&,* 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
Add a comment Improve this question Transcribed image text
Answer #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 a comment
Know the answer?
Add Answer to:
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:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Program is in C++, program is called airplane reservation. It is suppose to display a screen...

    Program is in C++, program is called airplane reservation. It is suppose to display a screen of seating chart in the format 1 A B C D E F through 10. I had a hard time giving the seats a letter value. It displays a correct screen but when I reserve a new seat the string seats[][] doesn't update to having a X for that seat. Also there is a file for the struct called systemUser.txt it has 4 users...

  •    moviestruct.cpp #include <iostream> #include <fstream> #include <cstdlib> #include <ostream> #include <fstream> #include <cstdlib> #include <cstring>...

       moviestruct.cpp #include <iostream> #include <fstream> #include <cstdlib> #include <ostream> #include <fstream> #include <cstdlib> #include <cstring> using namespace std; typedef struct{ int id; char title[250]; int year; char rating[6]; int totalCopies; int rentedCopies; }movie; int loadData(ifstream &infile, movie movies[]); void printAll(movie movies[], int count); void printRated(movie movies[], int count); void printTitled(movie movies[], int count); void addMovie(movie movies[],int &count); void returnMovie(movie movies[],int count); void rentMovie(movie movies[],int count); void saveToFile(movie movies[], int count, char *filename); void printMovie(movie &m); int find(movie movies[], int...

  • Can you fix this program and run an output for me. I'm using C++ #include using...

    Can you fix this program and run an output for me. I'm using C++ #include using namespace std; //function to calculate number of unique digit in a number and retun it int countUniqueDigit(int input) {    int uniqueDigitCount = 0;    int storeDigit = 0;    int digit = 0;    while (input > 0) {        digit = 1 << (input % 10);        if (!(storeDigit & digit)) {            storeDigit |= digit;       ...

  • C++ programming I need at least three test cases for the program and at least one...

    C++ programming I need at least three test cases for the program and at least one test has to pass #include <iostream> #include <string> #include <cmath> #include <iomanip> using namespace std; void temperatureCoverter(float cel){ float f = ((cel*9.0)/5.0)+32; cout <<cel<<"C is equivalent to "<<round(f)<<"F"<<endl; } void distanceConverter(float km){ float miles = km * 0.6; cout<<km<<" km is equivalent to "<<fixed<<setprecision(2)<<miles<<" miles"<<endl; } void weightConverter(float kg){ float pounds=kg*2.2; cout<<kg<<" kg is equivalent to "<<fixed<<setprecision(1)<<pounds<<" pounds"<<endl; } int main() { string country;...

  • please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName();...

    please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName(); double getNumberExams(); double getScoresAndCalculateTotal(double E); double calculateAverage(double n, double t); char determineLetterGrade(); void displayAverageGrade(); int main() { string StudentName; double NumberExam, Average, ScoresAndCalculateTotal; char LetterGrade; StudentName = getStudentName(); NumberExam = getNumberExams(); ScoresAndCalculateTotal= getScoresAndCalculateTotal(NumberExam); Average = calculateAverage(NumberExam, ScoresAndCalculateTotal); return 0; } string getStudentName() { string StudentName; cout << "\n\nEnter Student Name:"; getline(cin, StudentName); return StudentName; } double getNumberExams() { double NumberExam; cout << "\n\n Enter...

  • fully comments for my program, thank you will thumb up #include <iostream> #include <fstream> #include <string>...

    fully comments for my program, thank you will thumb up #include <iostream> #include <fstream> #include <string> #include <iomanip> using namespace std; struct book { int ISBN; string Author; string Title; string publisher; int Quantity; double price; }; void choice1(book books[], int& size, int MAX_SIZE) { ifstream inFile; inFile.open("inventory.txt"); if (inFile.fail()) cout <<"file could not open"<<endl; string str;    while(inFile && size < MAX_SIZE) { getline(inFile, str); books[size].ISBN = atoi(str.c_str()); getline(inFile, books[size].Title);    getline(inFile, books[size].Author); getline(inFile, books[size].publisher);          getline(inFile,...

  • I am trying to run this program in Visual Studio 2017. I keep getting this build...

    I am trying to run this program in Visual Studio 2017. I keep getting this build error: error MSB8036: The Windows SDK version 8.1 was not found. Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution". 1>Done building project "ConsoleApplication2.vcxproj" -- FAILED. #include <iostream> #include<cstdlib> #include<fstream> #include<string> using namespace std; void showChoices() { cout << "\nMAIN MENU" << endl; cout << "1: Addition...

  • #include<iostream> #include<string> #include<iomanip> using namespace std; /* ********* Class Car ************* ********************************* */ class Car {...

    #include<iostream> #include<string> #include<iomanip> using namespace std; /* ********* Class Car ************* ********************************* */ class Car { private: string reportingMark; int carNumber; string kind; bool loaded; string choice; string destination; public: Car() { reportingMark = ""; carNumber = 0; kind = "Others"; loaded = 0; destination = "NONE"; } ~Car() { } void setUpCar(string &reportingMark, int &carNumber, string &kind, bool &loaded, string &destination); }; void input(string &reportingMark, int &carNumber, string &kind, bool &loaded,string choice, string &destination); void output(string &reportingMark, int &carNumber,...

  • #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str);...

    #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str); int numConsonants(char *str); int main() {    char string[100];    char inputChoice, choice[2];    int vowelTotal, consonantTotal;    //Input a string    cout << "Enter a string: " << endl;    cin.getline(string, 100);       do    {        //Displays the Menu        cout << "   (A) Count the number of vowels in the string"<<endl;        cout << "   (B) Count...

  • Write a psuedocode for this program. #include <iostream> using namespace std; string message; string mappedKey; void...

    Write a psuedocode for this program. #include <iostream> using namespace std; string message; string mappedKey; void messageAndKey(){ string msg; cout << "Enter message: "; getline(cin, msg); cin.ignore(); //message to uppercase for(int i = 0; i < msg.length(); i++){ msg[i] = toupper(msg[i]); } string key; cout << "Enter key: "; getline(cin, key); cin.ignore(); //key to uppercase for(int i = 0; i < key.length(); i++){ key[i] = toupper(key[i]); } //mapping key to message string keyMap = ""; for (int i = 0,j...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT