软件工程大作业——数独游戏2

软件工程大作业——数独游戏2


一、PSP表格
二、问题分析
三、系统设计
四、具体实现
五、单元测试
六、程序性能及质量分析
七、GUI
八、总结
代码地址:https://github.com/friyal0730/sudoku/
这篇文章主要是第四部分具体实现、第五部分单元测试和第六部分程序性能及质量分析

四、具体实现

Check.h:负责对用户输入的命令进行处理,如果命令输入错误,进行错误提示,下面是判断输入并执行的代码部分:

int solveinput() //判断并执行命令
	{
		if (argc != 3) //输入格式不正确
		{
			cout << "Illegal paramater number" << endl;
			cout << "Input like this: [sudoku.exe -c n] or [sudoku.exe -s path]" << endl;
			return 1;
		}

		if (strcmp(argv[1], "-c") && strcmp(argv[1], "-s"))   //字母错误
		{
			cout << "The first parameter should only be -c or -s" << endl;
			cout << "-c means to generate the sudoku to file." << endl;
			cout << "-s means to solve the sudoku from the file." << endl;
			return 2;
		}

		if (!strcmp(argv[1], "-c"))   //创造数独终盘
		{
			int sum = 0;   //sudoku的个数
			int len = strlen(argv[2]);
			for (int i = 0; i < len; i++)
			{
				if (!(argv[2][i] >= '0' && argv[2][i] <= '9'))   //输入的字符不合法(不是数字)
				{
					cout << "The third paramater after -c should be number that indicate the sudoku you want." << endl;
					if (argv[2][i] == '+' || argv[2][i] == '-' || argv[2][i] == '/' || argv[2][i] == '*')
					{
						cout << "Please input the number!" << endl;
						return 8;
					}
					return 3;
				}
				sum = 10 * sum + argv[2][i] - '0';
			}

			if (sum > MAX || sum < 1)   //数字过大
			{
				cout << "The number is too large,the number should be 1-1000000" << endl;
				return 4;
			}
			/*----------------------------------*/
			/*创建数独终盘对象*/
			/*...........*/

			FILE* file;
			file = freopen("sudoku.txt", "w", stdout);   //没有文件时可以创造
			Base base(sum, file);    //调用Generator
			base.generate();
			/*----------------------------------*/

			return 5;
		}

		if (!strcmp(argv[1], "-s"))   //解题
		{
			FILE* ans;
			FILE* question;   //数独题目
			question = freopen(argv[2], "r", stdin);
			if (!question)
			{
				cout << "The file path is not right,please check." << endl;
				return 
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值