标签:add for info include AC bubuko mes amp http
1.
//Complex.h
class Complex{
public:
Complex(float X,FLOAT Y):x(X),y(Y){}
Complex(float X):x(X){}
void add(Complex &c);
void show();
private:
float x,y;
};
//Complex.cpp
using namespace std;
void Complex::add(Complex &c){
x+=c.x;
y+=c.y;
}
void Complex::show(){
cout<<x<<"+"<<y<<"i"<<endl;
}
int main(int argc,char**argv){
Complex c1(3,5);
Complex c2=4.5;
c1.add(c2);
c1.show();
return 0;
}
2.类的定义
//Graph.h
class Graph{
public:
Graph(char CH,int N):ch(CH),n(N){}//构造函数
void draw()://绘制函数
private:
char ch;
int n;
}
类的实现
//Graph.cpp
using namespace std;
void Graph::draw(){
for(int y=1;y<=n;y++)//行
{
for(int i=y;i<=n,++i)//空格数
{
if(i!=n)
cout<<" ";
if(i==n)
{
for(int x=1,x<=2*y-1,++x)//符号个数
cout<<ch;
}
}
cout<<endl;
}
}
int main(int argc,char**argv){
Fraph graph1(‘*‘,5);
graph1.draw();
Graph graph2(‘s‘,7);
graph2.draw();
return 0;
}
3
using namespace std;
class Fraction{
public:
Fraction(int t=0,int b=1);
void show();
private:
int top,bot;
}
Fraction::Traction(int t,int b);top(t),bot(b){}
void Fraction::show(){
cout<<top<<"/"<<bot<<endl;
}
int main(){
Fraction a;
a,show();
Fraction b(3,4);
b.show();
Fraction c(5);
c.show();
return 0;
}
标签:add for info include AC bubuko mes amp http
原文地址:https://www.cnblogs.com/705397046see/p/8922602.html