CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "square.h"
#include <iostream>
using namespace std;
float length; //declaring variable length of the float type
float square::getLength() { //getLength() function of the square type returns variable length (of float type)
return length;
}
void square::setLength(float l) { //setLength function of the square type takes one parameter, variable l of the float type
length = l; //assigning value 'l' to length
}
square::square(){ //initializing length to '0' in the square() member function
length = 0;
}
square::square(float l) { //square() takes one parameter, variable 'l' of the float type and assigns that value to 'length'
length = l;
}
float square::getArea() { //function getArea() of the square type returns expression length*length
return length * length;
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run