#include #include #include "PhoneCall.h" using namespace std; PhoneCall::PhoneCall() { //default constructor number = " "; length = 0; rate = 0; } PhoneCall::PhoneCall(string new_number) { //overloaded constructor number = new_number; length = 0; rate = 0; } PhoneCall::~PhoneCall() { //destructor ; } string PhoneCall::get_number() const { return number; } int PhoneCall::get_length() const { return length; } float PhoneCall::get_rate() const { return rate; } float PhoneCall::calcCharge() { ///datermine cost of call return length * rate; } bool operator==(const PhoneCall& call1, const PhoneCall& call2) { return(call1.number == call2.number); } istream& operator >> (istream& ins, PhoneCall& the_call) { ins >> the_call.number >> the_call.length >> the_call.rate; return ins; } ostream& operator << (ostream& outs, const PhoneCall& the_call) { outs << the_call.number << endl << the_call.length << endl << the_call.rate; return outs; } #pragma once #ifndef PHONECALL_H #define PHONECALL_H #include #include #include #include using namespace std; class PhoneCall { public: //the difference between the overloaded friend functions for the stream extraction operator >> and the stream insertion //operation. The overloaded stream insertion operator << uses the const keyword to ensure that the object which is //sent to the output stream will not be modified. In the case of the overloaded stream extraction operator >>, //the object retrieved from the input stream, must change. The overloaded stream insertion operator << modifies the //output stream and the overloaded stream extraction operator >> modifies the input stream, therefore both the //ostream and the istream must be reference parameters friend istream& operator >> (istream& ins, PhoneCall& the_call); friend ostream& operator << (ostream& outs, const PhoneCall& the_call); //the const keyword is used to guaratee that this function will not modify the PhoneCall objects. //When we compared two PhoneCall objects with ==, we do not want to change or modify the objects we //compare. A friend function may manipulate the underlying structure of the class but the const //keyword ensures that these manipulations do not modify the object in any possible way friend bool operator == (const PhoneCall& call1, const PhoneCall& call2); PhoneCall(); //default constructor PhoneCall(string new_number); //overloaded constructor ~PhoneCall(); //destructor string get_number() const; //accessor int get_length() const; //accessor float get_rate() const; //accessor float calcCharge(); //calculate amount charged for this call private: string number; //member variables int length; float rate; }; #endif PHONECALL_H