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

Plz write this in c++ code Write a program that contains a class called Phonecal

ID: 3803301 • Letter: P

Question

Plz write this in c++ code Write a program that contains a class called Phonecall. The data that the class contains in the number called, the length of the call in minutes, and the rate per minute. Overload the == operator to compare two phone numbers to see if they are the same. Create an array of 5 phone calls. If a phone call has already been placed to a number do not allow a second phone call to be placed. Be sure to include all of the necessary member functions to access and display the phone numbers. Also display a list of the data and the total charge for each call placed. Save the file as phonecall.cpp and upload it to Midterm in Moodle.

Explanation / Answer

PROGRAM CODE:

#include <iostream>
using namespace std;

class Phonecall
{
public:
   long numberCalled;
   int lengthOfCall;
   double ratePerMinute;
  
   Phonecall(long number, int len, double rate)
   {
       numberCalled = number;
       lengthOfCall = len;
       ratePerMinute = rate;
   }
  
   long getNumberCalled()
   {
       return numberCalled;
   }
   int getLengthOfCall()
   {
       return lengthOfCall;
   }
   double getratePerMinute()
   {
       return ratePerMinute;
   }
   void setNumberCalled(long number)
   {
       numberCalled = number;
   }
   void setLengthOfCall(int minutes)
   {
       lengthOfCall = minutes;
   }
   void setRatePerMinute(double rate)
   {
       ratePerMinute = rate;
   }
   bool operator==(Phonecall &phn) const
   {
       if(this->numberCalled == phn.numberCalled)
       {
           return true;
       }
       return false;
   }
   void print()
   {
       cout<<"Number Called: "<<numberCalled<<" Length: "<<lengthOfCall;
       cout<<" Rate: "<<ratePerMinute<<endl<<endl;
   }
};
int main() {
   int len = 5;
   double totalRate = 0;
   Phonecall *phonecalls[len];
   phonecalls[0] = new Phonecall(87632489, 23, 12.0);
   phonecalls[1] = new Phonecall(43567773, 12, 9.0);
   phonecalls[2] = new Phonecall(65423422, 12, 1.1);
   phonecalls[3] = new Phonecall(35858589, 32, 32.3);
   phonecalls[4] = new Phonecall(35858589, 65, 2.1);

   if(*phonecalls[3] == *phonecalls[4])
   {
       phonecalls[4] = NULL;
       len--;
   }
   for(int i=0; i<len; i++)
   {
       phonecalls[i]->print();
       totalRate += (phonecalls[i]->getLengthOfCall() * phonecalls[i]->getratePerMinute());
   }
   cout<<fixed<<"Total Cost: "<<totalRate;
   return 0;
}

OUTPUT:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote