Question

Please do this in C++. Thank you in advance. Note that you have to carefully create...

Please do this in C++. Thank you in advance.

Note that you have to carefully create your class using the names and capitalization shown below. Put comments into your program, make sure you indent your program properly, and use good naming conventions.

Create a class called entry. It should have two private data members of type std::string. One represents a name and the other represents an email address. Make sure you give them ,meaningful names.

Create public getters and setters for the two strings with the following signatures:

string getName() const;

void setName(string newName);

string getEmail() const;

void setEmail(string newEmail);

The entry class also needs two constructors. One that takes no parameters and sets both std::string values to "". The second one should have two std::string parameters. The first parameter is the name and and the second one is the email address.

You must not inline the constructors. You can, optionally, inline some or all of the remaining member functions.

Create your main function and create two instances of the entry class. The first one must use the default constructor and the second one must use the constructor that takes two parameters. Give the parameters the text "Susan Smith" and "[email protected]".

Your main function should output the contents of the name for the first entry object and the email of the second entry object. Your main function will call the appropriate getter member functions to get the values for name and email. Your main function should output the text with no headings or extra characters, but do output a std::endl after outputting the name and again after outputting the email.

Note that some of the tests are unit tests where I will create entry objects and call the various getters and setters. Note that you will be creating the entry class and the main function all in the same input file.

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

// do comment if any problem arises

//code

//answer has been highlighted

#include <iostream>

using namespace std;

class entry

{

private:

    string name, email;

public:

    // getter for name

    string getName() const

    {

        return name;

    }

    // setter for name

    void setName(string newName)

    {

        name = newName;

    }

    // getter for email

    string getEmail() const

    {

        return email;

    }

    // setter for email

    void setEmail(string newEmail)

    {

        email = newEmail;

    }

    // default constructor

    entry()

    {

        name = "";

        email = "";

    }

    // perameterized  constructor

    entry(string temo_name, string temo_email)

    {

        name = temo_name;

        email = temo_email;

    }

};

int main()

{

    // create 2 entry objects

    entry first, second("Susan Smith", "[email protected]");

    // print name of first object

    cout << first.getName() << endl;

    // print email of second object

    cout << second.getEmail();

}

Output:

PS E:\fixer> .\a.exe sue@example.com PS E:\fixer>.

PS E:\fixer> .\a.exe [email protected] PS E:\fixer>.

PS E:\fixer> .\a.exe [email protected] PS E:\fixer>.

Add a comment
Know the answer?
Add Answer to:
Please do this in C++. Thank you in advance. Note that you have to carefully create...
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
  • Godzilla Class Pt. 2 C++ I have to continue building off of this class and do...

    Godzilla Class Pt. 2 C++ I have to continue building off of this class and do the following I got help with the code below but could use some guidance as to how to finish this out. Any help would be appreciated This is the code for the main.cpp #include <iostream> #include "Godzilla.h" using namespace std; int main() { double health; double power; //prompt the user to input the health and power for Godzilla cout<< "Enter the health: " ;...

  • Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram)

    Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram) Author -name:String -email:String -gender:char +Author(name:String, email:String, gender:char) +getName():String +getEmail):String +setEmail (email:String):void +getGender():char +tostring ):String . Three private instance variables: name (String), email (String), and gender (char of either 'm' or 'f'): One constructor to initialize the name, email and gender with the given values . Getters and setters: get Name (), getEmail() and getGender (). There are no setters for name and...

  • Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   and please put comment with code! Problem:2 1. Class Student Create...

    Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   and please put comment with code! Problem:2 1. Class Student Create a "Hello C++! I love CS52" Program 10 points Create a program that simply outputs the text Hello C++!I love CS52" when you run it. This can be done by using cout object in the main function. 2. Create a Class and an Object In the same file as...

  • When answering this question, can you please specify what you name your files? Thank you! Write a...

    When answering this question, can you please specify what you name your files? Thank you! Write a Java application, and an additional class to represent some real-world entity. Keep in mind that a class is a model in code of something real or imagined, which has attributes (member variables) and behaviors (member methods). The class will: a. Create a total of 5 member variables for the class, selecting the appropriate data types for each field. For example, a class to...

  • for c++ answer the following and create the following (1)Declare a class to hold Employee Data....

    for c++ answer the following and create the following (1)Declare a class to hold Employee Data. It must have at least 2 attributes and 1 method in addition to getters/setters for 1 of the 2 attributes. Also, include at least 2 constructors and a destructor. Put the appropriate members in public and private sections. You don't need to write the code to implement the class except for getters and setters which should include the appropriate inline code. (2) What is/are...

  • C++ programming question, please help! Thank you so much in advance!!! In this exercise, you will...

    C++ programming question, please help! Thank you so much in advance!!! In this exercise, you will work with 2 classes to be used in a RPG videogame. The first class is the class Character. The Character class has two string type properties: name and race. The Character class also has the following methods: a constructor Character(string Name, string Race), that will set the values for the name and the race variables set/get functions for the two attributes a function print(),...

  • Create a java class for an object called Student which contains the following private attributes: a...

    Create a java class for an object called Student which contains the following private attributes: a given name (String), a surname (family name) (String), a student ID number (an 8 digit number, String or int) which does not begin with 0. There should be a constructor that accepts two name parameters (given and family names) and an overloaded constructor accepting two name parameters and a student number. The constructor taking two parameters should assign a random number of 8 digits....

  • C++ Assignment: Create a class called FitnessMember that has only one variable, called name. The FitnessMember...

    C++ Assignment: Create a class called FitnessMember that has only one variable, called name. The FitnessMember class should have a constructor with no parameters, a constructor with a parameter, a mutator function and an accessor function. Also, include a function to display the name. Define a class called Athlete which is derived from FitnessMember. An Athlete record has the Athlete's name (defined in the FitnessMember class), ID number of type String and integer number of training days. Define a class...

  • Here is the UML for the class Contact -fullName : string -phoneNum: string -emailAddress : string...

    Here is the UML for the class Contact -fullName : string -phoneNum: string -emailAddress : string +Contact()                     //default constructor sets all attribute strings to “unknown”; no other constructor +setName(string name) : void +setPhone(string pn) : void +setEmail(string em) : void +getName() : string +getPhone() : string +getEmail() : string +printContact() : void         //print out the name, phone numbers and email address Create New Project Name your project: CIS247_Lab7_YourLastName. For this exercise, you may use a header file or one file...

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