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


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

    031602230 卢恺翔

    题目描述

    问题1:采取面向对象的方法,四则运算自动出题软件,根据需求可以划分为几个类?每个类具有什么属性?每个类具有什么行为?

    我认为可以分成3个类:数据类、语言类、和文件类。

    其中文件类具有:读取文件的相对路径,从读取文件中读取的生成题目的个数和写入文件的属性。总之就是对文件进行操作的属性。具有读取文件和写入文件的操作。

    #pragma once
    #ifndef FILE_H
    #define FILE_H
    #include <iostream>
    #include <time.h>
    #include <cstdlib>
    #include <cstring>
    #include <stack>
    #include <map> 
    #include <fstream>
    using namespace std;
    class File
    {
    private:
    	char *inputfile;		//读取文件的相对路径
    	int n;			//从读取文件中读取的生成题目的个数
    	char *outpath;		//写入文件的相对路径
    
    public:
    	int inputcount(char *inputfile);
    	void outputfile(char *path,string equ,string answer,int rightanswer,char *boundadry);
    	void outputfile(char *path, char *bourdadry, int n);
    
    
    
    protected:
    };
    #endif
    

    数据类具有随机数,随机符号,表达式,表达式计算值等属性,并具有生成随机数,生成随机符号,生成算式,计算算式结果等操作。

    #pragma once
    #ifndef DATA_H
    #define DATA_H
    #include <iostream>
    #include <time.h>
    #include <cstdlib>
    #include <cstring>
    #include <stack>
    #include <map> 
    #include <fstream>
    using namespace std;
    class Data
    {
    private:
    	int random;			//代表随机数,可用于生成算式中的数字,也用于随机字符和随机括号
    	char randomsym;		//代表随机字符
    	string equ;			//生成的算式
    	string postfix;		//后缀表达式
    	stack<char> mark;	//符号栈
    	map<char, int> priority;		//符号优先级
    	stack<int> tempResult;			//计算后缀表达式的栈
    	int rightcount=0;      //记录回答正确的个数题数
    
    public:
    	int randomNumber();				//用于随机生成数字;
    	char randomOperation();			//用于随机生成运算符
    	string bracket(string n);    //随机生成括号 
    	string int_str(int number); //将数字转换为字符串 
    	string connect(string str1, string str2, char a);  //将数字与符号连接 
    	string InfixToPostfix(string infix);   //将前缀表达式转换为后缀表达式 
    	int expressionCalculate(string s);  //计算正确答案
    	int posfixCompute(string s);    //计算后缀表达式  
    	int record(int answer, int input);  //计算正确题数 
    
    	 
    
    protected:
    };
    #endif
    

    语言类具有存储语言等属性,并具有选择语言,根据语言生成界面等操作。

    #pragma once
    #pragma once
    #ifndef LANGUAGE_H
    #define LANGUAGE_H
    
    #include <iostream>
    #include <time.h>
    #include <cstdlib>
    #include <string>
    #include <stack>
    #include <map> 
    #include <fstream>
    class language
    {
    private:
    	char boundadry[20][200];		//用于存储语言界面的各个语句
    	char line[100] = "";			//存储语言列表
    	char path[100] = "";			//存储用户要求的语言,并存储其相对路径
    public:
    	void languagelist(char boundadry[20][200]);			//语言列表
    	void languagechoice(char boundadry[20][200]);			//用户选择语言
    
    
    
    protected:
    };
    #endif
    

    问题2:类与类之间是如何进行协作的?谁给谁发送消息?谁持有谁的引用?

    语言类为文件类的写入提供语言环境,文件类提供数据类的循环生成算式的次数,数据类提供正确答案,把答案传给文件类并被文件类记录下来。
    类图如下

    还不是很懂类与类之间的关系,查了资料之后,感觉是相互依赖的薄弱关系。。。

    问题3 该自动出题软件采取何种算法或者是如何实现的?可以采用流程图描述的方法。

    总之就是用中缀转后缀,计算后缀表达式为核心的算法。

  • 相关阅读:
    CIFAR10-网络训练技术
    论文-Deep Residual Learning for Image Recognition
    Origin-作图相关
    OnCtlColor
    查看电脑MAC地址
    改变静态文本框和PictureControl的背景颜色
    MFC在对话框中的Picture contrl控件中添加icon图标,并改变icon图标的背景色与对话框背景色一致
    char型数组学习
    条件编译
    ASCII码
  • 原文地址:https://www.cnblogs.com/leolkx/p/6863780.html
Copyright © 2020-2023  润新知