Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Ask the user for an email address. Determine if the input meets the standard for

ID: 3572266 • Letter: A

Question

Ask the user for an email address. Determine if the input meets the standard for an email address. An email address must have an @ symbol. Further, an email address must have a period after the @ symbol.. In HyperGrade my code passes all but one. I cant figure out how to make my code determine whether there there is a . AFTER the @ symbol. It reads it before, but not after. My code is attached along with the failed test. I found this question on Chegg before but they do not work, they do the same thing as mine, I do not want another set of codes, just a revision of mine. I want to keep the cctype library and the ispunct function.Thank you.

test@examplecom Required Output Your Program's Output Enter your email address n Missing . symbol after an Enter your email address n Missing symbol after @n Test Case 4 -Failed Standard Input test.person@examplecom Required Output Your Program's Output Enter your email addressAn Missing symbol aftern Enter your email addressAn Email accepted.An (Your output is too short.) Test Case 5 Passed Standard Input test.person.other@example.com Required Output Your Program's Output Enter your email address n Email accepted.An Enter your email addressin Email accepted. An

Explanation / Answer

#include <iostream>// required header files

#include <string>

#include <cctype>

using namespace std;

bool isCharacter();

bool isNumber();

bool isValidEmailAddress(string);

bool isCharacter(const char Character) // checking charaters are not

{

return ( (Character >= 'a' && Character <= 'z') || (Character >= 'A' && Character <= 'Z'));

}

bool isNumber(const char Character) // checking number or not

{

return ( Character >= '0' && Character <= '9');

}

bool isValidEmailAddress(const char * email) // main function to check email address

{

if(!email)

return 0;

if(!isCharacter(email[0]))// if first character is not a charecter then not an email address

return 0;

int AtOffset = -1;

int DotOffset = -1;

unsigned int Length = strlen(email); // length of string

for(unsigned int i = 0; i < Length; i++)

{

if(email[i] == '@') // checking we have @ and . characters in the string and getting there index numbers

AtOffset = (int)i;

else if(email[i] == '.')

DotOffset = (int)i;

}

if(AtOffset == -1 || DotOffset == -1) // if not there then not vaild email address

return 0;

if(AtOffset > DotOffset) // if . comes first then not valid email address

return 0;

return !(DotOffset >= ((int)Length-1)); // if . index is less than length then valid

}

int main() // main method

{ string test; // declaring req variables

string email;

cout << "Enter in your email and I will tell "

<< "you if it is valid or not. " ;

getline(cin, email); // getting email address

test=email;

if(isValidEmailAddress(test) )// if true returned than valid

cout << "Your email address is valid.";

else // else no

cout << "Your email address is invalid, Please re-enter.";

system("pause");

return 0;

}// end of main

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote