Implement a square class in C++. Each object of the class will represent a square
storing it’s side as float. Include a default constructor. Write a function area() to
calculate area of square and perimeter() to calculate the perimeter of square.
#include <stdio.h>
#include <iostream>
using namespace std;
class square{
protected:
float side;
public:
square(float s){
side = s;
}
void area(){
float a = side*side;
cout<<a<<endl;
}
void perimeter(){
float p = side*4;
cout<<p<<endl;
}
};
int main()
{
square s(10);
s.perimeter();
s.area();
return 0;
}
Comments
Leave a comment