面向对象程序设计 第三次作业补充

Github链接:https://github.com/zora02/object-oriented/tree/master/Caculator(更改)

作业准备

说实话寒假打代码的时候没有认真的看过代码规范,当时觉得能把代码打出来就很开心了(´・_・`)。这几天认真的看了代码规范,感觉还是有所收获。(虽然有些内容我们现在还用不到,但是以后肯定是能用到的。)看完代码规范后对自己的代码做了一些修改。但是没有特别大的改动,主要是一些格式上的修改。还有就是注释方面我还是不很清楚,不知道该怎么注释比较合适正确,所以本来想修改一下自己的注释,但是不知道该怎么改orz。。。所以我没有改,如果这个被扣分,我认了>_<

修改后的代码

main.cpp

#include <iostream>
#include <string>
#include <queue>
#include <stdlib.h>
#include "Scan.hpp"
#include "Print.hpp"
using namespace std;


int main()
{
    string s;
    cin >> s;
    Print :: PrintQueue(Scan :: ToStringQueue(s));
}

Scan.cpp

#include "Scan.hpp"
#include <iostream>
#include <string>
#include <queue>
#include <stdlib.h>
using namespace std;

bool Scan::checkNum(char c)
{
    return ('0' <= c && c <= '9') || c == '.'; //判断数字或者是小数点
}
queue<string> Scan::ToStringQueue(string s)
{
    int len = s.size();
    string tem_s;
    queue<string> q;
    for (int i = 0 ; i < len;)
    {
        tem_s.clear();
        if (!checkNum(s[i])) //判断是符号还是数字
        {
            tem_s += s[i++]; //符号
        }
        else
        {
            while (i < len && checkNum(s[i]))
            {
                tem_s += s[i++]; //数字
            }
        }
        if (tem_s.size() > 10)
        {
            cout << "Error" << endl;
            exit(0); //报错
        }
        q.push(tem_s);
    }
    return q;
};

Scan.hpp

#ifndef Scan_hpp
#define Scan_hpp
#include <iostream>
#include <string>
#include <queue>
#include <stdlib.h>
using namespace std;

class Scan
{
    public :
    static bool checkNum(char c);

    static queue<string> ToStringQueue(string s);
    
    queue<string> q;
  
};


#endif /* Scan_hpp */

Print.cpp

#include "Print.hpp"
#include <iostream>
#include <string>
#include <queue>
#include <stdlib.h>
using namespace std;

void Print::PrintQueue(queue<string> q)
{
    while (!q.empty())
    {
        cout << q.front() << endl, q.pop();
    }
};

Print.hpp

#ifndef Print_hpp
#define Print_hpp
#include <iostream>
#include <string>
#include <queue>
#include <stdlib.h>
using namespace std;

class Print
{
public:
    static void PrintQueue(queue<string> q);    
};


#endif /* Print_hpp */

转载于:https://www.cnblogs.com/perhap-s/p/5321224.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值