Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Hello World.cpp : main project file.
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- //Declare class and comments
- class CRectangle {
- private:
- int h, w; //These are private by default.
- public: //Everyone can see the below:
- void set_sides (int,int); //Declare the set_sides method within CRectangle
- int area () {return (h*w);} //This is an inline function or method
- int perimeter () {return ((2*h)+2*w);}
- bool squarecheck () {return h*w;}
- };
- //Define the CRectangle::set_sides method
- void CRectangle::set_sides (int a, int b) {
- h = a; //We can see h and w because we are part of the
- w = b; //CRectangle class. We have "scope".
- }
- int main () {
- CRectangle rect; //Make a CRectangle object called rect
- rect.set_sides (-2,1); //Use one of its methods for input
- cout << "Entered Values: " << << "\n";
- cout << "Area: " << rect.area () << "\n"; //Use another method for output.
- cout << "Perimeter: " << rect.perimeter () << "\n";
- cout << "Is a square: ";
- if (rect.squarecheck ())
- {cout << "True \n";}
- else
- {cout << "False \n";}
- return 0;
- }
Add Comment
Please, Sign In to add comment