CMIS 140
Lab exercise
Download the all example programs from
http://sensei.ad.umuc.edu/dwills/cmis140/140cpp.zip
Create a folder on E(F?):cmis140 and unzip the files into it.
Compile and run the quad2.cpp
Test it with various inputs so that ALL paths thru it are used:
0 for 'a' multiple times
1 1 1 for the negative discrminant case (0 solutions)
1 2 1 for the one solution case
1 4 1 for the two solutions case
Compile and run the quadbad.cpp Note that is really is only 3 lines
long.
Back to quad2.cpp. Modify it so that the user can enter either yes or
y to loop again. (Hint: again will be a string).
Optional:
Add "check your work" code, as you would do in algebra:
a x squared plus b x plus c (i.e. ax2+bx+c) is supposed to equal 0
after you've solved for the x. So have one or two expressions that do
the quadratic equation with the calculated x's. Note that the
calculated results don't always equal the mathematical result of 0.
**********************************************
Write a program that will add time intervals together. The user
will first enter a number that tells how many lengths of time the user
will then enter. The user then enters sets of three values
representing hours, minutes and seconds. The program will sum all the
time values that the user enters.
Ex.
user enters:
3 meaning there will be three time lengths input
2 34 16 meaning 2 hours, 34 minutes, 16 seconds
0 23 100 0 hours, 23 minutes, 100 seconds (seconds can be more than 59)
1 1 1 1 hour, 1 minute, 1 second
program then outputs:
3 59 57 meaning those values total 3 hours, 59 minutes, 57 seconds
Optional:
After you've got that working, add the ability to input the time
values from a file whose format is the same as the interactive input.
Ask the user if s/he wants to input interactively or from a file.
Optional:
If you've read about, or know about the for loop, or are eager to
learn about it, use it instead of the while loop to accomplish the
above.
A for loop is the most appropriate loop when the number of iterations
is known. In this program, when the user has entered the number of
numbers, the number of iterations will be known, thus a for loop is
stylistically preferable to a while loop.
Ok. If you've done all that, let's do another time-oriented program.
Have the user enter two times in HH:MM:SS format and then determine
and output the difference between them. Reject invalid times like
11:64:12.
If the user enters:
4:24:19 and 21:53:6
the program outputs:
17:28:47
***************************************
Experiment with the overflow.cpp program to convince yourself
of the range of ints.
Modify it to find the range of long ints and unsigned long int.
Find the minimum and maximum values of int, long int, and
unsigned long int.
***************************************
Write a program that multiplies a bunch of numbers the user
enters. The user can enter any number of numbers. A 0
indicates the end of the sequence of numbers. Display
the product as is and with 4 digits tothe right of the
decimal point.
Ex
user enters:
5 -3 6.3 0
program outputs: -94.5
-94.5000