Question
Convert problems in to template classes. Test each with Implicit int, float, double, long int. Test each with explicit int, float, double, long int. Please
Convert problems in to template classes.
Test each with Implicit int, float, double, long int.
Test each with explicit int, float, double, long int.
Please help me with this C++ problem
Q.
//Main.cpp
#include
#include "Circle.h"
using namespace std;
int main()
{
double radius = 0;
cout << "Enter radius of circle: ";
cin >> radius;
//declare Circle class
Circle c;
c.setRadius(radius);
cout << "Radius:" << c.getRadius()<< endl;
cout << "Circumference:" << c.calcCircumference() << endl;
cout << "Area:" << c.calcArea() << endl;
cout << "Diameter:" << c.calDiameter() << endl;
system("pause");
return 0;
}
---------------------------------------------------------
//Circle.cpp
#include
#include "Circle.h"
using namespace std;
//Default constructor
Circle::Circle()
{
radius=0;
}
//Parameterized constructor
Circle::Circle(double r)
{
radius=r;
}
//Setter methods
void Circle::setRadius ( double r )
{
radius=r;
}
//Getter method
double Circle::getRadius ( )
{
return radius;
}
double Circle::calcCircumference()
{
return 2 * 3.14 * radius;
}
double Circle::calcArea ()
{
return 3.14 * radius * radius;
}
double Circle::calDiameter()
{
return 2 * radius;
}
-------------------------------------
//Circle.h
#include
using namespace std;
class Circle
{
public:
double radius;
public:
//Default constructor
Circle();
//Parameterized constructor
Circle(double );
//Setter methods
void setRadius ( double n ) ;
//Setter methods
double getRadius () ;
//Methods to calculate area and volume of box
double calcCircumference() ;
double calcArea () ;
double calDiameter();
};
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started