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
The input shaft to a gearbox rotates at 2300 rpm and transmits a power of 42.6 kW. The output shaft power is 34.84 kW at a rotat
Marrrta [24]

Answer:

Torque at input shaft will be 176.8695 N-m

Explanation:

We have given input power P_{IN}=42.6KW=42.6\times 10^3W

Angular speed = 2300 rpm

For converting rpm to rad/sec we have multiply with \frac{2\pi }{60}

So 2300rpm=\frac{2300\times 2\pi }{60}=240.855rad/sec

We have to find torque

We know that  power is given by P=\tau \omega, here \tau is torque and \omega is angular speed

So 42.6\times 10^3=\tau \times 240.855

\tau =176.8695N-m

So torque at input shaft will be 176.8695 N-m

4 0
4 years ago
A bar having a length of 5 in. and cross-sectional area of 0.7 i n . 2 is subjected to an axial force of 8000 lb. If the bar str
IRISSAK [1]

Answer:

E=1.969 × 10¹¹ Pa

Explanation:

The formula to apply is;

E=F*L/A*ΔL

where

E=Young modulus of elasticity

F=Force in newtons

L=Original length in meters,m

A=area in square meters m²

ΔL= Change in length in meters,m

Given

F= 8000 lb = 8000*4.448 =35584 N

L= 5 in = 0.127 m

A= 0.7 in² =0.0004516 m²

ΔL = 0.002 in = 5.08e-5 m

Applying the formula

E=(35584 * 0.127)/(0.0004516*5.08e-5 )

E=1.969 × 10¹¹ Pa

6 0
3 years ago
A car air-conditioning unit has a 0.5-kg aluminum storage cylinder that is sealed with a valve, and itcontains 2 L of refrigeran
kondaur [170]

Answer:

The irreversibilty of this process is that you can't undo this reaction that has already taken place inside of the car due to it being an irrevesible chemical reaction.

Explanation:

4 0
3 years ago
How would I get this python code to run correctly? it's not working.​
Elanso [62]

Answer:

See Explanation

Explanation:

This question requires more information because you didn't state what the program is expected to do.

Reading through the program, I can assume that you want to first print all movie titles then prompt the user for a number and then print the move title in that location.

So, the correction is as follows:

Rewrite the first line of the program i.e. movie_titles = ["The grinch......."]

for each_movie_titles in movie_titles:

   print(each_movie_titles)

   

usernum = int(input("Number between 0 and 9 [inclusive]: "))

if usernum<10 and usernum>=0:

   print(movie_titles[usernum])

Line by line explanation

This iterates through the movie_titles list

for each_movie_titles in movie_titles:

This prints each movie title

   print(each_movie_titles)

This prompts the user for a number between 0 and 9    

usernum = int(input("Number between 0 and 9 [inclusive]: "))

This checks for valid range

if usernum<10 and usernum>=0:

If number is valid, this prints the movie title in that location

   print(movie_titles[usernum])

6 0
4 years ago
Neon gas enters an insulated mixing chamber at 300 K, 1 bar with a mass flow rate of 1 kg/s. A second steam of carbon monoxide e
BaLLatris [955]

Answer:

a) the molar fraction of neon at the exit is

xₙ= 0.735

and carbon monoxide

xₓ = 0.265

b) the final temperature is

T =  410.55 K

c) the rate of entropy production is

ΔS = 1.83 KW/K

Explanation:

denoting n for neon and x for carbon monoxide:

a) from a mass balance, the molar fraction of neon at the exit is:

outflow mass neon=inflow mass neon

xₙ = outflow mass neon/ (total outflow of mass) = inflow mass neon/ (total outflow of mass) = (1 kg/seg / 20.18 kg/kmol) / (1 kg/seg / 20.18 kg/kmol + 0.5 kg/seg / 28.01 kg/kmol) = 0.735

and the one of carbon monoxide is

xₓ = 1-xₙ = 1-0.735 = 0.265

b) from the first law of thermodynamics applied to an open system, then

Q - Wo = ΔH + ΔK +  ΔV

where

Q= heat flow to the chamber = 0 ( insulated)

Wo= external work to the chamber = 0 ( there is no propeller to mix)

ΔH = variation of enthalpy

ΔK = variation of kinetic energy ≈ 0 ( the changes are small with respect to the one of enthalpy)

ΔV = variation of kinetic energy ≈ 0 ( the changes are small with respect to the one of enthalpy)

therefore

ΔH = 0 → H₂ - H₁ = 0 → H₂=H₁

if we assume ideal has behaviour of neon and carbon monoxide, then

H₁ = H ₙ₁ + H ₓ₁ = mₙ₁*cpₙ*Tn + mₓ₁*cpₓ*Tc

H₂ = (m ₙ+mₓ)*cp*T  

for an ideal gas mixture

cp = ∑ cpi xi

therefore

mₙ*cpₙ*Tₙ + mₓ*cpₓ*Tₙ₁ = (m ₙ+mₓ)*∑ cpi xi*T

mₙ/(m ₙ+mₓ)*cpₙ*Tₙ + mₓ/(m ₙ+mₓ)*cpₓ*Tₓ = T ∑ cpi xi

xₙ* cpₙ*Tₙ +xₓ*cpₓ*Tₓ = T*( xₙ* cpₙ+xₓ*cpₓ)

T= [xₙ* cpₙ/( xₙ* cpₙ+xₓ*cpₓ)]*Tₙ₁ +[xₓ*cpₓ/( xₙ* cpₙ+xₓ*cpₓ)]*Tₓ₁

denoting

rₙ = xₙ* cpₙ/( xₙ* cpₙ+xₓ*cpₓ)

and

rₓ= xₓ*cpₓ/( xₙ* cpₙ+xₓ*cpₓ)

T= rₙ *Tₙ +rₓ*Tₓ

for an neon , we can approximate its cv through the cv for an monoatomic ideal gas  

cvₙ= 3/2 R , R= ideal gas constant=8.314 J/mol K=

since also for an ideal gas: cpₙ - cvₙ = R → cpₙ = 5/2 R

for the carbon monoxide ,  we can approximate its cv through the cv for an diatomic ideal gas

cvₓ= 7/2 R → cpₓ = 9/2 R

replacing values

rₙ = xₙ* cpₙ/( xₙ* cpₙ+xₓ*cpₓ)  = xₙ₁*5/2 R/ ( xₙ₁*5/2 R+xₓ*9/2 R) =

xₙ₁*5/(xₙ₁*5 + xₓ*9) = 5xₙ₁/(5 + 4*xₓ) = 5*0.735/(5+ 4*0.265) =0.598

since

rₙ + rₓ =1  → rₓ = 1-rₙ = 1- 0.598 = 0.402

then

T =  rₙ *Tₙ +rₓ*Tₓ  = 0.598 * 300 K + 0.402 * 575 K = 410.55 K

c) since there is no entropy changes due to heat transfer , the only change in entropy is due to the mixing process

since for a pure gas mixing process

ΔS = n*Cp* ln T₂/T₁ -n*R ln (P₂/P₁)

but P₂=P₁ (P=pressure)

ΔS = n*Cp* ln T₂/T₁ = n*Cp*ln T₂ - n*Cp*ln T₁ = S₂-S₁

for a gas mixture as end product

ΔS = (nₓ+nₙ)*Cp*ln T - (nₓ*Cpₓ*ln Tₓ + nₙ*Cpₙ*ln Tₙ)

ΔS = nₙ*Cpₙ ( (nₓ+nₙ)*Cp/[nₙ*Cpₙ]* ln T - ( nₓ*Cpₓ/ (nₙ*Cpₙ) *ln Tₓ + ln Tₙ)

ΔS = nₙ*Cpₙ [ 1/rₙ * ln T -( (rₓ/rₙ)*ln Tₓ + ln Tₙ)]

replacing values ,

ΔS = nₙ*Cpₙ [ 1/rₙ * ln T -( (rₓ/rₙ)*ln Tₓ + ln Tₙ)] = (1 kg/s/ 20.18*10 kg/kmol)* 5/2* 8.314 kJ/kmol K *[ 1/0.598 * ln 410.55 K-( 0.402/0.598  *ln 575 K + ln 300K)]

= 1.83 KW/K

5 0
3 years ago
Other questions:
  • The pulley has mass 12.0 kg, outer radius Ro=250 mm, inner radius Ri=200 mm, and radius of gyration kO=231 mm. Cylinder A weighs
    14·1 answer
  • A transmission line with an imperfect dielectric is connected to an ideal time-invariant voltage generator. The other end of the
    9·1 answer
  •  Question 1. CVP exercises. The Doral Company manufactures and sells pens. Currently, 5,000,000 units are sold per year at $0.5
    8·1 answer
  • What is the density of a substance that has a mass of 14gm and has a volume of 42cm^3
    7·1 answer
  • Diana and Kinsey are put in charge of choosing a mascot for their basketball team. There are fifteen players on the team, but Di
    12·1 answer
  • The four important principles of flight are lift, drag, thrust, and _____.
    7·1 answer
  • What area would an industrial materials recycler avoid obtaining construction and demolition materials from?
    5·1 answer
  • Refrigerant 134a enters the evaporator of a refrigeration system operating at steady state at -16oC and a quality of 20% at a ve
    13·1 answer
  • While reflecting on the solutions and the process of concept generation, the development team takes a look at some critical ques
    10·1 answer
  • ) A certain polymer is used for evacuation systems for aircraft. It is important that the polymer be resistant to the aging proc
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!