Overloading operators in PhoneCall class I am trying to understand the concepts of friend functions, overloaded operators, and inheritance in C++. I am very confused on the specifics used for coding, since I am fairly new in programming, and working in the Visual Studio C++ environment in writing code. 

The following is the project details for writing a program in Visual Studio C++: 


  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 extraction and insertion operators for the class. In
  this program, overload the == operator to compare two PhoneCalls.
  Consider one PhoneCall to be equal to another if both calls are
  placed to the same number. Also, create a main() function that allows
  you to enter ten PhoneCalls into an array. If a PhoneCall has
  already been placed to a number, do not allow a second PhoneCall to
  the same number.


I really need some feedback on the following code:

#include &lt;iostream&gt; 
#include &lt;string&gt; 

using namespace std; 

class PhoneCall { 
private: 
    string phonenumber; 
    double perminuterate; 
    double calldurationminutes; 
public: 
    bool operator==( const PhoneCall &amp;n ) const; 
    friend ostream &amp; operator&lt;&lt;( ostream &amp;f, const PhoneCall &amp;n ); 
    friend istream &amp; operator&gt;&gt;( istream &amp;f, PhoneCall &amp;n ); 
 }; 
 bool PhoneCall::operator==( const PhoneCall &amp;n ) const { 
    return phonenumber == n.phonenumber; 
 }; 
 ostream &amp; operator&lt;&lt;( ostream &amp;f, const PhoneCall &amp;n ) { 
    f &lt;&lt; "Phone number: " &lt;&lt; n.phonenumber &lt;&lt; 
         ", Duration: " &lt;&lt; n.calldurationminutes &lt;&lt; 
         " minutes, Rate: " &lt;&lt; n.perminuterate &lt;&lt; endl; 
 return f; 
 } 
 istream &amp; operator&gt;&gt;( istream &amp;f, PhoneCall &amp;n ) { 
 f &gt;&gt; n.phonenumber; 
 f &gt;&gt; n.calldurationminutes; 
 f &gt;&gt; n.perminuterate; 
 return f; 
 } 

int main( ) { 
 PhoneCall a[10]; 
 cout &lt;&lt; "Enter 10 phone numbers, duration in minutes, and the per-minute rates." &lt;&lt; 
     endl &lt;&lt; "Separate each with a space and then hit enter to complete it." &lt;&lt; endl; 
 for ( int i= 0; i &lt; 10; ) { 
     cin &gt;&gt; a[i]; 
     int j; 
     for ( j= 0; j &lt; i; ++j ) 
         if ( a[i] == a[j] ) { 
             cout &lt;&lt; "Duplicate number information ignored. Try again." &lt;&lt; endl; 
             break; 
         } 
     if ( j == i ) ++i; 
 } 
 for ( int i= 0; i &lt; 10; ++i ) 
     cout &lt;&lt; a[i];

 system("pause");
 return 0; 
 }
using namespace std; 


This is generally frowned upon, especially at the "global" level like this. Since you don't know what names might be defined inside namespace std, this has the potential to create conflicts with your code.

class PhoneCall { 
private: 


Although it's harmless, the private: here is redundant--members of a class are private by default.

    string phonenumber; 
    double perminuterate; 
    double calldurationminutes; 


I think I'd rename these to something like:

string phone_number;
double per_minute_rate;
double call_duration_minutes;


If at all possible, I'd use an std::vector instead of a "raw" array, so this:

 PhoneCall a[10]; 


...would turn into something like:

std::vector&lt;PhoneCall&gt; a(10);


std::endl is drastically overused. I'd generally just use '\n';. endl also flushes the file's buffer, which you rarely want. When you read/write cin and cout, flushes are done automatically between writing and reading anyway.

 cout &lt;&lt; "Enter 10 phone numbers, duration in minutes, and the per-minute rates." &lt;&lt; 
     endl &lt;&lt; "Separate each with a space and then hit enter to complete it." &lt;&lt; endl; 
 for ( int i= 0; i &lt; 10; ) { 
     cin &gt;&gt; a[i]; 
     int j; 
     for ( j= 0; j &lt; i; ++j ) 
         if ( a[i] == a[j] ) { 
             cout &lt;&lt; "Duplicate number information ignored. Try again." &lt;&lt; endl; 
             break; 
         } 
     if ( j == i ) ++i; 
 } 


You might want to use std::find to find whether the array already contains an instance of a particular phone number. This could simplify your logic quite a bit.

When you print out your phone call objects:

 for ( int i= 0; i &lt; 10; ++i ) 
     cout &lt;&lt; a[i];


...you traditionally want to only print out the data itself in your operator&lt;&lt;, and leave any final new-line to separate one object from the next to be printed somewhere else (like right here).

 system("pause");


I'd avoid this, and use something like:

std::cout &lt;&lt; "Press return to quit."
char ch;
std::cin.get(ch);