Project 1 of the second week-Skating Rink cost, and 1 of the second week-Skating Rink
There is a circular dry ice site, where cement is used in the site. The cost is M yuan per square meter, and the fence is surrounded by wood bars. The cost per meter is N yuan. Enter the roller rink radius, use a program to calculate the cost.
Level 1 prompt:
First, define the class to determine its data members and member functions. Here we want to define the roller skating rink. In reality, we only care about its area and perimeter. The cost of the cement in the field is calculated based on the area, and the cost of the fence is calculated based on the perimeter. With the class definition, you can define the class object in the main function and call the member function to complete the solution.
Level 2 prompt:
In fact, we only care about the ice rink as a circle. This means that the design captures the essence. Therefore, a Circle class is designed. The data member is the Circle radius. The Circle class also provides a member function for calculating the area and edge length of the Circle. In the main function, define an object of the Circle class and call the member function to find the cost of the roller rink.
/** Copyright (c) 2015, School of Computer Science, Yantai University * All right reserved. * Author: Shao Shuai * file: Demo. cpp * completion time: October 13, March 14, 2015 * version: v1.0 */# include <iostream> using namespace std; const int M = 20; // const int N = 35 for each square meter of cement site; // fence cost per meter class Circle {// declare the required member function below (from the provided main function, you can find out which member functions are needed) public: double area (); void setRadius (double r); double circumference (); private: double radius ;}; // The following defines the required member function void Circle: setRadius (double r) {radiu S = r;} double Circle: area () {return (3.14 * radius);} double Circle: circumference () {return (2*3.14 * radius);} int main () {double r; cout <"Enter the roller rink radius:"; cin> r; Circle c; c. setRadius (r); cout <"The cost of the roller rink is" <M * c. area () + N * c. circumference () <"Yuan. "<Endl; return 0 ;}
Running result:
At first, I forgot the Public declaration and kept error. Then I finally found out...
Remember that the default permission of the class is Private ~
@ Mayuko