Question

In C++ design a function that determines if an email entered by a user is from...

In C++ design a function that determines if an email entered by a user is from an approved email extension. It will return true if the email is valid and false if it is not. The function must also throw an exception if "@" is not in the string argument.

Function Prototype:

bool validEmail(string);

Approved Email Extensions:

list <string> validEmailExtensions = { "@aol.com", "@yahoo.com", "@icloud.com", "@hotmail.com"};

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the completed code for this method. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. If not, PLEASE let me know before you rate, I’ll help you fix whatever issues. Thanks

//required method

bool validEmail(string email){

                //creating a list of valid extensions

                list <string> validEmailExtensions = { "@aol.com", "@yahoo.com", "@icloud.com", "@hotmail.com"};

                //if @ is not found, throwing an exception with a string message.

                if(email.find("@")==string::npos){

                                throw "@ is not found!";

                }

                //looping through the validEmailExtensions list using an iterator

                for(list<string>::iterator it=validEmailExtensions.begin();it!=validEmailExtensions.end();it++){

                                //fetching current value

                                string ext=*it;

                                //making sure that email's length is greater than extension's length

                                if(email.length()>ext.length()){

                                                //checking if email ends with current extension (not just contains, we are checking that

                                                //the last ext.length() characters in email is equal to the string ext or not.)

                                                if(email.compare(email.length()-ext.length(),ext.length(),ext)==0){

                                                                return true; //valid

                                                }

                                }

                               

                }

                //no extensions match, invalid.

                return false;

}

Add a comment
Know the answer?
Add Answer to:
In C++ design a function that determines if an email entered by a user is from...
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
  • In C++, create a recursive bool function which determines if a string is symmetrical or not....

    In C++, create a recursive bool function which determines if a string is symmetrical or not. A symmetrical string can be read the same front to back (ex. kayak). Function Blueprint --------------------- bool isSymmetrical(string s) if (s is the empty string or s is of length 1) return true else if (s's first and last characters are the same letter)   return isSymmetrical (s minus its first and last characters) else return false

  • User Profiles Write a program that reads in a series of customer information -- including name,...

    User Profiles Write a program that reads in a series of customer information -- including name, gender, phone, email and password -- from a file and stores the information in an ArrayList of User objects. Once the information has been stored, the program should welcome a user and prompt him or her for an email and password The program should then use a linearSearch method to determine whether the user whose name and password entered match those of any of...

  • working on a program in c++ The user enters an email address into your program. You...

    working on a program in c++ The user enters an email address into your program. You must cuteverything after the @ symbol and output it. #include <iostream> #include <string> using namespace std; int main() { string email_adress = ""; //email get the info cout <<"what is your email adress? "; getline(cin, email_adress) ; cin.ignore('@'); // now we put into writitng in sentence cout <<"the email you entered is: " << email_adress << ". " <<"your email adress domian is :"...

  • white a program that determines if 3 numbers that are entered, by the user, are sides of a right triangle.

     project 5 functions calling functions white a program that determines if 3 numbers that are entered, by the user, are sides of a right triangle. remember any combination of numbers can be entered, 3 4 5, 5 4 3, 4 3 5... are all the same right triangle. you must have a function that does exponentiation, one that does input one that does output. and one that does the comparisons the main will be this code main:    jal allwork    li $v0,10    syscall function allwork will...

  • REQUIREMENTS: Write a Graphical User Interface (GUI) program using JavaFX that prompts the user to enter...

    REQUIREMENTS: Write a Graphical User Interface (GUI) program using JavaFX that prompts the user to enter a credit card number. Display whether the number is valid and the type of credit cards (i.e., Visa, MasterCard, American Express, Discover, and etc). The requirements for this assignment are listed below: • Create a class (CreditNumberValidator) that contains these methods: // Return true if the card number is valid. Boolean isValid(String cardNumber); // Get result from Step 2. int sumOfDoubleEvenPlace(String cardNumber); // Return...

  • Write a C – program that calls a user-defined function from within main() that determines the...

    Write a C – program that calls a user-defined function from within main() that determines the minimum value from three positive numbers received from the user. Your function should be called minimum.  You must use a loop to receive the numbers. If the user enters a negative number, you must ask the user to re-enter the number. The function should also print out the positive numbers and the smallest number.

  • Python Create a function that checks user input in an attempt to create a password. The...

    Python Create a function that checks user input in an attempt to create a password. The valid_password function accepts a password as an argument and returns either true or false to indicate whether the password is valid. A valid password must be at least 7 characters in length, have at least one uppercase letter, one lowercase letter, and one digit. Respond with output to the user as to whether the password is valid or not, and allow the user to...

  • Q.1. Write a C program that determines whether a line entered by a user is a...

    Q.1. Write a C program that determines whether a line entered by a user is a palindrome or not. You must demonstrate it as an application of stack (you may use linked list implementation demonstrated in the class). Hint! Think of the basic property of a stack i.e. LIFO (list-in-first-out). Q.2. Write a charQueue header file containing all the function headers of following functions: 1- initiateQueue—to initialize a queue 2- enqueue—to add a node at the rear end of the...

  • C++ The member function getCountReadBooks which determines how many books a particular user has r...

    C++ I only need a clear explanation on how to read the file, then get the ratings from a txt file as integers by splitting by comma. (The first item on each line is always the username.) Sum up everything that is NOT 0 and divide by the total amount not including 0 ratings. No vectors using namespace std The member function getCountReadBooks which determines how many books a particular user has read and reviewed. This function should: ● Accept...

  • C++ PROGRAMMING Implement a bool function whose header is given below. Inside the function, declare, ask,...

    C++ PROGRAMMING Implement a bool function whose header is given below. Inside the function, declare, ask, and get a character from the user. The function will return true if the character the user enters is NOT in either of the words, otherwise it will return false. Keep in mind that uppercase and lowercase letters are not the same. You will need to change both words and the character input by the user to the same case (upper or lower) -...

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