|
|
|
|
|
CS 121
Programming Assignment 1
Assignment Date: Tuesday, February 5
Due Date: Tuesday, February 19
DDD: Tuesday, February 26
|
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:
-
Creating a project in Visual C++, adding a source code file
to the project, adding code to the source code file, compiling,
and running the program.
-
Defining variables of any of the basic C++ data types, and
setting values in those variables. This includes the char,
short, int, long, float, double, and bool data types and the
string object.
-
Using the cout command to output information to the screen.
-
Performing simple mathematical calculations using the basic math
operators +, -, *, /, and %.
-
Performing mixed type mathematical calculations in which parentheses
are required to ensure the correct order of the calculation is
preserved.
-
Performing more complex mathematical calculations which involve
calling special math functions in the math library defined by
including the math.h header file.
-
Including comments in the source code which provide adequate
documentation of what the program is doing.
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_1 or ProgAssignment_1.
-
Add a .CPP source code file to the project. You can name the source file
something like Prog1Main.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 1
* 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 number of permutations of a set of n items taken r at a time is
given by the following formula:
where n! is the factorial of n (the product of all the numbers up
to the number itself multiplied together).
If there are 18 people in your class and you want to divide the class into programming teams
of 3 members, you can compute the number of different teams that can be arranged using this formula.
Write a C++ program that determines the number of potential team arrangements. You will need to use
double type variables, not int. Be sure to use proper formatting and appropriate comments in your code.
The output should be labeled clearly and formatted neatly. Note: Do not use Stirling's formula for
this program (see program option 2).
-
The factorial of a number n (written n!) is the product of all the numbers up
to the number itself multiplied together. For example the factorial of 2 is 1 * 2, the factorial of
4 is 1 * 2 * 3 * 4, etc. Factorials grow very large, very quickly. An approximation to
the factorial for larger values is given by Stirling's formula:
The exp function in the math.h header file gives the value of e raised to a given power.
Write a C++ program that computes the factorial of 15 both directly and with Stirling's formula,
and outputs both results, together with their difference.
Be sure to use proper formatting and appropriate comments in your code.
The output should be labeled clearly and formatted neatly.
(Hint: When you calculate 15! the
long way, i.e. 1*2*...*15 you will need to use double values (1.0 * 2.0 * 3.0, etc.) not
integer values (1 * 2 * 3, etc.) to avoid an "integer overflow" warning from the compiler.)
-
Write a C++ program that computes the mean and standard deviation of a set of four integer
values (use the values 85, 72, 90, and 78). The four values should be stored in double
variables which are used in the calculations. The mean is the sum of the four values
divided by 4, and the formula for the
standard deviation is:
Where n = 4, xi refers to each of the four values, and
is the mean. Translated this means subtract the mean
from each score then square that difference. Add up those four values, divide by (n-1),
then take the square root of the result using the sqrt function in math.h.
Be sure to use proper formatting and appropriate comments in your code.
The output should be labeled clearly and formatted neatly.
|
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.
|