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

    感受

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

  • 相关阅读:
    List 集合的常用方法总结
    springboot 整合 web 项目找不到 jsp 文件
    Web 安全
    微服务开放平台接口设计
    SpringCloud Hystrix 参数
    SpringCloud Eureka 配置
    ELK 日志收集系统
    网盘搜索引擎原理
    jsPlumb.jsAPI阅读笔记(官方文档翻译)
    ionic获取ios唯一设备id的解决方案
  • 原文地址:https://www.cnblogs.com/gjx031602211/p/6863375.html
Copyright © 2011-2022 走看看