Programming Assignment I - Computer System Concepts | CS 350, Assignments of Computer Science

Material Type: Assignment; Professor: Cukic; Class: Computer System Concepts; Subject: Computer Science; University: West Virginia University; Term: Fall 2008;

Typology: Assignments

Pre 2010

Uploaded on 07/30/2009

koofers-user-8i9
koofers-user-8i9 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 350 – Fall 2008
Programming Assignment #1
Obstacle Avoidance Problem
(You may download this assignment statement from http://www.csee.wvu.edu/~cukic , follow the link to
CS 350 home page)
Deadline: Monday, Sept 15th , 2008, 11:59pm
Problem Statement
The following grid of ones and zeroes is a double scripted array representation of a terrain of size 12 x 12.
1 1 1 1 1 1 1 1 1 1 1 1
1 0 0 0 1 0 0 0 0 1 0 1
0 0 1 0 1 0 0 0 0 1 0 1
1 1 0 0 1 0 0 0 0 1 0 1
1 0 0 0 0 0 1 1 0 1 0 0
1 1 1 1 0 0 1 1 0 1 0 1
1 0 1 1 0 0 1 1 0 1 0 1
1 1 1 1 0 0 1 1 0 1 0 1
1 0 0 0 0 0 0 0 0 1 0 1
1 1 1 1 1 0 0 0 0 1 0 1
1 0 0 0 0 0 0 0 0 1 0 1
1 1 1 1 1 1 1 1 1 1 1 1
The ones represent the obstacles if the field, and the zeroes represent positions in the possible path through
the field.
In this assignment, the field will have a single entrance and a single exit, i.e., there will be only two zeroes
in the “outer wall” of the field. In order to find the entrance and the exit, traverse the outer wall of the field in
counter-clockwise direction, starting from the upper left corner. The first encountered zero will be the entrance
(square [2,0] in the field above), and next zero will be the exit (square [4,11]). In this assignment, the size of a
field is NOT FIXED, it MAY NOT BE A SQUARE array. Each array dimension will vary in size
between 5 and 40.
There are several simple algorithms for walking through a field that guarantee finding the path, if one exists.
The only legal moves are north, west, south or east. For example, look to your right and walk forward. Always
keep an obstacle to your right. If you reach the corner of the obstacle, turn right and continue following it.
There may be a shorter path than the one you have taken, but in this way you are guaranteed to get out of the
field. In this algorithm, if you exit from the field through the entrance, this means that the path from the
entrance to the exit does not exist.
In your assignment, you need to write a program called path.c. First of all, the program should ask user to
type in the size of the field (if you enter 12, 6, this will imply a 12 rows and 6 columns field). Then the program
should request the user to type in the name of the input file that contains the field (the code for reading the file
will be offered to you on the class Web page). You may assume that the field size given to the program always
matches the size in the file. The field will be given to your program in an ASCII text file, looking very much
like the one above (but of proper size). Upon opening the file, your program must find the entrance. As your
program attempts to find a path through the field, it should place the character X into each square in the path.
Note that your program MUST NOT replace a 1 (an obstacle) with an X. Only zeroes can be replaced by X’s.
pf2

Partial preview of the text

Download Programming Assignment I - Computer System Concepts | CS 350 and more Assignments Computer Science in PDF only on Docsity!

CS 350 – Fall 2008

Programming Assignment

Obstacle Avoidance Problem

(You may download this assignment statement from http://www.csee.wvu.edu/~cukic , follow the link to

CS 350 home page)

Deadline: Monday, Sept 15 th^ , 2008, 11:59pm

Problem Statement

The following grid of ones and zeroes is a double scripted array representation of a terrain of size 12 x 12.

1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1 0 0 0 0 1 0 1 0 0 1 0 1 0 0 0 0 1 0 1 1 1 0 0 1 0 0 0 0 1 0 1 1 0 0 0 0 0 1 1 0 1 0 0 1 1 1 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 1 0 1 0 1 1 1 1 1 0 0 1 1 0 1 0 1 1 0 0 0 0 0 0 0 0 1 0 1 1 1 1 1 1 0 0 0 0 1 0 1 1 0 0 0 0 0 0 0 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1

The ones represent the obstacles if the field, and the zeroes represent positions in the possible path through the field.

In this assignment, the field will have a single entrance and a single exit, i.e., there will be only two zeroes in the “outer wall” of the field. In order to find the entrance and the exit, traverse the outer wall of the field in counter-clockwise direction , starting from the upper left corner. The first encountered zero will be the entrance (square [2,0] in the field above), and next zero will be the exit (square [4,11]). In this assignment, the size of a field is NOT FIXED, it MAY NOT BE A SQUARE array. Each array dimension will vary in size between 5 and 40.

There are several simple algorithms for walking through a field that guarantee finding the path, if one exists. The only legal moves are north, west, south or east. For example, look to your right and walk forward. Always keep an obstacle to your right. If you reach the corner of the obstacle, turn right and continue following it. There may be a shorter path than the one you have taken, but in this way you are guaranteed to get out of the field. In this algorithm, if you exit from the field through the entrance, this means that the path from the entrance to the exit does not exist.

In your assignment, you need to write a program called path.c. First of all, the program should ask user to type in the size of the field (if you enter 12, 6 , this will imply a 12 rows and 6 columns field). Then the program should request the user to type in the name of the input file that contains the field (the code for reading the file will be offered to you on the class Web page). You may assume that the field size given to the program always matches the size in the file. The field will be given to your program in an ASCII text file, looking very much like the one above (but of proper size). Upon opening the file, your program must find the entrance. As your program attempts to find a path through the field, it should place the character X into each square in the path. Note that your program MUST NOT replace a 1 (an obstacle) with an X. Only zeroes can be replaced by X’s.

Before exiting, your program must display the traversed path, that is, the path between the entrance and the exit (the path is marked by X’s). Your program must also report whether the path was found or not.

In case of the field from the figure above, the path could not be found and your program would provide the following output:

1 1 1 1 1 1 1 1 1 1 1 1 1 X X X 1 X X X X 1 0 1 X X 1 X 1 X 0 0 X 1 0 1 1 1 X X 1 X 0 0 X 1 0 1 1 X X X X X 1 1 X 1 0 0 1 1 1 1 X 0 1 1 X 1 0 1 1 0 1 1 X 0 1 1 X 1 0 1 1 1 1 1 X 0 1 1 X 1 0 1 1 X X X X X 0 0 X 1 0 1 1 1 1 1 1 X 0 0 X 1 0 1 1 X X X X X X X X 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1

No path found.

Submitting Your Assignment In order to be graded, you must submit the following:

  1. Submit all the program files following the procedure described in my Web page (http://www.csee.wvu.edu/~cukic/CS350 follow the link “How to submit programming assignments”). Programs submitted through e-mail will be rejected! It is your responsibility to submit programs successfully. Do not submit your programs before Monday, September 8 th. 2. Submit program documentation in class on Thursday, September 18th^. The documentation consists of a short description of your algorithm (not more than a page long), description of program’s main data structures (did you represent the field by an array? Are the elements of the field characters or integers, etc). If your program does not work properly or if it does not compile, you are requested to state this _clearly in the documentation (what works, what doesn’t).
  2. Submit the listing of your code with the documentation_. Use a small font for printing your code. Please make sure that your program is well documented. Use inline comments (comments in your code) to explain what certain part of your program does. The header of the file (the comment on the top of your program file) MUST contain your name, student ID, and your account name. I will not grade your assignment unless I have program documentation, and code listing.

Programs, written in C, must compile using gcc compiler on LCSEE Linux cluster (shell.csee.wvu.edu). To receive full credit, your program must be submitted by the deadline. Please note that UNIX keeps track of the submission time. You are advised to keep a copy of your submission in your own account (with the original time-stamp). Remember that late assignments will be penalized by 5% of the grade for each day of delay (including weekend days). No assignment will be accepted after 11:59PM, Friday, September 19th^. Programs that cannot be compiled will receive up to 30% of the assignment grade. Only well written, well documented, nicely structured, fully functional programs, will receive a full credit.

Academic Honesty:

Each student in the class is expected to develop his/her assignment alone. Do not share programs, or program parts, with your colleagues. Violators of this policy will be held responsible for academic dishonesty, and will bear consequences in accordance to the rules and regulations of West Virginia University.