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
Add a comment
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 Coin

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
  •    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...

  • 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 <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...

  • 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...

  • #include <iostream> #include <sstream> #include <string> using namespace std; int main() {    const int index...

    #include <iostream> #include <sstream> #include <string> using namespace std; int main() {    const int index = 5;    int head = 0;    string s[index];    int flag = 1;    int choice;    while (flag)    {        cout << "\n1. Add an Item in the Chores List.";        cout << "\n2. How many Chores are in the list.";        cout << "\n3. Show the list of Chores.";        cout << "\n4. Delete an...

  • Can someone fix the program below so it does what the picture says it won't work...

    Can someone fix the program below so it does what the picture says it won't work for me. import java.util.Scanner; public class Userpass { static String arr[]; static int i = 0; public static void main(String[] args) { String username, password; int tries = 0, result; do { System.out.print("Enter the username: "); username = readUserInput(); System.out.print("Enter the password: "); password = readUserInput(); result = verifyCredentials(username, password); tries++; if (result == -1) System.out.println("The username is incorrect!\n"); else if (result == -2)...

  • #include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; struct transition{ // transition structure...

    #include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; struct transition{ // transition structure char start_state, to_state; char symbol_read; }; void read_DFA(struct transition *t, char *f, int &final_states, int &transitions){ int i, j, count = 0; ifstream dfa_file; string line; stringstream ss; dfa_file.open("dfa.txt"); getline(dfa_file, line); // reading final states for(i = 0; i < line.length(); i++){ if(line[i] >= '0' && line[i] <= '9') f[count++] = line[i]; } final_states = count; // total number of final states // reading...

  • THIS IS FOR C++ PROGRAMMING USING VISUAL STUDIO THE PROGRAM NEEDS TO BE IN C++ PROGRAMMING #inclu...

    THIS IS FOR C++ PROGRAMMING USING VISUAL STUDIO THE PROGRAM NEEDS TO BE IN C++ PROGRAMMING #include "pch.h" #include #include using namespace std; // Function prototype void displayMessage(void); void totalFees(void); double calculateFees(int); double calculateFees(int bags) {    return bags * 30.0; } void displayMessage(void) {    cout << "This program calculates the total amount of checked bag fees." << endl; } void totalFees() {    double bags = 0;    cout << "Enter the amount of checked bags you have." << endl;    cout <<...

  • #include <fstream> #include <iostream> #include <cstdlib> using namespace std; // Place charcnt prototype (declaration) here int...

    #include <fstream> #include <iostream> #include <cstdlib> using namespace std; // Place charcnt prototype (declaration) here int charcnt(string filename, char ch); int main() { string filename; char ch; int chant = 0; cout << "Enter the name of the input file: "; cin >> filename; cout << endl; cout << "Enter a character: "; cin.ignore(); // ignores newline left in stream after previous input statement cin.get(ch); cout << endl; chcnt = charcnt(filename, ch); cout << "# of " «< ch« "'S:...

Free Homework 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.