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;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统