• 实验4= = == = = =


    // 类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;
        }
    }

  • 相关阅读:
    用mysql+redis实现微博feed架构上需要注意哪些问题
    windows7下安装zend studio5.5
    鼠标移出DIV层时,触发onMouseOut事件
    关于MVVM和RAC的一些拓展阅读
    Swift(上) 常量, 变量, 数据类型, 循环, 选择结构 简单函数
    SDWebImage的使用
    App Store新应用提审攻略
    关于iOS的推送服务的点点
    iOS开发代码规范
    伟大的RAC和MVVM入门(二)
  • 原文地址:https://www.cnblogs.com/kakuiyjl/p/8922369.html
Copyright © 2020-2023  润新知