Guest User

Untitled

a guest
Oct 18th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. // Hello World.cpp : main project file.
  2.  
  3. #include "stdafx.h"
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. //Declare class and comments
  9.  
  10. class CRectangle {
  11. private:
  12. int h, w; //These are private by default.
  13.  
  14. public: //Everyone can see the below:
  15. void set_sides (int,int); //Declare the set_sides method within CRectangle
  16. int area () {return (h*w);} //This is an inline function or method
  17. int perimeter () {return ((2*h)+2*w);}
  18. bool squarecheck () {return h*w;}
  19. };
  20.  
  21. //Define the CRectangle::set_sides method
  22.  
  23. void CRectangle::set_sides (int a, int b) {
  24. h = a; //We can see h and w because we are part of the
  25. w = b; //CRectangle class. We have "scope".
  26. }
  27.  
  28. int main () {
  29. CRectangle rect; //Make a CRectangle object called rect
  30. rect.set_sides (-2,1); //Use one of its methods for input
  31. cout << "Entered Values: " << << "\n";
  32. cout << "Area: " << rect.area () << "\n"; //Use another method for output.
  33. cout << "Perimeter: " << rect.perimeter () << "\n";
  34. cout << "Is a square: ";
  35. if (rect.squarecheck ())
  36. {cout << "True \n";}
  37. else
  38. {cout << "False \n";}
  39. return 0;
  40. }
Add Comment
Please, Sign In to add comment