nearly similar rectangles hackerrank solution

Solutions on MaxInterview for nearly similar rectangles hackerrank solution by the best coders in the world

showing results for - "nearly similar rectangles hackerrank solution"
Sofie
21 Oct 2020
1#include <iostream>
2
3using namespace std;
4/*
5 * Create classes Rectangle and RectangleArea
6 */
7class Rectangle{
8    protected:
9        int width;
10        int height;
11
12    public:
13        virtual void display() const{
14            cout<< width <<' ' << height << endl;
15        }
16};
17class RectangleArea : public Rectangle {
18    public:
19        void display() const override {
20            cout << (width * height) << endl;
21        }
22        void read_input(){
23            cin >> width >> height;
24        }
25};
26
27int main()
28{
29    /*
30     * Declare a RectangleArea object
31     */
32    RectangleArea r_area;
33    
34    /*
35     * Read the width and height
36     */
37    r_area.read_input();
38    
39    /*
40     * Print the width and height
41     */
42    r_area.Rectangle::display();
43    
44    /*
45     * Print the area
46     */
47    r_area.display();
48    
49    return 0;
50}
Elisa
16 Apr 2017
1#include<bits/stdc++.h>
2#define ll long long
3using namespace std;
4ll combinations(ll n)
5{
6	ll count=1;
7	if(n<2)
8	return 0;	
9	else
10	{
11	   for(ll i=1;i<=2;i++)
12		{
13			count=count*n--;
14			count=count/i;
15		}
16	}
17	return count;
18}