#include <string>
#include <iostream>
using namespace std;
class PhoneCall {
private:
string number;
// In minutes
int callLength;
// Per minute
double rate;
public:
bool operator==(const PhoneCall &r) {
return this->number == r.number;
}
friend istream& operator>> (istream& in, PhoneCall & phoneCall);
friend ostream& operator<< (ostream& out, const PhoneCall &phoneCall);
};
istream& operator>> (istream& in, PhoneCall & phoneCall) {
in >> phoneCall.number >> phoneCall.callLength >> phoneCall.rate;
return in;
}
ostream& operator<< (ostream& out, const PhoneCall &phoneCall) {
out << "Phone call: \n";
out << "Number: " << phoneCall.number << endl;
out << "Time(minutes): " << phoneCall.callLength << endl;
out << "Rate(per minute): " << phoneCall.rate << endl;
return out;
}
int main() {
const int arrSize = 10;
PhoneCall calls[arrSize];
cout << "Enter " << arrSize << " phone calls(format: number length rate): \n";
for (int i = 0; i < 10; ++i) {
cin >> calls[i];
// Check if there is a call to such number
bool isCall = false;
for (int j = i - 1; j >= 0; --j) {
if (calls[i] == calls[j]) {
isCall = true;
break;
}
}
if (isCall) {
cout << "Call to this number already exists. Try once more.\n";
--i;
}
}
return 0;
}
Comments
Leave a comment