Question

In: Computer Science

directions: use c++ Create a  ContactInfo class that contains the following member variables: name age phoneNumber The...

directions: use c++

Create a  ContactInfo class that contains the following member variables:

  • name
  • age
  • phoneNumber

The ContactInfo class should have a default constructor that sets name = "", phoneNumber = "", and age = 0.

The ContactInfo class should have a constructor that accepts the name and phone number as parameters and sets name = <value of parameter name>, aAge = 0, and phoneNumber = <value of parameter phone number>.

The ContactInfo class should have accessor and mutator functions for each member variable.

The ContactInfo class should have a function called canVote that returns a boolean. It will return true if age is >= 18. Otherwise, it will return false.

Create three instances of this class in the main function

Write a C++ function (outside of the class) that will display (as shown below in the sample run) an instance of the ContactInfo class. Call the function to display the three instances you created in the main function.

Make sure your program conforms to the following requirements:
1. This program should be called ContactInfoApp.cpp. The header file should be called ContactInfo.h and place member function definitions in ContactInfo.cpp. You must submit these three files.

Include the basic header in your program. (5 points deduction if missing)

2. Properly set up the ContactInfo class and declare three instances of ContactInfo (45 points)

3. Write a C++ program that will create and display (as shown below in the sample run) three instances of the ContactInfo class. (25 points).

4. Add comments wherever necessary. (5 points)

Sample Run:

NOTE: not all possible runs are shown below.

Name: Kristen Lee
Phone Number: 555-2021
Age: 45
Can vote?: Yes

Name: Joe Smith
Phone Number: 111-9999
Age: 5
Can vote?: No

Name: Tom Hanks
Phone Number: 111-8888
Age: 75
Can vote?: Yes

General Requirements:

1) Include the header comment with your name and other information on the top of your files.

2. Please make sure that you're conforming to specifications (program name, print statements, expected inputs, and outputs, etc.). Not doing so will result in a loss of points. This is especially important for prompts. They should match mine EXACTLY.

3. If we have listed a specification and allocated a point for it, you will lose points if that particular item is missing from your code, even if it is trivial.

4. No global variables (variables outside of main) unless they are constants.

5. All input and output must be done with streams, using the library iostream

6. You may only use the iostream, iomanip, and string libraries. Including unnecessary libraries will result in a loss of points.

7. NO C style printing is permitted. (Aka, don't use printf). Use cout if you need to print to the screen.

8. When you write source code, it should be readable and well-documented (comments).

9. Make sure you test using G++ (to be sure it reports no compile errors or warnings!) before you submit the program.

10. Testing your program thoroughly is a part of writing good code. We give you sample runs to make sure you match our output requirements and to get a general idea of how we would test your code. Matching your outputs for JUST the sample runs is not a guarantee of a 100. We have several extensive test cases.

11. Program submissions should be done through the Canvas class page, under the assignments tab (if it's not there yet I'll create it soon.) Do not send program submissions through e-mail { e-mail attachments will not be accepted as valid submissions.

12. The four files you will submit via Canvas are ContactInfoApp.cpp, ContactInfo.h, ContactInfo.cpp, and your makefile.

13. Please make sure you've compiled and run your program before you turn it in. Compilation errors can be quite costly. We take 4 points per compiler error for the first 9 errors. The 10th compiler error will result in a grade of 0.

14. Only a file turned in through Canvas counts as a submission. A file on your computer, even if it hasn't been edited after the deadline, does not count. Now that you are familiar with the process of turning in a file through Canvas, we will not accept any excuses.

15. The student is responsible for making sure they have turned in the right file(s). We will not accept any excuses about inadvertently modifying or deleting files, or turning in the wrong files.

16. General Advice - always keep an untouched copy of your finished homework files in your email. These files will have a time-stamp which will show when they were last worked on and will serve as a backup in case you ever have legitimate problems with submitting files through Canvas. Do this for ALL programs.

Solutions

Expert Solution

ContactInfo.h:

Code as text (to copy):

#ifndef _CONTACT_INFO_H_

#define _CONTACT_INFO_H_

#include <iostream>

#include <string>

using namespace std;

class ContactInfo {

private:

string name;

string phoneNumber;

int age;

public:

// default constructor

ContactInfo();

// parameterised constructor

ContactInfo(string _name, string _phoneNumber);

// accessor

string getName();

string getPhoneNumber();

int getAge();

// mutators

void setName(string _name);

void setPhoneNumber(string _phoneNumber);

void setAge(int _age);

// member functions

bool canVote();

};

#endif

ContactInfo.cpp:

Code as text (to copy):

#include "ContactInfo.h"

// Default constructor

ContactInfo::ContactInfo() {

name = "";

phoneNumber = "";

age = 0;

}

// Parameterised constructor

ContactInfo::ContactInfo(string _name, string _phoneNumber) {

name = _name;

phoneNumber = _phoneNumber;

age = 0;

}

// Accessor functions

// function to get name of contact

string ContactInfo::getName() {

return name;

}

// function to get phone number of contact

string ContactInfo::getPhoneNumber() {

return phoneNumber;

}

// function to get age of contact

int ContactInfo::getAge() {

return age;

}

// Mutator functions

// function to set name of contact

void ContactInfo::setName(string _name) {

name = _name;

}

// function to set phone number of contact

void ContactInfo::setPhoneNumber(string _phoneNumber) {

phoneNumber = _phoneNumber;

}

// function to set age of contact

void ContactInfo::setAge(int _age) {

age = _age;

}

// Member functions

// boolean function

// returns true if age >= 18 otherwise return false

bool ContactInfo::canVote() {

return age >= 18;

}

ContactInfoApp.cpp:

Code as text (to copy):

#include <iostream>

#include <string>

#include "ContactInfo.h"

using namespace std;

// function to display an instance of the class ContactInfo

void displayContactInfo(ContactInfo& obj) {

cout << "Name: " << obj.getName() << endl;

cout << "Phone Number: " << obj.getPhoneNumber() << endl;

cout << "Age: " << obj.getAge() << endl;

cout << "Can vote?: ";

if (obj.canVote()) cout << "Yes" << endl;

else cout << "No" << endl;

}

int main() {

// Create three instances of class ContactInfo

ContactInfo instance1("Kristen Lee", "555-2021");

instance1.setAge(45);

ContactInfo instance2, instance3;

instance2.setName("Joe Smith");

instance2.setPhoneNumber("111-9999");

instance2.setAge(5);

instance3.setName("Tom Hanks");

instance3.setPhoneNumber("111-8888");

instance3.setAge(75);

// call function to display details of three instances

displayContactInfo(instance1); cout << endl;

displayContactInfo(instance2); cout << endl;

displayContactInfo(instance3);

return 0;

}

makefile:

makefile as text (to copy):

CXX = g++

CXXFLAGS = -Wall

ContactInfoApp: ContactInfoApp.o ContactInfo.o

$(CXX) $(CXXFLAGS) -o ContactInfoApp ContactInfoApp.o ContactInfo.o

ContactInfoApp.o: ContactInfoApp.cpp

$(CXX) $(CXXFLAGS) -c ContactInfoApp.cpp

ContactInfo.o: ContactInfo.cpp ContactInfo.h

$(CXX) $(CXXFLAGS) -c ContactInfo.cpp

Sample Run:

P.s.> Check screenshots to get proper indentation of code.

ask any doubts in comments and don't forget to rate the answer.


Related Solutions

Create a UEmployee class that contains member variables for the university employee name and salary. The...
Create a UEmployee class that contains member variables for the university employee name and salary. The UEmployee class should contain member methods for returning the employee name and salary. Create Faculty and Staff classes that inherit the UEmployee class. The Faculty class should include members for storing and returning the department name. The Staff class should include members for storing and returning the job title. Write a runner program that creates one instance of each class and prints all of...
1)  Create a UEmployee class that contains member variables for the university employee name and salary. The...
1)  Create a UEmployee class that contains member variables for the university employee name and salary. The UEmployee class should contain member methods for returning the employee name and salary. Create Faculty and Staff classes that inherit the UEmployee class. The Faculty class should include members for storing and returning the department name. The Staff class should include members for storing and returning the job title. Write a runner program that creates one instance of each class and prints all of...
First lab: Create a Fraction class Create member variables to store numerator denominator no additional member...
First lab: Create a Fraction class Create member variables to store numerator denominator no additional member variable are allowed Create accessor and mutator functions to set/return numerator denominator Create a function to set a fraction Create a function to return a fraction as a string ( common name ToString(), toString())  in the following format: 2 3/4 use to_string() function from string class to convert a number to a string; example return to_string(35)+ to_string (75) ; returns 3575 as a string Create...
In C++ please Your class could have the following member functions and member variables. However, it's...
In C++ please Your class could have the following member functions and member variables. However, it's up to you to design the class however you like. The following is a suggestion, you can add more member variables and functions or remove any as you like, except shuffle() and printDeck(): (Note: operators must be implemented) bool empty(); //returns true if deck has no cards int cardIndex; //marks the index of the next card in the deck Card deck[52];// this is your...
THIS IS JAVA PROGRAMMING 1. Create a class named Name that contains the following: • A...
THIS IS JAVA PROGRAMMING 1. Create a class named Name that contains the following: • A private String to represent the first name. • A private String to represent the last name. • A public constructor that accepts two values and assigns them to the above properties. • Public methods named getProperty (e.g. getFirstName) to return the value of the property. • Public methods named setProperty ( e.g. setFirstName)to assign values to each property by using a single argument passed...
Using C# Create a class called Artist that contains 4 pieces of information as instance variables:...
Using C# Create a class called Artist that contains 4 pieces of information as instance variables: name (datatype string), specialization – i.e., music, pottery, literature, paintings (datatype string), number of art items (datatype int), country of birth (datatype string). Create a constructor that initializes the 4 instance variables. The Artist class must contain a property for each instance variable with get and set accessors. The property for number should verify that the Artist contributions is greater than zero. If a...
C++ PersonData and CustomerData classes Design a class named PersonData with the following member variables: lastName...
C++ PersonData and CustomerData classes Design a class named PersonData with the following member variables: lastName firstName address city state zip phone Write the appropriate accessor and mutator functions for these member variables. Next, design a class named CustomerData, which is derived from the PersonData class. The CustomerData class should have the following member variables: customerNumber mailingList The customerNumber variable will be used to hold a unique integer for each customer. The mailingList variable should be a bool. It will...
# List the two private member variables (including name and functionality) in the node class. #Write...
# List the two private member variables (including name and functionality) in the node class. #Write a general pattern for a loop statement that traverses all the nodes of a linked list
Create a class named Horse that contains the following data fields: name - of type String...
Create a class named Horse that contains the following data fields: name - of type String color - of type String birthYear - of type int Include get and set methods for these fields. Next, create a subclass named RaceHorse, which contains an additional field, races (of type int), that holds the number of races in which the horse has competed and additional methods to get and set the new field. ------------------------------------ DemoHorses.java public class DemoHorses {     public static void...
Create a class called Student. Include the following instance variables: name, address, phone, gpa Create all...
Create a class called Student. Include the following instance variables: name, address, phone, gpa Create all of the methods required for a standard user defined class: constructors, accessors, mutators, toString, equals Create the client for testing the Student class Create another class called CourseSection Include instance variables for: course name, days and times course meets (String), description of course, student a, student b, student c (all of type Student) Create all of the methods required for a standard user defined...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT