subject
Engineering, 04.04.2020 09:35 McMingMing

In this lab, you will be creating a class that implements the Rule of Three (A Destructor, A Copy Constructor, and a Copy Assignment Operator). You are to create a program that prompts users to enter in contact information, dynamically create each object, then print the information of each contact to the screen. Some code has already been provided for you. To receive full credit make sure to implement the following:

Default Constructor - set Contact id to -1
Overloaded Constructor - used to set the Contact name, phoneNumber and id (Should take in 3 parameters)
Destructor
Copy Constructor
Copy Assignment Operator
Any other useful functions (getters/setters)
Main. cpp

#include
#include
#include "Contact. h"

using namespace std;

int main() {
const int NUM_OF_CONTACTS = 3;
vector contacts;

for (int i = 0; i < NUM_OF_CONTACTS; i++) {
string name, phoneNumber;
cout << "Enter a name: ";
cin >> name;
cout << "Enter a phoneNumber; ";
cin >> phoneNumber;

// TODO: Use i, name, and phone number to dynamically create a Contact object on the heap
// HINT: Use the Overloaded Constructor here!

// TODO: Add the Contact * to the vector...
}
cout << "\n\n Contacts \n\n";

// TODO: Loop through the vector of contacts and print out each contact info

// TODO: Make sure to call the destructor of each Contact object by looping through the vector and using the delete keyword

return 0;
}

Contact. h

#ifndef CONTACT_H
#define CONTACT_H

#include
#include

using std::string;
using std::cout;

class Contact {
public:
Contact();
Contact(int id, string name, string phoneNumber);
~Contact();
Contact(const Contact& copy);
Contact& operator=(const Contact& copy);

private:
int *id = nullptr;
string *name = nullptr;
string *phoneNumber = nullptr;
};

#endif

Contact. cpp

#include "Contact. h"

Contact::Contact() {
this->id = new int(-1);
this->name = new string("No Name");
this->phoneNumber = new string("No Phone Number");
}

Contact::Contact(int id, string name, string phoneNumber) {
// TODO: Implement Overloaded Constructor
// Remember to initialize pointers on the heap!
}

Contact::~Contact() {
// TODO: Implement Destructor
}

Contact::Contact(const Contact ©) {
// TODO: Implement Copy Constructor
}

Contact &Contact::operator=(const Contact ©) {
// TODO: Implement Copy Assignment Operator
return *this;
}

ansver
Answers: 1

Another question on Engineering

question
Engineering, 04.07.2019 18:10
Steel is coated with a thin layer of ceramic to protect against corrosion. what do you expect to happen to the coating when the temperature of the steel is increased significantly? explain.
Answers: 1
question
Engineering, 04.07.2019 18:10
Refrigerant 134a enters an insulated compressor operating at steady state as saturated vapor at -26°c with a volumetric flow rate of 0.18 m3/s. refrigerant exits at 9 bar, 70°c. changes in kinetic and potential energy from inlet to exit can be ignored. determine the volumetric flow rate at the exit, in m3/s, and the compressor power, in kw.
Answers: 1
question
Engineering, 04.07.2019 18:10
Slip occurs via two partial dislocations because of (a) the shorter path of the partial dislocation lines; (b) the lower energy state through partial dislocations; (c) the charge balance.
Answers: 1
question
Engineering, 04.07.2019 18:10
An ideal otto cycle with air as the working fluid has a compression ratio of 8. the minimum and maximum temperatures in the cycle are 300 k and 1340 k. use constant specific heats at room temperature to determine (a) the amount of heat transferred to the air during the heat- addition kj/kg, (b) the thermal efficiency, and (c) the thermal efficiency of a carnot cycle ope limits. process, in rating between the same temperature
Answers: 2
You know the right answer?
In this lab, you will be creating a class that implements the Rule of Three (A Destructor, A Copy Co...
Questions
question
Physics, 11.07.2021 15:10
question
Mathematics, 11.07.2021 15:10
question
English, 11.07.2021 15:10
question
Biology, 11.07.2021 15:10
question
Health, 11.07.2021 15:10
Questions on the website: 13722363