📄 pex3_3.cpp
字号:
#include <iostream.h>
const float PI = 3.14159265;
// declare Circle class with data and method declarations
class Circle
{
private:
// data member radius is a floating point number
float radius;
public:
// constructor
Circle(float r);
// measurement functions
float Circumference(void) const;
float Area(void) const;
float SectorArea(float theta) const;
};
// class implementation
// constructor initializes the radius data member
Circle::Circle(float r): radius(r)
{ }
// return circumference
float Circle::Circumference() const
{
return 2 * PI * radius;
}
// return area
float Circle::Area() const
{
return PI * radius * radius;
}
// return area
float Circle::SectorArea(float theta) const
{
return (theta/360) * PI * radius * radius;
}
void main ()
{
float radius, numberRolls;
float fenceCost, lawnCost, lawnArea;
// set fixed point output with 2 decimal places
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
// prompt for and input radius
cout << "Enter the radius of the playground: ";
cin >> radius;
// declare the Circle objects
Circle playground(radius);
// Compute the cost of the Fence and output its value
fenceCost = playground.Circumference() * 2.40;
cout << "Fencing Cost is $" << fenceCost << endl;
lawnArea = playground.Area() - playground.SectorArea(30);
numberRolls = lawnArea / 16;
lawnCost = numberRolls * 4.00;
cout << "Lawn Cost is $" << lawnCost << endl;
}
/*
<Run>
Enter the radius of the playground: 100
Fencing Cost is $1507.96
Lawn Cost is $7199.48
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -