第二题
using namespace std;
class Graph {
public:
Graph(char t, int n);
void draw();
private:
char ch;
int number;
};
Graph::Graph(char t, int n): ch(t), number(n) {}
void Graph::draw()
{
int i,j;
for(i=0;i<=number;i++)
{
for(j=0;j<=number-i;j++)
cout<<" ";
for(int j=0;j<2*i-1;j++)
cout<<number;
cout<<endl;
}
}
int main() {
Graph graph1(‘*‘,5), graph2(‘$‘,7) ;
graph1.draw();
graph2.draw();
return 0;
} ```
第三题
using namespace std;
class Fraction
{
public:
Fraction():top(0),bottom(1) {};
Fraction(int a,int b):top(a),bottom(b) {};
Fraction(int c):top(c),bottom(1){};
void add(Fraction p);
void sub(Fraction p);
void mul(Fraction p);
void div(Fraction p);
void display()
{
cout<<top<<"/"<<bottom<<endl;
};
void op();
private:
int top;
int bottom;
};
void Fraction:: add(Fraction p)
{
原文:https://www.cnblogs.com/-Alone/p/8922618.html