|
|
|
|
|
CS 121
Programming Assignment 3
Assignment Date: Tuesday, March 12
Due Date: Thursday, April 4
DDD: Thursday, April 11
|
Instructions
|
|
Below you will find descriptions of a number of simple programs.
Each of these programs assumes you have already had some experience
with each of the following C++ programming techniques or commands
in addition to those listed for programming assignments 1 and 2:
-
C++ operators +=, -=, *=, /=, %=, ++, --, <<, >>, &, |, ^,
and ~ in addition to those covered earlier in the
course. .
-
Creating and using functions including void and value returning
functions and functions whose parameters include incoming,
outgoing, and incoming/outgoing types.
-
One-dimensional and two-dimensional arrays.
You are to select one of the following programs to write. Follow this basic
procedure:
-
Create a new project in Visual Studio. You may call the program anything
you wish. Many students like to keep it simple and just call the project
something like Program_3 or ProgAssignment_3.
-
Add a .CPP source code file to the project. You can name the source file
something like Prog3Main.cpp. Place your main() function
in this file.
-
When you have completed writing the code, compile the program. If the
program does not compile look carefully at the errors listed by the
compiler and fix those errors. Also pay attention to the warnings
the compiler gives you.
-
When your program compiles, run it and test it thoroughly to make sure
it is working correctly. Do not turn in your program till it is
fully tested and you know the output is correct based on the inputs.
Just because you get an output does NOT mean the program
is working correctly. The instructor will compare your program's
output to the known correct output. If it does not match you will
get no credit.
-
When you are sure the program is working correctly e-mail your program
file (the .cpp file) to the instructor. Make sure you are sending the
.cpp file and not another file. See the Submit Projects link on
the web page for details.
Remember you must include the following comment at the top of your source file.
If you do not place this at the top of your file your program will not be accepted.
/*******************************************************************
* CS 121 Programming Assignment 3
* File: Source Code File Name
* Author: Your Name
* Desc: A brief description of what the program does.
* Date: Date file was submitted to the instructor
*
* I attest that this program is entirely my own work
*******************************************************************/
|
Program Options
Select one of the following programs to complete.
|
|
-
The International Civil Aviation Organization Alphabet is a series of
words which are used to represent each letter of the alphabet. These
are used in critical radio communications between airplanes and ground,
and between airplanes in flight to avoid misunderstanding. The code
words are given in the list below:
Letter
|
Word
|
Letter
|
Word
|
A
|
Alpha
|
N
|
November
|
B
|
Bravo
|
O
|
Oscar
|
C
|
Charlie
|
P
|
Papa
|
D
|
Delta
|
Q
|
Quebec
|
E
|
Echo
|
R
|
Romeo
|
F
|
Foxtrot
|
S
|
Sierra
|
G
|
Golf
|
T
|
Tango
|
H
|
Hotel
|
U
|
Uniform
|
I
|
India
|
V
|
Victor
|
J
|
Juliet
|
W
|
Whiskey
|
K
|
Kilo
|
X
|
X-ray
|
L
|
Lima
|
Y
|
Yankee
|
M
|
Mike
|
Z
|
Zulu
|
Write a C++ program that inputs a string and output a series of
ICAO words that would be used to spell it out. For example:
Enter string: Program Test.
Phonetic version is: Papa Romeo Oscar Golf Romeo Alpha Mike Tango Echo
Sierra Tango
Note that there is a space in the string being translated and letters
can be entered either upper or lower case. Any characters other than
alphabet or the space should be ignored.
You should create a function called BuildCodeArray to build an
array of strings of the ICAO words.
You should create a second function called TranslateString that
takes a string and translates it into the ICAO spelling.
After printing the ICAO words the application should ask the user if
they want to translate another string and continue looping until the
user indicates they do not want to translate another string.
Be sure to use proper formatting and appropriate comments in your code.
Provide appropriate prompts to the user. The output should be clearly
labeled and neatly formatted.
-
Write a number-guessing game in which the computer selects a random
number in the range 1 to 100, and users get a maximum of 20 attempts to
guess it.
After each guess there should be some hint given to the player
as to how close that guess was. If the guess was only 1 away print
a hint like "That guess was hot". If the guess was within 5 points
(high or low) print a hint like "You're getting warm". If the guess
was within 10 points print a hint like "Your guess is still cool".
If the guess was more than 10 points away print a hint like "You're
guess is cold".
At the end of each game, users should be told whether they won
or lost, and how many guesses it took if they got it correct.
To make the game more interesting, the program should vary the wording
of the messages that it outputs for winning, for losing, and for asking
for another game. Create as many as 5 different messages for each of
these cases and use random numbers to choose among them. You should
put this functionality in two functions called SayYouWon and
SayYouLost
At the end of each game the player should then be asked if they want to
play again. The user should be allowed to play as many games as
desired. When the user quits, the program should output the total
number of wins and losses.
You should ceate a third function called CheckGuess that takes the
player's current guess and the number selected by the computer and
prints an appropriate response as described above. It might be
useful to have the function return a boolean value; true if the
player guessed the number and false if not.
You should create a fourth function called GetRandomNumber that
generates and returns a
random number when passed the range in which to select the
random number.
To generate a random number you must include one header file:
#include <stdlib.h>
You will also need the time header file if you want to use time to seed
the random number generator.
#include <time.h>
Somewhere at the beginning of the program you will need to make one
and only one call to the srand
function to seed the random number generator. It requires an unsigned
int value to be passed to it. The easiest way to insure that this is
a relatively random seed number is to pass in the current time in seconds.
srand((unsigned int)(time(NULL)));
To generate a random number between a 1 and 100 use the
following. Assume that value is an int. The rand()
function generates values between zero and RANDMAX.
value = rand() % 100 + 1; // Generate random numbers from 1 to 100
// FYI: A more generic function will find a random number in
// a range from low to high with: rand() % (high - low + 1) + low;
This application should provide a good opportunity for you to use a
do...while statement and switch statements. Write your
C++ code using good style and documenting comments, and have fun thinking up
some messages that will surprise the player.
-
You are working for a company that lays ceramic floor tile, and its
employees need a program that estimates the number of boxes of tiles
need for a job.
A job is estimated by taking the dimensions of each room in
feet and inches, and converting those dimensions into a multiple of
the tile size (rounding up any partial multiple) before multiplying
to get the number of tiles for the room.
A box contains 20 tiles, so the total number needed should be divided
by 20 and rounded up to get the number of boxes. The tiles are assumed
to be square.
The program should initially prompt the user for the size of the tiles
in inches and the number of rooms to be covered with tile. It should
then input the dimensions for each room in feet and inches.
After the dimensions for each room have been input then calculate and
output the number of tiles needed for each room, the total number of
tiles needed for all rooms, the number of boxes of tiles needed, and
how many extra tiles will be left over.
You should create a function called TilesInRoom that will take
the size of one tile, and the width and length of a room and return
the number of tiles it will take to cover that room. The number of
tiles should be rounded up to the nearest whole number.
Here is an example of how a run might appear:
Enter the number of rooms in the job: 2
Enter the size of each tile in inches: 12
Enter room 1 width (feet and inches, separated by a space): 17 4
Enter room 1 length (feet and inches, separated by a space): 9 3
Room 1 requires 161 tiles.
Enter room 2 width (feet and inches, separated by a space): 11 6
Enter room 2 length (feet and inches, separated by a space): 11 9
Room 2 requires 136 tiles.
The 2 rooms in this job will require 297 tiles.
The number of boxes of tiles needed is 15.
There will be 3 extra tiles left over.
Note: Do not assume that the instructor will enter only 2 rooms when testing
your program.
|
A word of caution:
-
Your programming assignment must be your own work. Do not ask
someone else to help you or to do the assignment for you. If you
are having trouble please see the instructor and he will be glad
to help.
-
If you copy someone else's code or let someone else
copy your code you will both receive a zero for this assignment
and could receive an F for the course as well as having the
incident of cheating reported to the Dean.
|