Haval1

passing object in function

Jan 18th, 2019
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. // sol-final-ex1.cpp : Defines the entry point for the console application.
  2.  
  3.  
  4. #include "stdafx.h"
  5. #include "iostream"
  6. using namespace std;
  7. class omar {
  8. private:
  9.     int area, population;
  10. public:
  11.     omar() {
  12.     }
  13.     omar(int a, int p) {
  14.         area = a;
  15.         population = p;
  16.     }
  17.     void display(){
  18.         cout << "area : " << area << "\npopulation : " << population << endl;
  19.     }
  20.     int get_area() {
  21.         return area;
  22.     }
  23.     int get_pop() {
  24.         return population;
  25.     }
  26. };
  27. omar addcity(omar city1, omar city2) {
  28.     int area,population;
  29.     area = city1.get_area();
  30.     population = city2.get_pop();
  31.     omar temp(area, population);
  32.     return temp;
  33. }
  34. int main()
  35. {
  36.     omar city1(200, 1000), city2(400, 3000),city3;
  37.     city1.display();
  38.     cout << "\n=======\n";
  39.     city2.display();
  40.     // city3 = area from city1 and population from city2
  41.     city3 = addcity(city1, city2);
  42.     city3.display();
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment