bsc

Comprehensive codebase and cou...
Log | Files | Refs | Activity | README | LICENSE

root / semester_2 / eduincs / pgrm_022.cpp

pgrm_022.cpp (825B)


      1 /* overloading of extraction operator and insertion operator */
      2 
      3 #include <iostream>
      4 using namespace std;
      5 
      6 class Height {
      7 private:
      8     int feet, inches;
      9 
     10 public:
     11     Height(int f = 0, int i = 0) {
     12         feet = f; inches = i;
     13     }
     14 
     15     friend ostream /* output stream */  &operator << (ostream &output, const Height &D) {
     16         output << D.feet << " ft " << D.inches << " inch";
     17         return output;
     18     }
     19 
     20     friend istream /* input stream */ &operator >> (istream &input, Height &D) {
     21         input >> D.feet >> D.inches;
     22         return input;
     23     }
     24 };
     25 
     26 int main() {
     27     Height D1(5, 10), D2(5, 11), D3;
     28     cout << "First height: " << D1 << endl; 
     29     cout << "Second height: " << D2 << endl; 
     30     cout << "Enter third height: " << endl;
     31     cin >> D3; 
     32     cout << "Third height: " << D3 << endl; 
     33     return 0;
     34 }
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror