c打卡补2

1.

class Circle

{

private:

    double r;

public:

    Circle(double r)

    {cout << "Constructor called" << endl;

        this->r = r;

    }

    Circle(Circle& c)

    {

        this->r = c.r;

        cout << "Copy constructor called" << endl;

    }

    double area()

    {

        return 3.14 * r * r;

    }

    double perimeter()

    {

        return 3.14 * r * 2;

    }

    ~Circle()

    {

        cout << "Destructor called" << endl;

    }

};

 

2.

bool prime( int p )

{

    int i;

 

    if(p<=1) return false;

    for(i=2; i<=sqrt(p); i++)

        if(p%i==0) return false;

    return true;

}

 

 

void Solution::solve()

{

    int a[30],i,j=0,b=n;

    if(prime(b)) cout<<b<<"="<<b<<endl;

    else

    {

        for(i=2; ; )

            if(prime(i) && b%i==0 )

            {

                a[j++]=i;

                b/=i;

                if(b==1) break;

            }

            else i++;

        cout<<n<<"=";

        for(i=0; i<j-1; i++) cout<<a[i]<<"*";

        cout<<a[i]<<endl;

    }

}

3.

#include <iostream>

 

using namespace std;

 

class Box

{

        private:

                 float X;

        public:

                 void seta(float x )

                 {

                         X=x;

                 }

                 float getvolume( )

                 {

                         return X*X*X;

                 }

                 float getarea( )

                 {

                         return 6*X*X;

                 }

                 void disp( )

                 {

                         cout<<X*X*X<<" "<<6*X*X<<endl;

                 }

                

};

int  main( ){

    float ab;

    cin>>ab;

    Box  obj;

    obj.seta( ab );

    obj.getvolume( );

    obj.getarea( );

    obj.disp( );

    return 0;

}

 

posted @   vvvcutee  阅读(11)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
点击右上角即可分享
微信分享提示