Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please add //comments to the below code so I can a good understanding of the fun

ID: 3907409 • Letter: P

Question

Please add //comments to the below code so I can a good understanding of the functions. Thanks

Circle.ccp

#ifndef CIRCLE_H

#define CIRCLE_H

#include <iostream>

using namespace std;

class Circle

{

private:

double radius;

public:

Circle()

{

radius = 1;//default value

}

void input()

{

cout << "Enter radius: ";

cin >> radius;

}

void print()

{

double PI = 3.14159;

double area = PI * radius * radius;

double circumference = 2 * PI * radius;

cout << "Circle with radius = " << radius << ", area = " << area << ", circumference = " << circumference << endl;

}

};

#endif // CIRCLE_H

Circle.h

#ifndef CIRCLE_H_INCLUDED

#define CIRCLE_H_INCLUDED

#include <iostream>

using namespace std;

class Circle

{

private:

double radius;

public:

Circle()

{

radius = 1;//default value

}

void input()

{

cout << "Enter radius: ";

cin >> radius;

}

void print()

{

double PI = 3.14159;

double area = PI * radius * radius;

double circumference = 2 * PI * radius;

cout << "Circle with radius = " << radius << ", area = " << area << ", circumference = " << circumference << endl;

}

};

#endif // CIRCLE_H_INCLUDED

Square.ccp

#include "square.h"

Square::Square(double _a, double _b)

{

    a = _a;

    b = _b;

}

void Square::print() const

{

    std::cout << "First side: " << a << std::endl;

    std::cout << "Second side: " << b << std::endl;

    std::cout << "Area: " << area() << std::endl;

}

double Square::area() const

{

    return a*b;

}

void Square::input()

{

    std::cout << "Enter side 1: "; std::cin >> a;

    std::cout << "Enter side 2: "; std::cin >> b;

}

Square.h

#endif // SQUARE_H_INCLUDED

#ifndef SQUARE_H_INCLUDED

#define SQUARE_H_INCLUDED

#include <iostream>

class Square

{

private:

    double a;

    double b;

public:

    Square(double _a = 0.0, double _b = 0.0);

    void    print() const;

    double area() const;

    void    input();

};

#endif // SQUARE_H_INCLUDED

Explanation / Answer

Circle.cpp

#include "Circle.h" // include header file

#include <iostream>

using namespace std;

class Circle // Circle class definition

{

private: // private data variable

double radius;

public: // define all methods declared in header file

Circle() // default constructor

{

radius = 1;//default value

}

void input() // function to input the value of radius

{

cout << "Enter radius: ";

cin >> radius;

}

void print() // function to print the radius,area and circumference of circle

{

double PI = 3.14159;

double area = PI * radius * radius; // area of circle

double circumference = 2 * PI * radius; // circumference of circle

cout << "Circle with radius = " << radius << ", area = " << area << ", circumference = " << circumference << endl;

}

};

Circle.h

#ifndef CIRCLE_H_INCLUDED

#define CIRCLE_H_INCLUDED

#include <iostream>

using namespace std;

class Circle

{

private:

double radius;

public: // declaration of public methods in header file

Circle();

void input();

void print();

};

#endif // end of header file CIRCLE_H_INCLUDED

Square.cpp

#include "square.h"

Square::Square(double _a) // square only needs side , all sides are equal in square, constructor needs 1 argument

{

    a = _a;

}

void Square::print() const // definition of print() method in cpp file ,declaration done in header file

{

    std::cout << "side: " << a << std::endl;

    std::cout << "Area: " << area() << std::endl; // area() method is called

}

double Square::area() const    // definition of area() method of Square class

{

    return a*a;    // area of square = side*side

}

void Square::input() // method definition for input()

{

    std::cout << "Enter side : "; std::cin >> a;

}

Square.h

#ifndef SQUARE_H_INCLUDED

#define SQUARE_H_INCLUDED

#include <iostream>

class Square

{

private:

    double a; // private data, side of square

public:    // declaration of functions in header file

    Square(double _a = 0.0); // constructor with default arguments 0.0

    void    print() const;

    double area() const;

    void    input();

};

#endif // end of SQUARE_H_INCLUDED

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote