zoukankan      html  css  js  c++  java
  • 实验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;
        }
    }

  • 相关阅读:
    django复习笔记2:models
    django复习笔记1:环境配置
    jQuery复习笔记
    Javascript备忘复习笔记2
    Javascript备忘复习笔记1
    实战SQL注入
    【Python】SyntaxError: Non-ASCII character 'xe8' in file
    【iOS】Error: Error Domain=PBErrorDomain Code=7 "Cannot connect to pasteboard server
    【Mac】nsurlsessiond 后台下载问题的解决方法
    【iOS】沙盒目录
  • 原文地址:https://www.cnblogs.com/kakuiyjl/p/8922369.html
Copyright © 2011-2022 走看看