码迷,mamicode.com
首页 > 其他好文 > 详细

实验4

时间:2018-04-24 13:55:28      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:ace   http   namespace   nbsp   top   ima   alt   mes   inf   

#include<iostream>
using namespace std;
class Graph{
public:
Graph(char,int);
void draw();
private:
char s;
int z;
};
Graph::Graph(char x,int y)
{
s=x;
z=y;
}
void Graph::draw()
{
char a[z][2*z-1];
int b,c,d,e;
for(b=0;b<z;b++)
{
for(d=0;d<z-b-1;d++)
{
a[b][d]=‘ ‘;
}
for(c=z-b-1;c<z+b;c++)
{
a[b][c]=s;
}
for(e=z+b;e<2*z-1;e++)
{
a[b][e]=‘ ‘;
}
}
for(b=0;b<z;b++)
{
for(c=0;c<2*z-1;c++)
{
cout<<a[b][c];
}
cout<<endl;
}
}
int main()
{
Graph Graph1(‘$‘,7);
Graph1.draw();
Graph Graph2(‘*‘,5);
Graph2.draw();
return 0;
}

技术分享图片

#include<iostream>
using namespace std;
class Fraction{
public:
Fraction();
Fraction(int t,int b);
Fraction(int c);
void add(Fraction);
void min(Fraction);
void mul(Fraction);
void div(Fraction);
void output();
private:
int top;
int bottom;
};
Fraction::Fraction():top(0),bottom(1){
}
Fraction::Fraction(int t,int b):top(t),bottom(b){
}
Fraction::Fraction(int c):top(c),bottom(1){
}
void Fraction::add(Fraction x)
{
top=top*x.bottom+x.top*bottom;
bottom=bottom*x.bottom;
output();
}
void Fraction::min(Fraction x)
{
top=top*x.bottom-x.top*bottom;
bottom=bottom*x.bottom;
output();
}
void Fraction::mul(Fraction x)
{
top=top*x.top;
bottom=bottom*x.bottom;
output();
}
void Fraction::div(Fraction x)
{
top=top*x.bottom;
bottom=bottom*x.top;
output();

}
void Fraction::output()
{
cout<<top<<‘/‘<<bottom<<endl;
}
int main()
{
Fraction h;
Fraction g(3,4);
Fraction k(5);
h.output();
g.output();
k.output();

g.add(k);

g.min(k);

g.mul(k);

g.div(k);

return 0;

}

技术分享图片

 

实验4

标签:ace   http   namespace   nbsp   top   ima   alt   mes   inf   

原文地址:https://www.cnblogs.com/feiming/p/8929071.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!