Problem

This Programming Project explores how the unnamed namespace works. Listed below are snippe...

This Programming Project explores how the unnamed namespace works. Listed below are snippets from a program to perform input validation for a username and password. The code to input and validate the username is in a file separate from the code to input and validate the password.

File user.cpp:

namespace Authenticate

{

void inputllserNameO

{

do

{

cout « “Enter your username (8 letters only)” « endl; cin »

username;

} while (HsValid());

}

string getUserName()

{

return username;

}

}

Define the username variable and the isValid() function in the unnamed namespace so the code will compile. The isValid() function should return true if username contains exactly eight letters. Generate an appropriate header file for this code.

Repeat the same steps for the file password. cpp, placing the password variable and the isValid() function in the unnamed namespace. In this case, the isValid() function should return true if the input password has at least eight characters including at least one nonletter:

File password.cpp:

namespace Authenticate

{

void inputPassword()

{

Do

{

cout « “Enter your password (at least 8 characters “ «

“and at least one nonletter)” « endl;

cin » password;

}

while (iisValid{});

}

string getPassword()

{

return password;

}

}

At this point you should have two functions named isValid(), each in different unnamed namespaces. Place the following main function in an appropriate place. The program should compile and run.

int main()

{

InputllserName();

i nputPassword();

cout « “Your username is “ « getUserName() «

“ and your password is: “ «

getPasswordO « endl ;

return 0;

}

Test the program with several invalid usernames and passwords

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 12
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