C++作业01

原创 2004年10月26日 10:32:00

Program #2 - Maze Traversal


Maze Traversal:

You will be given two files that contain ASCII mazes, and your program should first read in the maze into arrays (or vectors) and then recursively find a path through the maze. When the program has found a path through the maze it should print to the screen the path that it found. Your path can only be up, down, left or right (sorry no diagonal moves). For your final path you are not allowed to step on a square more than once (so treat previously marked squares as impassable).

Your program should prompt the user for the file name that contains the maze, and then proceed to read in the file. The format of the file is that the first line will contain information about the numbers of rows and the number of columns for the maze.

Key to the maze characters:

	%	wall

	.	empty floor

	e	entrance (starting position)

	x	exit (ending position)



	+	step that your program takes....mark your trail as you go....and don't forget to erase 

		your marks if you need to go back

Here is what maze2.txt looks like:

15 x 28
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%...%.....%.......%........%
%......%....%.......%%%....%
%..%%..%%......%......%....e
%%%%%.%%%.%%%.....%...%%...%
%......%%....%...%.......%.%
%..%%%%.....%....%....%%%..%
%.....%%....%%...%%%%....%%%
%..%%%%%%%....%.%.%........%
%...............%..........%
%%%%%.......%...%..%..%%%%%%
%.....%.%...%%%....%.......%
%%%....%....%....%%%....%%.%
%%....%.%.%...%.....%%%....%
%%%%x%%%%%%%%%%%%%%%%%%%%%%%

Hints:

  • As you read in the maze you may want to save the location of the starting position.
  • Think about the solution first and write some pseudo-code before trying to write the recursive part of the solution.
    • what is your ending condition
    • what do you want to try each time you call the function
    • what happens in your function each time it is successful, or each time it is unsuccessful?
  • One way to solve it is to have your function declaration something like this: bool takeStep( int row, int col); where the function returns true if it finds the end (through a chain of calls) or false if this path is a dead-end.
  • Remember where a function call will return when it is done (successfull or not).....back to it's calling point.

Debugging Suggestions: For debugging feel free to make a smaller maze (5x5) to see if your algorithm works, or even a maze with no internal walls. Also it is always a good idea to print out the maze after every step or two so you can see the progress of you program (you can read a char into a junk variable to cause a pause in your program).

Turn in: A print out of your code, and the two mazes with your path. The two mazes you can capture from the command window (black screen) by using Select All and then Copy from the command windows menus, then you can paste your output below your programs code as a comment.

 

解答C++作业01

#include#include#include#include#includeusing namespace std;int find(char ch,int &x,int &y,string op...
  • skyinter
  • skyinter
  • 2004年10月26日 10:40
  • 839

帮同学写的C++大作业,图书管理系统

#include #include #include #include #include #include #include #include #include #include #define de...
  • zhoujinyu0713
  • zhoujinyu0713
  • 2012年12月12日 23:24
  • 3004

算法训练 C++ CH08 01

算法训练 C++ CH08 01 时间限制:1.0s 内存限制:256.0MB问题描述   已知一个有理数类Zrf_Ratio,实现如下的操作符重载形式:   friend std::os...
  • ldsh304
  • ldsh304
  • 2016年12月31日 14:58
  • 367

2013年大一上学期的C++大作业 学生信息管理系统

main.cpp #include #include #include #include "function.h" using namespace std; int main() { p...
  • u012725244
  • u012725244
  • 2015年04月11日 19:47
  • 1568

C++期末大作业

实现一个工资管理系统 一、内容 1.题目《小型公司工资管理系统》设计 2.设计说明与要求 (1) 公司主要有5类人员:文秘、技术经理、技术员、销售员、销售经理。要求存储这些...
  • u013928645
  • u013928645
  • 2014年06月21日 20:57
  • 1503

C++期末作业

    好无聊的 C++作业,虽然是练熟练度的,但是好歹也出个有点意思的题目吧... #include /*关于运算符重载,完全定义六个类之间的四则运算实在是太耗费时间了,只定义了 圆加上...
  • ypc1109
  • ypc1109
  • 2010年11月30日 19:57
  • 556

C++课程设计作业

4、模拟智能交通信号灯系统  设计一个智能信号灯系统,在十字路口控制东西南北四个方向交通信号,当然是红灯停绿灯行了, 一般情况是四个方向每次绿灯亮30秒,只不过在绿灯熄灭后亮3秒黄灯再转红...
  • u014042940
  • u014042940
  • 2014年06月11日 15:32
  • 985

算法学习 - 01背包问题(动态规划C++)

动态规划 01背包 问题描述 求解思路 代码实现 放入哪些物品 代码动态规划我在上一篇博客里已经讲了一点动态规划了,传送门:算法学习 - 动态规划(DP问题)(C++)这里说一下,遇到动态规划应该如何...
  • chenfs1992
  • chenfs1992
  • 2015年04月28日 21:09
  • 3319

01背包问题 及c++ 代码实现

今天在看july的博客之时,看到其中一道题目的原理为01背包问题,就自己温习了下,写下今天的学习体会。 本文理论分析参考博客:http://www.cnblogs.com/qinyg/archive...
  • zhaowenchaofang
  • zhaowenchaofang
  • 2013年06月14日 01:12
  • 4276

01字串---二进制输出(结合网友大神方法和自己的思路)

问题描述 对于长度为5位的一个01串,每一位都可能是0或1,一共有32种可能。它们的前几个是: 00000 00001 00010 00011 00100 请按从小到大的顺序输出这32种01串...
  • Tao_222
  • Tao_222
  • 2016年03月19日 15:57
  • 594
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:C++作业01
举报原因:
原因补充:

(最多只允许输入30个字)