首页 > 其他分享 >打卡

打卡

时间:2023-04-28 22:55:42浏览次数:41  
标签:PI float Cir 打卡 include called Dot

编写代码实现一个表示点的父类Dot和一个表示圆的子类Cir,求圆的面积。

Dot类有两个private数据成员 float x,y;

Cir类新增一个private的数据成员半径float r 和一个public的求面积的函数getArea( );

主函数已经给出,请编写Dot和Cir类。

#include <iostream>
#include<iomanip>
using namespace std;
const double PI=3.14;
//请编写你的代码
int main(){
    float x,y,r;
    cin>>x>>y>>r;
    Cir c(x,y,r);
    cout<<fixed<<setprecision(2)<<c.getArea()<<endl;
    return 0;
}

 

输入格式:

输入圆心和半径,x y r中间用空格分隔。

输出格式:

输出圆的面积,小数点后保留2位有效数字,注意:const double PI=3.14,面积=PI*r*r

输入样例:

在这里给出一组输入。例如圆的中心点为原点(0,0),半径为3:

0 0 4
 

输出样例:

在这里给出相应的输出。例如:

Dot constructor called
Cir constructor called
50.24
Cir destructor called
Dot destructor called
#include <iostream>
#include<iomanip>
using namespace std;
const double PI=3.14;
class Dot{
    public:
        Dot(float q, float w){
            a = q;
            b = w;
            cout << "Dot constructor called" <<endl;
        }
        ~Dot(){
            cout << "Dot destructor called"<< endl;
        }
    private:
        float a, b;
};
class Cir:public Dot{
    public:
        Cir(float a, float b, float e):Dot(a,b){
            
            r = e;
            cout << "Cir constructor called" << endl;
        }
        float getArea(){
            return PI * r * r;
        }
        ~Cir(){
            cout << "Cir destructor called"<<endl;
        }
        private:
        float r;
        
};

int main(){
    float x,y,r;
    cin>>x>>y>>r;
    Cir c(x,y,r);
    cout<<fixed<<setprecision(2)<<c.getArea()<<endl;
    return 0;
}

 

标签:PI,float,Cir,打卡,include,called,Dot
From: https://www.cnblogs.com/kongxiangzeng/p/17363344.html

相关文章

  • 打卡6
    代码验证#include<iostream>usingnamespacestd;template<classT>Tsum(T*array,intsize=0){ Ttotal=0; for(inti=0;i<size;i++) total+=array[i]; returntotal;}template<classT1,classT2>T2sum(T1*array1,T2*......
  • 4.28打卡
    #include<iostream>#include<iomanip>#include<cmath>usingnamespacestd;intfun2(intm){returnm*m;}intfun1(intx,inty){returnfun2(x)+fun2(y);}intmain(){inta,b;cout<<"pleaseentertwointeger......
  • 打卡15
    3.2亲密数 思路很简单,先遍历1-3000,把因子算一下,加一下,然后再算和的质因数和,看是否相等即可,时间复杂度不是很高 流程也很简单#include<bits/stdc++.h>usingnamespacestd;intf(intx)//求一个数的因子和{ intsum=0; for(inti=1;i<=x/2;i++) { if(x%i==0)sum+=i; } re......
  • c++打卡练习(19)
    1.问题描述相传国际象棋是古印度舍罕王的宰相达依尔发明的。舍罕王十分喜爱象棋,决定让宰相自己选择何种赏赐。这位聪明的宰相指着8x8共64格的象棋棋盘说:陛下,请您赏给我一些麦子吧。就在棋盘的第1格中放1粒,第2格放2粒,第3格放4粒,以后每一格都比前一格增加一倍,依此放完棋盘上64格,我......
  • 打卡 C++类与对象定义一个日期类 N天以后 - C/C++ 操作符重载
    改造练习13-1(日复一日)中的Date类并提交,使其可以与一个整数n相加或相减,得到该日期N天后/前的日期。提示:请参考题目(日复一日)中的Date类实现;注意考虑闰月;整数n的取值范围为[1,10000]。裁判测试程序样例: #include<iostream>#include<string>#include<assert.h>usingn......
  • 第十二天打卡
    问题: 算法设计:根据问题可以计算出每个颜色球的取值范围红球为M<3,白球为N<3,黑球为8-M-N<6流程图: 源代码:#include<stdio.h>intmain(){ intm,n,number=0; for(m=0;m<=3;m++) for(n=0;n<=3;n++) if(8-m-n<=6) printf("%2d:%d%d%d\n",++number,m,n,8-m-n); return0;......
  • 第十一天打卡
    一、问题描述编写一个计算个人所得税的程序,要求输入收入金额后,能够输出应缴的个人所得税。二、设计思路1.利用结构体记录不同起始征税点、结束点和税率;2.利用函数计算各个阶段的税;3.输出结果。三、四、代码实现 ......
  • 打卡10
    位反序数设N是一个四位数,它的9倍恰好是其反序数,求N。反序数就是将整数的数字倒过来形成的整数。例如:1234的反序数是4321。#include<stdio.h>intmain(){ inti; for(i=1002;i<1111;i++)/*穷举四位数可能的值*/ if(i%10*1000+i/10%10*100+i/100%10*10+i/1000==i*9)/*判断反序数......
  • 打卡11
    一辆以固定速度行驶的汽车,司机在上午10点看到里程表上的读数是一个对称数(即这个数从左向右读和从右向左读是完全一样的),为95859。两小时后里程表上出现了一个新的对称数。问该车的速度是多少?新的对称数是多少?#include<stdio.h>intmain(){ intt,a[5];/*数组a存放分解的数字位*......
  • 每日打卡-15
    一.问题描述该铁路经过N个城市,每个城市都有一个站。不过,由于各个城市之间不能协调好,于是乘车每经过两个相邻的城市之间(方向不限),必须单独购买这一小段的车票。第i段铁路连接了城市i和城市i+1(1<=i<N)。如果搭乘的比较远,需要购买多张车票。第i段铁路购买纸质单程票需要Ai博艾元。虽......