Tuesday, December 8, 2009

Finding a Path Algorithm - Driver Program

The following (and the 3-4 posts before) is an incomplete, not-working-quite-right program I wrote in the equivalent of a CMPT 306 class while at Snow; just tossing it up here to get some feedback on it. Take a gander if ya like, though it's not my best work...

Title: Programming Project 5 - Maze and Creature
Author: Daniel J. Tanner
Class: CS 2420 - Data Abstraction & Problem Solving w/ C++
Date: October 17th, 2005 (latest update)

#include "TannMaze.h"
#include "TannCreature.h"
using namespace std;

//function declarations
void displayGreeting();

int main()

//set variables
Coord start, end;
int width, height;
char choice;
string filename;
TannMaze basicMaze;
TannCreature bob;
bool success;

//Find out if user has a file he'd like to use or if he'd like to
//manually input the data
cout << "Would you like to get the data from a file?:(y/n) "; cin >> choice;
if(toupper(choice) != 'Y')
//get width and height
cout << "input the width: "; cin >> width;
cout << "input the height: "; cin >> height;

//get start and exit
cout << "Please enter the coordinates for the entrance of your\n" << "maze in the form (x y): "; cin >> start.x >> start.y;
cout << "Do the same for the exit: "; cin >> end.x >> end.y;

//adjust for proper array usage
start.x--; start.y--;
end.x--; end.y--;

//generate maze
basicMaze.generateMaze(width, height, start, end);
//get filename
cout << "Please input the name of your file, including the extension: "; cin >> filename;

//generate maze based on file

//create a creature and have it go through the maze after displaying it
cout << "Your maze appears as follows: \n\n";
cout << endl;

//show the solution to the maze:
cout << "The solution to your maze is as follows: \n\n";
success = bob.findExit();
cout << "Unfortunately your maze is unsolveable.\n\n";
cout << endl << endl;

return 0;

void displayGreeting()
cout << "Greetings! This program will generate a maze and provide a solution\n"
<< "should there be one. You can tell the program the width and height\n"
<< "yourself or you can open a file that you've already input the data\n"
<< "into.\n\n";

No comments:

Post a Comment