Answer to Question #209616 in C++ for Mahesh

Question #209616

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.


1
Expert's answer
2021-06-22T17:21:28-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS