1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
HACTEHA [7]
3 years ago
5

In this lab, you will be creating a class that implements the Rule of Three (A Destructor, A Copy Constructor, and a Copy Assign

ment 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;
}

Engineering
1 answer:
Elodia [21]3 years ago
3 0

Answer:

Explanation:

============== main.cpp =======================

#include <iostream>

using namespace std;

#include <iostream>

#include <vector>

#include "Contact.h"

using namespace std;

int main() {

const int NUM_OF_CONTACTS = 3;

vector<Contact *> 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;

// Use i, name, and phone number to dynamically create a Contact object on the heap

// HINT: Use the Overloaded Constructor here!

Contact * newContact = new Contact(i+1,name,phoneNumber);

// Add the Contact * to the vector...

contacts.push_back(newContact);

}

cout << "\n\n----- Contacts ----- \n\n";

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

std::vector<Contact *>::iterator itrContact;

for(itrContact = contacts.begin(); itrContact !=contacts.end(); itrContact++)

{

cout<< " Id : " << (*itrContact)->getId();

cout<< " Name : " << (*itrContact)->getName();

cout<< " Phone-Number : " << (*itrContact)->getPhoneNumber() <<endl;

}

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

for(int i = 0; i < NUM_OF_CONTACTS; i++)

{

delete contacts[i];

}

return 0;

}

================== contact.h =====================

#ifndef CONTACT_H

#define CONTACT_H

#include <string>

#include <iostream>

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);

// getters

int getId() const;

string getName() const;

string getPhoneNumber() const;

//setters

void setId(int id);

void setName(string name);

void setPhoneNumber(string phoneNumber);

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) {

// Implement Overloaded Constructor

// Remember to initialize pointers on the heap!

this->id = new int(id);

this->name = new string(name);

this->phoneNumber = new string(phoneNumber);

}

Contact::~Contact() {

// Implement Destructor

if(this->id != nullptr)

delete this->id;

if(this->name != nullptr)

delete this->name;

if(this->phoneNumber != nullptr)

delete this->phoneNumber;

}

Contact::Contact(const Contact &copy) {

// Implement Copy Constructor

this->id = new int(copy.getId());

this->name = new string(copy.getName());

this->phoneNumber = new string(copy.getPhoneNumber());

}

Contact &Contact::operator=(const Contact &copy) {

// Implement Copy Assignment Operator

if(this == &copy) // Checks for self Assignment

return *this;

this->id = new int(copy.getId());

this->name = new string(copy.getName());

this->phoneNumber = new string(copy.getPhoneNumber());

return *this;

}

// getters

int Contact::getId() const

{

return *(this->id);

}

string Contact::getName() const

{

return *(this->name);

}

string Contact::getPhoneNumber() const

{

return *(this->phoneNumber);

}

//setters

void Contact::setId(int id)

{

*(this->id) = id;

}

void Contact::setName(string name)

{

*(this->name) = name;

}

void Contact::setPhoneNumber(string phoneNumber)

{

*(this->phoneNumber) = phoneNumber;

}

====================Output =========================

is attached below

You might be interested in
A 400 kg machine is placed at the mid-span of a 3.2-m simply supported steel (E = 200 x 10^9 N/m^2) beam. The machine is observe
Alenkinab [10]

Answer:

moment of inertia = 4.662 * 10^6 mm^4

Explanation:

Given data :

Mass of machine = 400 kg = 400 * 9.81 = 3924 N

length of span = 3.2 m

E = 200 * 10^9 N/m^2

frequency = 9.3 Hz

Wm ( angular frequency ) = 2 \pi f = 58.434 rad/secs

also Wm = \sqrt{\frac{g}{t} }  ------- EQUATION 1

g = 9.81

deflection of simply supported beam

t = \frac{wl^3}{48EI}

insert the value of t into equation 1

Wm^2 = \frac{g*48*E*I}{WL^3}   make I the subject of the equation

I ( Moment of inertia about the neutral axis ) = \frac{WL^3* Wn^2}{48*g*E}

I = \frac{3924*3.2^3*58.434^2}{48*9.81*200*10^9}  = 4.662 * 10^6 mm^4

6 0
3 years ago
What is the work required to deflect a linear spring (k=32 kN/m) by 120 cm?
Anit [1.1K]

Answer:

the work done by the linear spring will be equal to 23.04 k J

Explanation:

given,

k = 32 k N /m

deflected spring = 120 cm

                            = 1.2 m

work done by spring can be calculate as

                          = \dfrac{1}{2}kx^2

                          = \dfrac{1}{2}\times 32 \times 1.2^2

                          = 23.04 k J

hence, the work done by the linear spring will be equal to 23.04 k J

6 0
3 years ago
When using an alternative method of sizing with two vent connectors for draft hood-equipped water heaters, the effective area of
amid [387]

Answer:

Fifty (50) percent.<em> [50%] </em>

Explanation:

Water heater is a home appliance that comprises of an electric or gas heating unit as well as a water-tank where water is heated and stored for use.

When using an alternative method of sizing with two vent connectors for draft hood-equipped water heaters, the effective area of the common vent connector or vent manifold and all junction fittings shall not be less than the area of the larger vent connector plus fifty (50) percent of the areas of smaller flue collar outlets.

A water heater is primarily vented with an approved and standardized plastic or metallic pipe such as flue or chimney, which allows gas to flow out of the water heater into the surrounding environment.

For a draft hood-equipped water heater, both the water heater and the barometric draft regulators must be installed in the same room. Also, the technician should ensure that the vent is through a concealed space such as conduit and should be labeled as Type L or Type B.

The minimum capacity of a water heater should be calculated based on the number of bathrooms, bedrooms and its first hour rating.

8 0
3 years ago
Disadvantages of bezier curve and b-spline
Gnesinka [82]

Answer:

The main disadvantage of the Bezier-curves is the global influence of the control points on the whole curve.

This has two major drawbacks: (1) every change of a control point (insert, move, delete) changes the look of the curve in all points of the curve, and (2) the computation time needed for a big set of control points is comparatively high. The reason is the weighting-function form.

hope it helps,pls mark me as brainliest

5 0
3 years ago
In the idealized Otto cycle, heat is added during: a. Isentropic Compression b. Constant (minimum) volume c. Constant (maximum)
docker41 [41]

Answer:

(b) Constant (minimum) volume

Explanation:

In the idealized Otto cycle there are 4 process that are

  • Reversible adiabatic compression  
  • Addition of heat at constant volume
  • Reversible adiabatic expansion
  • Rejection of constant volume

So from above discussion we can see that heat is added when there is constant (minimum) volume which is given in option (b) so option (b) will be the correct answer

3 0
3 years ago
Other questions:
  • A spherical, stainless steel (k 16 W m1 K-1) tank has a wall thickness of 0.2 cm and an inside diameter of 10 cm. The inside sur
    12·1 answer
  • In which type of restaurant do customers order and pay before eating?
    5·1 answer
  • Define volume flow rate Q of air flowing in a duct of area A with average velocity V
    12·1 answer
  • Which phase of project development provides engineers with an opportunity to determine the gaps or problems of the project on pa
    14·1 answer
  • Layout the logical structure of the report.along with headings and subheadings
    5·1 answer
  • What are some goals of NYFEA? Select three options.
    9·2 answers
  • Does anyone know how to fixes rope lights? Half of the rope is not on<br><br>Someone.. Anyone..
    9·1 answer
  • Many vehicles have indicator lights telling you when your
    13·1 answer
  • A. State the functions of the followings
    9·1 answer
  • Blind spots around a large vehicle are _________________ than the blind spots around a car.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!