// 类graph的实现
 
#include "graph.h" 
#include <iostream>
using namespace std;

// 带参数的构造函数的实现 
Graph::Graph(char ch, int n): symbol(ch), size(n) {
}


// 成员函数draw()的实现
// 功能:绘制size行,显示字符为symbol的指定图形样式 
//       size和symbol是类Graph的私有成员数据 
void Graph::draw()
{
    for(int i=0; i<size ; i++)//一共size行 
    {
        for(int j=0; j<2*size-1 ;j++)//一共size-1列 
        {
            if( j<size-i-1 || j>size+i-1 )
            cout<<" ";
            else cout<<symbol; 
        }
        cout<<endl;
     } 
    // 补足代码,实现「实验4.pdf」文档中展示的图形样式 
}

#include<iostream>
#include "Fraction.cpp" 
using namespace std;
int main()
{
    int i,j,n,m;
    cin>>i>>j>>n>>m;
    Fraction zz(i,j);
    Fraction yy(n,m);
    Fraction a;
    Fraction b(3,4);
    Fraction c(5);
    a.xx();
    b.xx();
    c.xx();
    a.jia(zz,b);
    a.jian(zz,b);
    a.cheng(zz,b);
    a.chu(zz,b);
    a.daxiao(zz,yy);
    return 0;
}
#ifndef CP
#define CP
class Fraction
{
    public:
        Fraction ()
        {
            top=0;
            bottom=1;
        }
        Fraction (int top1,int bottom1)
        {
            top=top1;
            bottom=bottom1;
        }
        Fraction (int top1)
        {
            top=top1;
            bottom=1;
        }
        void xx();
        void jia(Fraction a, Fraction b);
        void jian(Fraction a,Fraction b);
        void cheng(Fraction a,Fraction b);
        void chu(Fraction a,Fraction b);
        void daxiao(Fraction a,Fraction b);
    private:
        int top;
        int bottom;
};
#endif
#include<iostream>
#include "Fraction.h"
using namespace std;
void Fraction::xx()
{
    cout<<top<<"/"<<bottom<<endl;
}
void Fraction::jia(Fraction a,Fraction b)
{
    cout<<a.top+b.top<<"/"<<a.bottom+b.bottom<<endl;
}
void Fraction::jian(Fraction a,Fraction b)
{
    cout<<a.top*b.bottom-a.bottom*b.top<<"/"<<a.bottom*b.bottom<<endl;
}
void Fraction::cheng(Fraction a,Fraction b)
{
    cout<<a.top*b.top<<"/"<<a.bottom *b.bottom <<endl;
}
void Fraction::chu(Fraction a,Fraction b)
{
    cout<<a.top*b.bottom<<"/"<<a.bottom*b.top<<endl;
}
void Fraction::daxiao(Fraction a,Fraction b)
{
    if(a.top*b.bottom-a.bottom*b.top>0)
    {
        cout<<""<<endl;
    }
    if(a.top*b.bottom-a.bottom*b.top<0)
    {
        cout<<""<<endl;
    }
}

 

 

 

 

posted on 2018-04-23 22:40  卡斯兰娜樱  阅读(133)  评论(2编辑  收藏  举报