Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For our week 2 assignment create a C++ program using Visual Studio where you des

ID: 3728477 • Letter: F

Question

For our week 2 assignment create a C++ program using Visual Studio where you design a “PhoneCall” class that holds a phone number to which a call is placed, the length of the call in minutes, and the rate charged per minute. Overload the extraction and insertion operators for the class; these are shown in the Chapter 9 ppt as ostream and istream, i.e. cout and cin. In this program, overload the == operator to compare two PhoneCall objects. Consider one PhoneCall object to be equal to another if both calls are placed to the same phone number. Also, create a main() function that allows you to enter ten PhoneCall objects into an array. If a PhoneCall has already been placed to a number, do not allow a second PhoneCall to the same number.

Compile this application using Visual Studio and run it to make sure it is error free.

Please copy and paste ALL (use Control-A, control-C, control-V) of your C++ code to a Word file. I will copy, paste, read and test your code for grading.

This is for C++

Explanation / Answer


// PhoneCall.cpp : Defines the entry point for the console application.
//
// #include "stdafx.h"
#include <iostream>
#include <string>
#define MAX_SIZE 3
using namespace std;
class PhoneCall
{
public:
PhoneCall();
PhoneCall(string phoneNumber, long lengthOfCall, double rateOfCall);
~PhoneCall();
void setPhoneNumber(string phoneNumber);
void setLengthOfCall(long lenghtOfCall);
void setRateOfCall(double rateOfCall);
string getPhoneNumber();
long getLengthOfCall();
double getRateOfCall();
friend ostream & operator << (ostream &out, const PhoneCall &pc);
friend istream & operator >> (istream &in, PhoneCall &pc);
bool operator==(const PhoneCall &pc);
private:
string phoneNumber;
long lengthOfCall; // in minute
double rateOfCall; // per minute
};
PhoneCall::PhoneCall()
{
phoneNumber = "";
lengthOfCall = 0;
rateOfCall = 0.0;
}
PhoneCall::PhoneCall(string phoneNumber, long lengthOfCall, double rateOfCall) {
setPhoneNumber(phoneNumber);
setLengthOfCall(lengthOfCall);
setRateOfCall(rateOfCall);
}
PhoneCall::~PhoneCall()
{
}
void PhoneCall::setPhoneNumber(string phoneNumber) {
this->phoneNumber = phoneNumber;
}
string PhoneCall::getPhoneNumber()
{
return phoneNumber;
}
long PhoneCall::getLengthOfCall()
{
return lengthOfCall;
}
double PhoneCall::getRateOfCall()
{
return rateOfCall;
}
bool PhoneCall::operator==(const PhoneCall &pc)
{
return this->phoneNumber == pc.phoneNumber;
}
void PhoneCall::setLengthOfCall(long lengthOfCall) {
this->lengthOfCall = lengthOfCall;
}
void PhoneCall::setRateOfCall(double rateOfCall) {
this->rateOfCall = rateOfCall;
}
ostream & operator<<(ostream & out, const PhoneCall & pc)
{
out << "{PhoneNumber: " << pc.phoneNumber << ", LengthOfCall: " << pc.lengthOfCall << ", RateOfCall: " << pc.rateOfCall << "}";
return out;
}
istream & operator>>(istream & in, PhoneCall & pc)
{
in >> pc.phoneNumber >> pc.lengthOfCall >> pc.rateOfCall;
return in;
}
int main()
{
PhoneCall phoneCalls[MAX_SIZE];
cout << "Enter the " << MAX_SIZE << " Phone Calls:" << endl;
for (int i = 0; i < MAX_SIZE; i++) {
cin >> phoneCalls[i];
bool isPlaced = false;
for (int j = i - 1; j >= 0 && !isPlaced; j--) {
if (phoneCalls[i] == phoneCalls[j]) {
isPlaced = true;
}
}
if (isPlaced) {
cout << "Entered Phone Call is already been placed to this number, Please try different Phone Call" << endl;
i--;
}
}
// display the phone calls
for (int i = 0; i < MAX_SIZE; i++) {
cout << phoneCalls[i] << endl;
}
return 0;
}