Question

In: Computer Science

*Please write code in C++* Write a program to verify the validity of the user entered...

*Please write code in C++*

Write a program to verify the validity of the user entered email address.  

if email is valid : output the stating that given email is valid. ex: "The email [email protected] is valid"

else : output the statement that the email is invalid and list all the violations

ex:  "The email sarahwinchester.com is invalid"
* @ symbol
* Missing Domain name

  • The program should keep validating emails until user enter 'q'
  • Upload your source code. ex: main.cpp

Solutions

Expert Solution

Code:

#include<iostream>
#include<string>
using namespace std;
int main()
{
   while(true)
   {/*Infinet while loop*/
       string email;
       int at_pos=-1,dot_pos=-1,i;/*declaring variables*/
       cout<<"Enter emailId:";
       getline(cin,email);/*Reading email id*/
       if(email=="q")
       {/*If q e break the loop*/
           break;
       }
       else
       {
           if(email[0]>='0'&& email[0]<='9')
           {/*if email id starting with number*/
               cout<<"The email id "<<email<<" is invalid"<<endl;
               cout<<"* Email Id should not start with a number"<<endl;
           }
           else
           {
               for(i=0;i<email.length();i++)
               {
                   if(email[i]=='@')
                   {/*finding the @ index*/
                       at_pos=i;
                   }
                   if(email[i]=='.')
                   {/*finding the . index*/
                       dot_pos=i;
                   }
               }
               if(at_pos==-1)
               {/*if @ not present*/
                   cout<<"The email id "<<email<<" is invalid"<<endl;
                   cout<<"* @ symbol is missing"<<endl;
                   cout<<"* Missing Domain Name "<<endl;
               }
               else if(dot_pos==-1)
               {/*. not present*/
                   cout<<"The email id "<<email<<" is invalid"<<endl;
                   cout<<"* Missing Domain Name "<<endl;
               }
               else if(dot_pos<at_pos)
               {/*if dot is not present after @ symbol*/
                   cout<<"The email id "<<email<<" is invalid"<<endl;
                   cout<<"* Missing Domain Name "<<endl;
               }
               else
               {/*email id is valid*/
               cout<<"The email id "<<email<<" is valid"<<endl;
               }
              
           }
          
       }
   }
}

Output:

Indentation:


Related Solutions

Write a C++ program that finds the minimum number entered by the user .The user is...
Write a C++ program that finds the minimum number entered by the user .The user is allowed to enter negative numbers 0, or positive numbers. The program should be controlled with a loop statement. Break statements is not allowed to break from loop. After each number inputted by the user, The program will prompt user if they need to enter another number. User should enter either Y for yes or N for no. Make Sure the user enters either Y...
Please code C# 8. Write a program that prompts the user to enter an integer. The...
Please code C# 8. Write a program that prompts the user to enter an integer. The program then determines and displays the following: Whether the integer is divisible by 5 and 6 Whether the integer is divisible by 5 or 6
Using C++ Write a program to ask user to enter a password and validity the password....
Using C++ Write a program to ask user to enter a password and validity the password. The password should be 8 – 20 characters long (8 is included and 20 is included), it should contain at least one uppercase letter and one lower case letter. The password should contain at least one digit, and at least one symbol other than alphabets or numbers. Most importantly, the password may not contain any white space. Functions: You will need at least the...
Please code C# 10. Write a program that allows a user to input names and corresponding...
Please code C# 10. Write a program that allows a user to input names and corresponding heights (assumed to be in inches). The user can enter an indefinite number of names and heights. After each entry, prompt the user whether they want to continue. If the user enters true, ask for the next name and height. If the user enters false, display the name of the tallest individual and their height. Sample run: “Name?” James “Height?” 50 “Continue?” True “Name?”...
Please Write C++ PROGRAM : That will write a program that initially prompts the user for...
Please Write C++ PROGRAM : That will write a program that initially prompts the user for a file name. If the file is not found, an error message is output, and the program terminates. Otherwise, the program prints each token in the file, and the number of times it appeared, in a well formatted manner. To accomplish all this, do the following: - Open the file - the user must be prompted and a file name input. DO NOT hardcode...
Please write in Python code please: Write a program that asks the user to enter 5...
Please write in Python code please: Write a program that asks the user to enter 5 test scores between 0 and 100. The program should display a letter grade for each score and the average test score. You will need to write the following functions, including main: calc_average – The function should accept a list of 5 test scores as an input argument, and return the average of the scores determine_grade – The function should accept a test score as...
Write a C++ program that accepts a single integer value entered by user. If the value...
Write a C++ program that accepts a single integer value entered by user. If the value entered is less than one the program prints nothing. If the user enters a positive integer n. The program prints n x n box drawn with * characters. If the user enters 1 , for example the program prints *. If the user enter a 2, it prints ** ** that is , a 2x2 box of * symbols.
Please write the code JAVA Write a program that allows the user to enter the last...
Please write the code JAVA Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. A sample output is: Candidate      Votes Received                                % of Total Votes...
Write a C++ program using produces Huffman code for a string of text entered by the...
Write a C++ program using produces Huffman code for a string of text entered by the user. Must accept all ASCII characters.
Code in C# please. Write a program that will use the greedy algorithm. This program will...
Code in C# please. Write a program that will use the greedy algorithm. This program will ask a user to enter the cost of an item. This program will ask the user to enter the amount the user is paying. This program will return the change after subtracting the item cost by the amount paid. Using the greedy algorithm, the code should check for the type of bill. Example: Cost of item is $15.50 User pays a $20 bill $20...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT