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
Next > < Previous
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.

Know the 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.
Similar Homework Help Questions
  • c++ PLEASE HELP its rather easy if you know what your doing.

    x.øi5class header//File car.h#ifndef STUDENTDATABASE_H#define STDUENTDATABASE_H#include <string>#include <iostream>using namespace std;// Student Database declarationclass StudentDatabase{private:int numberOfRecords;struct StudentRec{ string name;string ID;double GPA;};public:StudentRec *Record;int getnumRecords(){return numberOfRecords;}StudentDatabase();//string getRecord()//{//string userName = Record->name;//return userName;//}void addRecord(string, string, double);void removeRecord(string, string, double);void showAll();int getOneName(StudentRec[], int, string);StudentRec getStudentRecord(){StudentRec StudentRecords[100];return StudentRecords[100];}void sortArray (StudentRec[], int);};#endifclass implementation #include <string>#include "StudentDatabase.h"#include <iostream>#include <iomanip>using namespace std;StudentDatabase::StudentDatabase(){Record = new StudentRec[100];numberOfRecords = 0;}void StudentDatabase::addRecord(string n, string I, double G){StudentRec newstudent;newstudent.name = n;newstudent.ID = I;newstudent.GPA = G;Record[numberOfRecords] = newstudent;numberOfRecords++;}void StudentDatabase::showAll(){StudentRec AllStudents;for (int count = 0; count < numberOfRecords;...

  • graph binary search for size and time c++ //System Libraries #include <iostream> #include <string> #include <cstdlib> #include <ctime> #include <iomanip> #include <alg...

    graph binary search for size and time c++ //System Libraries #include <iostream> #include <string> #include <cstdlib> #include <ctime> #include <iomanip> #include <algorithm> using namespace std; //User Libraries //Global Constants, no Global Variables are allowed //Math/Physics/Conversions/Higher Dimensions - i.e. PI, e, etc... //Function Prototypes //Execution Begins Here! int main(int argc, char** argv) { int n, i, arr[50], search, first, last, middle,count=0,count_in,tot; clock_t start, end; float duration; cout<<"Enter total number of elements :"; cin>>n; cout<<"Enter numbers"; for (i=0; i<n;i++) cin>>arr[i]; cout<<"Enter a...

  • easy program c++

    x.øi5ellspacing="0" cellpadding="0" border="0">I have a working program (well not working anymore) using arrays to add a record, delete etc. I need to now create the program only change the classfiles not the main one and change the arrays into pointers. I started on it, but I'm not very comfortable with the use of pointers, Thanks.main files #include <iostream>#include "StudentDatabase.h"#include <string>#include <iomanip>using namespace std;int main(){StudentDatabase newDB;int choice;void displayMenu();string userNameDesired;int pos;displayMenu();do{cin >> choice;if (choice == 1) {string n;string ident;double gp;cout << "Please...

  • question about my program in c++

    This is my code about passwords checking each word should have at least one upper one lower,one digit and at least 6 character length the user should enter again ifpass not correct and display in screen what is wrong if he type it correct then user enter again to verify ? i done all that but the problem is after the third enteredword only one option of worongs messages appeared not all the wrong messages i mean if i enter...

  • Requirements I have already build a hpp file for the class architecture, and your job is to imple...

    Requirements I have already build a hpp file for the class architecture, and your job is to implement the specific functions. In order to prevent name conflicts, I have already declared a namespace for payment system. There will be some more details: // username should be a combination of letters and numbers and the length should be in [6,20] // correct: ["Alice1995", "Heart2you", "love2you", "5201314"] // incorrect: ["[email protected][email protected]", "12306", "abc12?"] std::string username; // password should be a combination of letters...

  • c++ help with pointers in place of arrays

    x.øi5 working program (well not working anymore) using arrays to add a record, delete etc. I need to now create the program only change the class files not the mainone and change the arrays into pointers. I started on it, but I'm not very comfortable with the use of pointers, Thanks.main files#include <iostream>#include "StudentDatabase.h"#include <string>#include <iomanip>using namespace std;int main(){StudentDatabase newDB;int choice;void displayMenu();string userNameDesired;int pos;displayMenu();do{cin >> choice;if (choice == 1) {string n;string ident;double gp;cout << "Please enter name of student: ";cin...

  • The Code is C++ // tic tac toe game #include <iostream> using namespace std; const int SIZE = 9; int check(char *); void displayBoard(char *); void initBoard(char *); int main() {    char board[...

    The Code is C++ // tic tac toe game #include <iostream> using namespace std; const int SIZE = 9; int check(char *); void displayBoard(char *); void initBoard(char *); int main() {    char board[SIZE];    int player, choice, win, count;    char mark;    count = 0; // number of boxes marked till now    initBoard(board);       // start the game    player = 1; // default player    mark = 'X'; // default mark    do {        displayBoard(board);        cout << "Player " << player << "(" << mark...

  • Please SME urgent

    Project Name: Student Prerequisite Subjects Management SystemDescription: This project requires the use of link list or tree tostore different courses and their prerequisites and based on thislist it will allow any student totake any course or not.Basic Idea: This project will take the course list and theirprerequisites list from user once then it will allow or disallowthe students from taking the prerequisitesthis project will alsobe in c++. This projects can be console based or in graphicsdepending upon the student/s doing...

  • C++ Loops help! Beginner here...

    Please read everything before answering!My Assignment:(1) Generate a data file to record students' grades. Allow users to enter file name of data file; id, name and grade for each student as well as the total number ofstudents. A header should be shown in the data file as follows. Here is an example of the data file.ID NAME GRADE01 Mary 100.0002 Tom 98.3503 John 88.99......(2) If the grade is <0 or >100, ask users to re-enter the correct grade.(3) After the...

  • I NEED A PSEUDOCODE ALGORITHM FOR THIS CODE PLEASE C++: #include #include #include #include using...

    I NEED A PSEUDOCODE ALGORITHM FOR THIS CODE PLEASE C++: #include #include #include #include using namespace std; int NumOfEmployees(); int TotDaysAbsent(int); double AverageAbsent(int, int); int main() {         cout << endl << "Calculate the average number of days a company's employees are absent." << endl << endl;      int numOfEmployees = NumOfEmployees();         TotDaysAbsent(numOfEmployees);    return 0; } int NumOfEmployees() {    int numOfEmployees = 0;     cout << "Please enter the number of employees in the company: ";         cin >> numOfEmployees;     while(numOfEmployees <= 0)     {            ...

Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.