• 现场编码题目3


    现场编码题目3

    有一个蓝色圆形游泳池,中间有两个黄色圆形岛,也就是说,下方图中有3个圆形图像,圆形半径分别为:最大的外圆半径为outR,岛1半径为inR1,岛2半径为inR2。求游泳池水域的面积。算法规则规定:必须采用面向对象技术,解决这个问题。

     参考代码 C#版:

    using System;
    
    namespace Case3
    {
        class Circle
        {
            private int radius;
            public Circle(int r)
            {
                radius = r;
            }
            public double GetArea()
            {
                return 3.14 * radius * radius;
            }
        }
    
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("Outer Circle Radius:");
                int outR=int.Parse(Console.ReadLine());
                Console.WriteLine("Inner Circle One Radius:");
                int inR1 = int.Parse(Console.ReadLine());
                Console.WriteLine("Inner Circle two Radius:");
                int  inR2 = int.Parse(Console.ReadLine());
    
                Circle outCircle = new Circle(outR);
                Circle inCircle1 = new Circle(inR1);
                Circle inCircle2 = new Circle(inR2);
    
                double actualArea = outCircle.GetArea() - inCircle1.GetArea() - inCircle2.GetArea();
                Console.WriteLine("Swimming Pool Actual Area:{0}", actualArea);        
            }
        }
    }

    参考代码 C++:

    #include <iostream>
    #include<algorithm>
    using namespace std;
    
    class Circle
    {
    public:
        Circle(int r);
        double GetArea();
    private:
        int radius;
    };
    
    Circle::Circle(int r) 
    {
        radius = r;
    }
    double Circle::GetArea()
    {
        return 3.14 * radius * radius;
    }
    
    int main()
    {
        float  outR, inR1, inR2;
        cout << "Outer Circle Radius:"<<endl;
        cin >> outR;
        cout << "Inner Circle One Radius:"<<endl;
        cin >> inR1;
        cout << "Inner Circle two Radius:"<<endl;
        cin >> inR2;
        Circle outCircle = Circle(outR);
        Circle inCircle1 = Circle(inR1);
        Circle inCircle2 = Circle(inR2);
        double actualArea = outCircle.GetArea() - inCircle1.GetArea() - inCircle2.GetArea();
        cout << "Swimming Pool Actual Area :" << actualArea << endl;
    
    }

    参考代码 Python版:

    class Cirlce:
        def __init__(self,r):
            self.r=r
    
        def GetArea(self):
            return self.r*self.r*3.14
    
    
    outR=int(input("Outer Circle Radius:"))
    inR1=int(input("Inner Circle one Radius:"))
    inR2=int(input("Inner Circle two Radius:"))
    
    outCircle=Cirlce(outR)
    inCircle1=Cirlce(inR1)
    inCircle2=Cirlce(inR2)
    
    actualArea=outCircle.GetArea()-inCircle1.GetArea()-inCircle2.GetArea()
    print("Swimming Pool Actual Area:",actualArea)    
  • 相关阅读:
    python中将集合进行切割的方法
    Tomcat单库多实例部署
    (二) storm的基本使用
    工作流表结构解析
    [TCO 2012 Round 3A Level3] CowsMooing (数论,中国剩余定理,同余方程)
    [HEOI 2013 day2] 钙铁锌硒维生素 (线性代数,二分图匹配)
    [HEOI 2013 day2] SAO (树形动态规划)
    关于react和Angular的思考
    angular 中的modal
    从易到难,写一个JavaScript加载器之一
  • 原文地址:https://www.cnblogs.com/exesoft/p/16507075.html
Copyright © 2020-2023  润新知