• 2017《面向对象程序设计》课程作业四


    OOA(Object Oriented Analysis,面向对象分析):
    从客观存在的事务和事务之间的关系,归纳出有关对象(包括对象的属性和行为)以及对象之间的联系,并将具有相同属性和行为的对象用一个类(class)来表示。建立一个能够反映真实情况的需求模型。

    OOD(Object Oriented Design,面向对象设计) 将面向对象分析阶段形成的需求模型进一步具体设计。如类的设计(继承、派生、类与类之间的消息协作)、算法的设计等。采取通用的工具,如流程图、类图等来描述。

    类及其属性和行为

    我的程序中主要分为2个类:ExpressionFraction ;

    其余函数例如求最大公约数,文件读取,语言等全部放在aulixiary_functions
    中,作为这两个主要的类的辅助函数。

    流程图

    代码实现

    #pragma once
    
    #include"fraction.h"
    #include"auxiliary_functions.h"
    #include<iostream>
    #include<vector>
    using namespace std;
    const int kMax = 1000;
    
    class Expression
    {
    private:
    	vector<string> m_expressionUint;
    	string m_infix;
    	char m_postfix[kMax];
    	Fraction m_result;
    
    public:
    	Expression();
    	char RandomOperation(char ifMultiplyDivide);
    	string GenerateInfixExpression(int low, int high, int parameterNumber, char ifMultiplyDivide, char ifFraction, char ifBracket);
    	void TransferInfixIntoPostfix();
    	string CalculateResult();
    	bool IsOnly(string expression);
    };
    
    #pragma once
    
    #include"auxiliary_functions.h"
    #include<iostream>
    using namespace std;
    
    class Fraction
    {
    private:
    	int m_nnumerator, m_ndenominator;
    	string m_snumerator, m_sdenominator;
    
    public:
    	Fraction();
    	void GetFraction(int l, int h);
    	bool isDivisorZero();
    	bool IsInt();
    	void TransferIntIntoFraction(int up, int down);
    
    	void Simplify();
    	string TransferIntoStringNoInt();
    	string TransferIntoString();
    
    	friend const Fraction operator +(Fraction frac1, Fraction frac2);
    	friend const Fraction operator -(Fraction frac1, Fraction frac2);
    	friend const Fraction operator *(Fraction frac1, Fraction frac2);
    	friend const Fraction operator /(Fraction frac1, Fraction frac2);
    };
    

    感受

    这次用类图和流程图重新审视了一下自己的程序感觉清楚多了!如果栋哥能在四则运算之前流这个作业我决定我编程时就不用那么痛苦了。毕竟在编程前要先对题目进行分析和设计;然后按照设计的类图和流程图设计就容易的多了。

  • 相关阅读:
    Oracle 学习笔记4 SQL语言基础
    Oracle 学习笔记3 Sql Plus 命令
    连接扩展屏后,桌面上的图标自动跑到扩展屏上去了
    Oracle数据库基础知识
    ORACLE 学习笔记 2 Oracle 11g 体系结构
    EXCEL 连接Oracle 数据库
    虚拟机
    截取默写数据库无法识别的字符前几位的值
    c#的SerialPort在多线程环境下需要加锁
    32. 最长有效括号
  • 原文地址:https://www.cnblogs.com/gjx031602211/p/6863375.html
Copyright © 2020-2023  润新知