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

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 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...
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...
Write a C program/code that prompts the user for a minimum min and a maximum max....
Write a C program/code that prompts the user for a minimum min and a maximum max. Then use these values to print the squares of all even numbers between the min and max variables. For example if the user enters 6 as the minimum and 200 as the maximum, the program/code should print the following. Enter limit on minimum square: 6 Enter limit on maximum square: 200 36 64 100 144 196
Write a program that asks the user for an angle, entered in radians. The program should...
Write a program that asks the user for an angle, entered in radians. The program should then display the sine, cosine, and tangent of the angle. (Use the sin, cos, and tan library functions to determine these values.) The output should be displayed in fixed-point notation, rounded to four decimal places of precision Take your previous Angle Calculator program and modify it to do a table of trig values. The columns will be: Degrees, Sine, Cosine, Tangent,. And the rows...
Using C# programming language, Write a program that sort three numbers entered by the user using...
Using C# programming language, Write a program that sort three numbers entered by the user using only if and nested if statements. If for instance the user entered 5, 2, and 7; the program should display 2,5,7.
Write a C++ program performing the rot13 cipher, The code should perform like this: The user...
Write a C++ program performing the rot13 cipher, The code should perform like this: The user should be able to input any letter or words, or even sentences where once they have inputted the particular word, each letter goes 13 letters ahead, so an 'A' becomes an 'N', a 'C' becomes 'P', and so on. If rot13 cipher is tested a second time, the original plantext should be restored: 'P' becomes 'C', 'N' becomes 'A'. The 13 letters go in...
in C please! Write a code that asks user for input N and calculates the sum...
in C please! Write a code that asks user for input N and calculates the sum of the first N odd integers. There should be a "pure" method that calculates the sum separately that Main method should call when printing the output.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT