Question: Need help with these issues: In an object-oriented program, non-constant data members should always be private. In a few cases where inheritance is involved, a

Need help with these issues: In an object-oriented program, non-constant data members should always be private. In a few cases where inheritance is involved, a data member may need to be protected, but this is relatively rate and private is always preferred. Since there is no inheritance in this version of the shape area program, you should not use protected. While not specifically required, the classes in this program would be improved by including parameterized constructors.

//main.cpp #include //Need this header file to support the C++ I/O system

#include "circle.h"// including the header and implementation files #include "square.h" #include "circle.cpp" #include "square.cpp"

using namespace std;//Telling the compiler to use name space where C++ library is declared

int main()

{ int radius,length;//declare variables for circumference of the circle and length of square Circle circle;//default values used to display radius value circle.Display();//radius value for the circle Circle circ; cout << "Enter the radius value :" << endl;//user to enter value cin >> radius; circ.setRadius(radius); circ.Display();

Square square;//display the square square.Display(); Square squ;//get value for length cout << "Enter the length value :" << endl;//user to enter value cin >> length; squ.setLength(length);//base class squ.Display(); return 0; }

//circle.cpp #include //need this header file to support the C++ I/O system #include "circle.h"// include the header file

using namespace std;//telling the compiler to use names pace where C++ library is declared

const double PI = 3.14159;//declare, define and initialize global values Circle::Circle()// declare circle method { Radius = 0;//value of the radius initialized } void Circle::setRadius(double r) { Radius = r <= 0 ? 1 : r;//verify the input value } double Circle::getRadius() { return Radius;//retrieve and store value } double Circle::Area() { return Radius * Radius * PI;//return value of the area } void Circle::Display() { cout << " Circle Properties";// display the data cout << " Radius = " << getRadius(); cout << " Area = " << Area() << " "; }

//circle.h #ifndef CIRCLE_H #define CIRCLE_H

// circle structure class struct Circle { //declare circle access specifier public: Circle(); //set radius value void setRadius(double r); //retrieve radius value double getRadius(); //calculate area double Area(); //display data void Display(); //declare value for the radius access specifiers protected: double Radius; //access specifier private: };

#endif

//square.cpp

#include //need this header file to support the C++ I/O system #include "square.h"// including the header file

using namespace std;//telling the compiler to use name space where C++ library is declared

Square::Square()//declare method used for square shape { Length = 0;//initialize length value } void Square::setLength(double l) { Length = l <= 0 ? 1 : l;//verify data } double Square::getLength() { return Length;//returning length } double Square::Area() { return Length*Length;// returning the area } void Square::Display(){ cout << " Square Properties";// display output cout << " Length = " << getLength(); cout << " Area = " << Area() << " "; }

//square.h

#ifndef SQUARE_H #define SQUARE_H

// square structure class struct Square { //declare square access specifier public : Square(); //set length void setLength(double l); //retrieve length double getLength(); //retrieve area double Area(); //display data void Display(); // length value declaration access specifier protected : double Length; //access specifiers private: };

#endif

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!