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

软件工程实践第三次作业

github链接

1.PSP表格

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

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性能测试

内存性能测试

暂无

4.测试

三宫格

四宫格

五宫格

六宫格

七宫格

八宫格

九宫格


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'!"
posted @ 2019-09-25 20:20  莫得感情`  阅读(172)  评论(1编辑  收藏  举报