软件工程实践2019第三次作业

软件工程实践第三次作业

github链接

1.PSP表格
PSP2.1Personal Software Process Stages预估耗时(分钟)实际耗时(分钟)
Planning计划3010
Estimate估计这个任务需要多少时间240360
Development开发180120
Analysis需求分析 (包括学习新技术)6080
Design Spec生成设计文档6030
Design Review设计复审6030
Coding Standard代码规范 (为目前的开发制定合适的规范)1010
Design具体设计1010
Coding具体编码12090
Code Review代码复审6010
Test测试(自我测试,修改代码,提交修改)60120
Reporting报告3060
Test Repor测试报告3030
Size Measurement计算工作量3020
Postmortem & Process Improvement Plan事后总结, 并提出过程改进计划3060

2.计算模块接口设计

核心——回溯算法

void backtrace(int count) {
    /*输出*/
    if (count == m*m) {

        cout << "结果:" << endl;
        for (int i = 0; i < m; ++i) {
            for (int j = 0; j < m; ++j) {
                cout << map[i][j] << " ";
            }
            cout << endl;
        }

        for (int i = 0; i < m; i++)
        {
            for (int j = 0; j < m; j++)
            {
                fout << map[i][j];
                if (j < m - 1) fout << "  ";
            }
            fout << endl;
            if (i == m - 1) fout << endl;
        }
        return;
    }

    /*判断是否回溯*/
    int row = count / m;
    int col = count % m;
    if (map[row][col] == 0) {
        for (int i = 1; i <= m; ++i) {
            if (Check(i,count)) {//可以放
                map[row][col] = i;//赋值
                backtrace(count + 1);//进入下一层
            }
        }
        map[row][col] = 0;//回溯
    }
    else {
        backtrace(count + 1);
    }
}

检测函数:判断当前位置填入tag是否合格

bool Check(int tag, int count) {
    int row = count / m;
    int col = count % m;
    int tempRow;
    int tempCol;

    //行检测
    for (int i = 0; i < m; i++) {
        if (tag == map[row][i]) return false;
    }

    //列检测
    for (int i = 0; i < m; i++) {
        if (tag == map[i][col]) return false;
    }


    //宫检测
    switch (m)
    {
    case 3: {
        return true;
    }
    case 4: {
        tempRow = row / 2 * 2;
        tempCol = col / 2 * 2;
        for (int i = tempRow; i < tempRow + 2; ++i) {
            for (int j = tempCol; j < tempCol + 2; ++j) {
                if (tag == map[i][j]) {
                    return false;
                }
            }
        }
        return true;
    }

    case 5: {
        return true;
    }
    case 6: {
        tempRow = row / 2 * 2;
        tempCol = col / 3 * 3;
        for (int i = tempRow; i < tempRow + 2; ++i) {
            for (int j = tempCol; j < tempCol + 3; ++j) {
                if (tag == map[i][j]) {
                    return false;
                }
            }
        }
        return true;
    }
    case 7: {
        return true;
    }
    case 8: {
        tempRow = row / 4 * 4;
        tempCol = col / 2 * 2;
        for (int i = tempRow; i < tempRow + 4; ++i) {
            for (int j = tempCol; j < tempCol + 2; ++j) {
                if (tag == map[i][j]) {
                    return false;
                }
            }
        }
        return true;
    }
    case 9: {
        tempRow = row / 3 * 3;
        tempCol = col / 3 * 3;
        for (int i = tempRow; i < tempRow + 3; ++i) {
            for (int j = tempCol; j < tempCol + 3; ++j) {
                if (tag == map[i][j]) {
                    return false;
                }
            }
        }
        return true;
    }

    default:
        return true;
        break;
    
    }   
}

3.性能改进

cpu性能测试
1799473-20190925210709693-633652049.png

内存性能测试
1799473-20190925210737712-1018833603.png

暂无

4.测试

三宫格
1799473-20190925210747374-850741988.png

四宫格
1799473-20190925210759429-477776117.png

五宫格
1799473-20190925210810071-1535986083.png

六宫格
1799473-20190925210825024-384636557.png

七宫格
1799473-20190925210833409-1543472944.png

八宫格
1799473-20190925210840514-1263018418.png

九宫格
1799473-20190925210845417-1333510680.png


5.异常处理

处理文件打开失败与宫格非法的异常:

    try
    {
        if (m < 3 || m>9) {
            throw - 1;
        }
        if (fin.is_open()==false) {
            throw - 2;
        }
        if (fout.is_open() == false) {
            throw - 3;
        }
            
    }
    catch (int e)
    {
        if (e == -2) {
            cout << "Not found Infile!";
            return 0;
        }
        else if (e == -3)
        {
            cout << "Can not open Outfile!";
            return 0;
        }
        else
        {
            cout << "Please enter right number 'm'!";
            return 0;
        }
    }
  1. 如果输入的文件名有误,则抛出异常"Not found Infile!"
  2. 如果输出的文件夹无法打开,则抛出"Can not open Outfile!"
  3. 如果输入的m超出范围,则抛出"Please enter right number 'm'!"

转载于:https://www.cnblogs.com/LIU151/p/11587164.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值