Question

/// c ++ question plz help me fix this not a new code and explain to...

/// c ++ question plz help me fix this not a new code 
and explain to me plz

///   

Write a function to verify the format of an email address:

bool VeryifyEmail(char email[ ]);

Do NOT parse the email array once character at a time. Use cstring functions to do most of the work. Take a look at the available cstring and string class functions on cplusplus website.

Use a two dimensional array to store the acceptable top domain names: "COM", "ORG", "NET", "US", "CN", "CA",etc.

/////

I didnt do the 2D array, please also put it in the code thanks
//////

#include <iostream>
#include <string>
bool VeryfyEmail(char email);
bool isCharacter(char Character);
bool isNumber(char Character);
using namespace std;
 
int main()
{
    // set the email you wanna Verify
    string email;
    string test;
 
    cout << " enter an Email: " << endl;
    getline(cin,email);
    test = email;
 
    // output the email you entered
    cout << "the email you enter is: " << endl;
    cout << email;
    cout << endl;
    /////////////////////////////////////////////
    // Verfy email
    if (VeryfyEmail(test))
    {
        cout << " your email is vaild." << endl<< endl;
    }
    else
    {
        cout << " your email is invaild. " << endl<< endl;
    }
    return 0;
}
 
bool VeryfyEmail(char email)
{
    if(!email) // if cannot read emial
    {
        return 0;
    }
    if(!isCharacter(email[0]))
    {
        return 0;
        // first character not a character a-z A-Z
    }
    int atOffset = -1;
    int Dotoffset = -1;
    int length =  strlen(email); //length
    for (int i =0; i < length; i++)
    {
        if (email[i] == '@') // if one of the character is @ store it in atOffset
        {
            atOffset = (int)i;
        }
        else if (email[i] =='.') // if one of the character is . store it in Dotoffset
        {
            Dotoffset = (int)i;
        }
    }
    if (atOffset == -1 || Dotoffset == -1)
    {
        cout << " i cannot find any '@' or '.' " << endl;
        return 0;
    }
    if (atOffset > Dotoffset)
    {
    cout << "@ is after ." << endl<< endl;
    return 0;
    }
    return !(Dotoffset >= ((int)length -1 )); // check there is some other letters after the Dot
}
 
bool isCharacter(char Character)
{
    return ((Character >= 'a' && Character <= 'z') || (Character >='A' && Character <= 'Z'));
    // check between a-z or A-Z
}
bool isNumber(char Character)
{
    return (Character>='0' && Character <= '9');
    //between 0-9
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <string>
bool VeryfyEmail(char email);
bool isCharacter(char Character);
bool isNumber(char Character);
using namespace std;
 
int main()
{
    // set the email you wanna Verify
    string email;
    string test;
 
    cout << " enter an Email: " << endl;
    getline(cin,email);
    test = email;
 
    // output the email you entered
    cout << "the email you enter is: " << endl;
    cout << email;
    cout << endl;
    /////////////////////////////////////////////
    // Verfy email
    if (VeryfyEmail(test))
    {
        cout << " your email is vaild." << endl<< endl;
    }
    else
    {
        cout << " your email is invaild. " << endl<< endl;
    }
    return 0;
}
 
bool VeryfyEmail(char email[]) // Here there was a mistake since you have not used [] for email parameter, so it was accepting the string as character and not string
{
    if(!email) // if cannot read emial
    {
        return 0;
    }
    if(!isCharacter(email[0]))
    {
        return 0;
        // first character not a character a-z A-Z
    }
    int atOffset = -1;
    int Dotoffset = -1;
    int length =  strlen(email); //length
    for (int i =0; i < length; i++)
    {
        if (email[i] == '@') // if one of the character is @ store it in atOffset
        {
            atOffset = (int)i;
        }
        else if (email[i] =='.') // if one of the character is . store it in Dotoffset
        {
            Dotoffset = (int)i;
        }
    }
    if (atOffset == -1 || Dotoffset == -1)
    {
        cout << " i cannot find any '@' or '.' " << endl;
        return 0;
    }
    if (atOffset > Dotoffset)
    {
    cout << "@ is after ." << endl<< endl;
    return 0;
    }
    return !(Dotoffset >= ((int)length -1 )); // check there is some other letters after the Dot
}
 
bool isCharacter(char Character)
{
    return ((Character >= 'a' && Character <= 'z') || (Character >='A' && Character <= 'Z'));
    // check between a-z or A-Z
}
bool isNumber(char Character)
{
    return (Character>='0' && Character <= '9');
    //between 0-9
}
Add a comment
Know the answer?
Add Answer to:
/// c ++ question plz help me fix this not a new code and explain to...
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
  • C++ problem where should I do overflow part? in this code do not write a new...

    C++ problem where should I do overflow part? in this code do not write a new code for me please /////////////////// // this program read two number from the user // and display the sum of the number #include <iostream> #include <string> using namespace std; const int MAX_DIGITS = 10; //10 digits void input_number(char num[MAX_DIGITS]); void output_number(char num[MAX_DIGITS]); void add(char num1[MAX_DIGITS], char num2[MAX_DIGITS], char result[MAX_DIGITS], int &base); int main() { // declare the array = {'0'} char num1[MAX_DIGITS] ={'0'}; char...

  • ***************Fix code recursive function #include <iostream> #include <cctype> #include <string> using namespace std; void printUsageInfo(string executableName)...

    ***************Fix code recursive function #include <iostream> #include <cctype> #include <string> using namespace std; void printUsageInfo(string executableName) { cout << "Usage: " << executableName << " [-c] [-s] string ... " << endl; cout << " -c: turn on case sensitivity" << endl; cout << " -s: turn off ignoring spaces" << endl; exit(1); //prints program usage message in case no strings were found at command line } string tolower(string str) { for(unsigned int i = 0; i < str.length(); i++)...

  • C++ Programming - Design Process I need to create a flow chart based on the program...

    C++ Programming - Design Process I need to create a flow chart based on the program I have created. I am very inexperienced with creating this design and your help will be much appreciated. My program takes a string of random letters and puts them them order. Our teacher gave us specific functions to use. Here is the code: //list of all the header files #include <iomanip> #include <iostream> #include <algorithm> #include <string> using namespace std; //Here are the Function...

  • SCREENSHOTS ONLY PLEASE!!! DON'T POST ACTUAL CODE PLEASE LEAVE A SCREENSHOT ONLY! ACTUAL TEXT IS NOT NEEDED!!! myst...

    SCREENSHOTS ONLY PLEASE!!! DON'T POST ACTUAL CODE PLEASE LEAVE A SCREENSHOT ONLY! ACTUAL TEXT IS NOT NEEDED!!! mystring.h: //File: mystring1.h // ================ // Interface file for user-defined String class. #ifndef _MYSTRING_H #define _MYSTRING_H #include<iostream> #include <cstring> // for strlen(), etc. using namespace std; #define MAX_STR_LENGTH 200 class String { public: String(); String(const char s[]); // a conversion constructor void append(const String &str); // Relational operators bool operator ==(const String &str) const; bool operator !=(const String &str) const; bool operator >(const...

  • Can you tell me what is wrong and fix this code. Thanks #include <iostream> #include <string>...

    Can you tell me what is wrong and fix this code. Thanks #include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; //function void displaymenu1(); int main ( int argc, char** argv ) { string filename; string character; string enter; int menu1=4; char repeat; // = 'Y' / 'N'; string fname; string fName; string lname; string Lname; string number; string Number; string ch; string Displayall; string line; string search; string found;    string document[1000][6];    ifstream infile; char s[1000];...

  • CHALLENGE ACTIVITY 8.4.2: Find char in C string Assign a pointer to any instance of searchChar...

    CHALLENGE ACTIVITY 8.4.2: Find char in C string Assign a pointer to any instance of searchChar in personName to searchResult. #include <iostream> #include <cstring> using namespace std; int main() { char personName[100]; char searchChar; char* searchResult = nullptr; cin.getline(personName, 100); cin >> searchChar; /* Your solution goes here */ if (searchResult != nullptr) { cout << "Character found." << endl; } else { cout << "Character not found." << endl; } return 0; }

  • Problem with C++ program. Visual Studio say when I try to debug "Run-Time Check Failure #2...

    Problem with C++ program. Visual Studio say when I try to debug "Run-Time Check Failure #2 - Stack around the variable 'string4b' was corrupted. I need some help because if the arrays for string4a and string4b have different sizes. Also if I put different sizes in string3a and string4b it will say that those arrays for 3a and 3b are corrupted. But for the assigment I need to put arrays of different sizes so that they can do their work...

  • In C++ please! *Do not use any other library functions(like strlen) than the one posted(<cstddef>) in the code below!* /** CS 150 C-Strings Follow the instructions on your handout to complete t...

    In C++ please! *Do not use any other library functions(like strlen) than the one posted(<cstddef>) in the code below!* /** CS 150 C-Strings Follow the instructions on your handout to complete the requested function. You may not use ANY library functions or include any headers, except for <cstddef> for size_t. */ #include <cstddef> // size_t for sizes and indexes ///////////////// WRITE YOUR FUNCTION BELOW THIS LINE /////////////////////// ///////////////// WRITE YOUR FUNCTION ABOVE THIS LINE /////////////////////// // These are OK after...

  • I want to change this code and need help. I want the code to not use...

    I want to change this code and need help. I want the code to not use parallel arrays, but instead use one array of struct containing the data elements, String for first name, String for last name,Array of integers for five (5) test scores, Character for grade. If you have any idea help would be great. #include #include #include #include using namespace std; const int NUMBER_OF_ROWS = 10; //number of students const int NUMBER_OF_COLUMNS = 5; //number of scores void...

  • I have to type and explain in class each code in every detail filled with //...

    I have to type and explain in class each code in every detail filled with // commentary. Explains how does work in every codes. 1) What does the below print #include <iostream> using namespace std ; int main() {    int var1 = 20 ;    int var2 = 30 ;    int* ptr1 ;    int* ptr2 ;    int* temp ;    ptr1 = &var1 ;    ptr2 = &var2 ;    cout << *ptr1 << endl ;...

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