實驗 4
阿新 • • 發佈:2018-04-24
namespace out http ott otto OS isp .com src
第二題
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; } ``` 第三題
include
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)
{
實驗 4