Introduction to System Software - Programming Assignment 2 | COE 0449, Assignments of Engineering

Material Type: Assignment; Class: INTRO TO SYSTEMS SOFTWARE; Subject: Computer Engineering; University: University of Pittsburgh; Term: Unknown 1989;

Typology: Assignments

Pre 2010

Uploaded on 09/02/2009

koofers-user-9dj-1
koofers-user-9dj-1 🇺🇸

7 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS/COE 0449
Introduction to Systems Software & Programming
Programming Assignment–2
Due: Sunday Feb. 4th by 11:59pm--submitted electronically
Directions: Submit an electronic copy of this assignment to the course ftp-submission site.
Pack all the assignment files to a FirstName_LastNameAssign2.zip file, using WinZip or a similar application.
Submit the zipped package by using the computer science department's anonymous FTP server
(cs.pitt.edu/incoming/CS449/ or ftp://ftp.cs.pitt.edu/incoming/CS449/). Please make sure submit your
project to the proper section (449MWClass or 449THClass) and store it under Assign2 directory.
Submission must be before the due date, otherwise, it will be considered late. Once you submit, you can't
take the file back! Therefore, please submit your final program and only one time.
Submission Directions
1- Name all the files a unified names: exc1.c, exc2.c... if a question has
several parts: exc5a.c, exc5b.c,...
2- Don't include .exe files because we are compiling under UNIX.
3- The name of the folder is the full name of the student: firstName_LastName
4- Don't include more than one folder...
5- Compile your programs using gcc "because we are using is standard C".
A number of students are submitting files with .cpp files or .c but this runs only using g++.
1. Problem.1: (Towers of Hanoi) Every budding computer scientist must grapple with
certain classic problems, and the Towers of Hanoi of Hanoi is one of the most famous of these.
http://en.wikipedia.org/wiki/Tower_of_Hanoi
The legend-framework for "the towers of Hanoi" problem supposes there to be three pegs and
several disks all of different diameters that can be stacked up on the pegs. The restriction is that
any disks stacked on a peg must be arranged so that smaller disks are above larger disks. The
problem is how, starting with all the disks stacked on one peg, to move them all to another peg
one disk at a time, observing the stacking restriction at each move. The problem is generalized to
any number of disks
The initial stack had 64-disks threaded onto one peg and arranged from bottom to top by
decreasing size. Moving the stack from this peg to a second peg is done under the constraints that
exactly one disk is moved at a time, and at no time may a larger disk be placed above a smaller
disk. A third peg is available for temporarily holding the disks.
Let us attempt to move the disks from peg1 to peg3. We wish to develop an algorithm that will
print the precise sequence of disk-to-disk peg transfers. If we were to approach this problem with
conventional methods, we would rapidly find ourselves hopelessly knotted up in managing the
disks. Instead, if we attack the problem with recursion in mind, it immediately becomes
pf3

Partial preview of the text

Download Introduction to System Software - Programming Assignment 2 | COE 0449 and more Assignments Engineering in PDF only on Docsity!

CS/COE 0449

Introduction to Systems Software & Programming

Programming Assignment–

Due: Sunday Feb. 4th^ by 11:59pm--submitted electronically Directions: Submit an electronic copy of this assignment to the course ftp-submission site.

 Pack all the assignment files to a FirstName_LastNameAssign2.zip file, using WinZip or a similar application.

 Submit the zipped package by using the computer science department's anonymous FTP server

(cs.pitt.edu/incoming/CS449/ or ftp://ftp.cs.pitt.edu/incoming/CS449/). Please make sure submit your project to the proper section (449MWClass or 449THClass) and store it under Assign2 directory.  Submission must be before the due date, otherwise, it will be considered late. Once you submit, you can't take the file back! Therefore, please submit your final program and only one time.

Submission Directions

1- Name all the files a unified names: exc1.c, exc2.c... if a question has

several parts: exc5a.c, exc5b.c,...

2- Don't include .exe files because we are compiling under UNIX.

3- The name of the folder is the full name of the student: firstName_LastName

4- Don't include more than one folder...

5- Compile your programs using gcc "because we are using is standard C".

A number of students are submitting files with .cpp files or .c but this runs only using g++.

1. Problem.1: (Towers of Hanoi) Every budding computer scientist must grapple with

certain classic problems, and the Towers of Hanoi of Hanoi is one of the most famous of these. http://en.wikipedia.org/wiki/Tower_of_Hanoi The legend-framework for "the towers of Hanoi" problem supposes there to be three pegs and several disks all of different diameters that can be stacked up on the pegs. The restriction is that any disks stacked on a peg must be arranged so that smaller disks are above larger disks. The problem is how, starting with all the disks stacked on one peg, to move them all to another peg one disk at a time, observing the stacking restriction at each move. The problem is generalized to any number of disks The initial stack had 64-disks threaded onto one peg and arranged from bottom to top by decreasing size. Moving the stack from this peg to a second peg is done under the constraints that exactly one disk is moved at a time, and at no time may a larger disk be placed above a smaller disk. A third peg is available for temporarily holding the disks. Let us attempt to move the disks from peg1 to peg3. We wish to develop an algorithm that will print the precise sequence of disk-to-disk peg transfers. If we were to approach this problem with conventional methods, we would rapidly find ourselves hopelessly knotted up in managing the disks. Instead, if we attack the problem with recursion in mind, it immediately becomes

tractable. Moving n disks can be viewed in terms of moving only n-1 disks (and hence the recursion) as follows: a) Move n-1 disks from peg-1 to peg-2, using peg-3 as a temporary holding area. b) Move the last disk (the largest) from peg-1 to peg-3. c) Move n-1 disks from peg-2 to peg-3, using peg-1 as a temporary holding area. The process ends when the last task involves moving n=1 disks, i.e. the base-case. This is accomplished by trivially moving the disk without the need for a temporary holding area. Write a program to solve the Towers of Hanoi problem. Use a recursive function with four parameters: a) The number of disks to be moved. b) The peg on which these disks are initially threaded. c) The peg to which this stack of disks is to be moved. d) The peg to be used as a temporary holding area. Your program should print the precise instructions it will take to move the disks from the starting peg to the destination peg. For example, to move a stack of three disks from peg-1 to peg-3, your program should print the following series of moves: 13 (this means move one disk from peg-1 to peg-3) 12 32 13 21 23 13 Important Note: any code taken from the Internet will result in a 0-grade and possible further actions.

2. Problem-2: (Airline Reservation System) A small airline has just purchased a computer for

its new automated reservation system. The president has asked you to program the new system. You are to write a program to assign seats on each flight of the airline’s only plane (capacity: 10 seats). Your program should display the following menu of alternatives: Please type 1 for “first class” Please type 2 for “economy” If the person types 1, then your program should assign a seat in the first class section (seats 1-5). If the person types 2, then your program should assign a seat in the economy section (seats 6-10). Tour program should then print the boarding pass indicating the person’s seat number and whether it is in the first class or economy section of the plane. Use a single-subscripted array to represent the seating chart of the plane. Initialize all the elements of the array to 0 to indicate that all seats are empty. As each seat is assigned, set the corresponding element of the array to 1 to indicate that the seat is no longer available.

Your program should, of course, never assign a seat that has already been assigned. When

the first class section is full, your program should ask the person if it is acceptable to be

placed in the economy section (and vice versa). If yes, then make the appropriate seat

assignment. If no, then print he message “Next flight leaves in 3 hours”.