My assignment is listed below. I already have the code
complete, but I cannot figure out how to complete this
portion:
You must create a makefile to compile and build your
program.
I can't figure out if I need to create a makefile, and if I do,
what commands do I use for that?
Create a ContactInfo class that contains the following member variables:
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)
5. You must create a makefile to compile and build your program. In addition, you must test your program on linprog.cs.fsu.edu. (25 points)
(For this step - you must include a copy of the makefile and a copy of the terminal output from a compile and test run as shown below.)
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.
Get Answers For Free
Most questions answered within 1 hours.