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;
}
标签:obj,cout,int,float,return,打卡,Circle From: https://www.cnblogs.com/bdsz/p/17334802.html