Chris Pollett>Old Classes>PIC 10a, Spring
2000>Hw1
Program in
Computing
PIC 10A: Introduction to Programming
Homework 1: Friday, April 14 10:30 a.m.
The purpose of this assignment is twofold: to get you used to the
Visual C++ programming environment, and to give you practice with
some basic data types, arithmetic, and conditionals.
Part A
- Make sure you have your PIC Lab NT account.
- If you like, create your Visual C++ workspace before starting this
project, following the instructions in the
Getting Started Guide.
Or, if you prefer, you can start Visual C++
and start writing your program, and create the workspace the first time you
save your source code, as described in the Supplement to your
text.
Part B
Create a program named pic10ahw1.cpp
(for this assignment you only need to put this one file in your
\submit directory) that converts between various measurement units
according to the following specifications:
- The program starts by giving the user a menu of 4 conversion
choices: slugs to kilograms, kilograms to slugs, degrees Kelvin to
degrees Farenheit, and degrees Farenheit to degrees Kelvin. It then
asks the user to enter a number.
- Depending on the choice, the program asks the user to input
his/her weight in slugs or kilograms or the temperature in Kelvin or
Farenheit, and then converts into the other unit of of measurement.
One slug is equal to 14.594 kilograms, and x degrees Kelvin is
9(x - 273)/5 + 32 degrees Farenheit (you'll have to rearrange this
to do the conversion from Farenheit to Kelvin).
- If the user enters a weight less than or equal to 22.725 kg,
the program should
tell the user to eat more; if the user enters a temperature less than 0 degrees
Farenheit, it should tell the user to wear a sweater.
- The variables you use for weights must be double's.
Furthermore,
the conversion factor from slugs to kilograms must be stored in a variable
of type
double that is initialized in its
declaration.
- The variable you use for inputting the temperature must be
an int, but the output should be a double (and the
arithmetic must be accurate).
- The program should output an error message if the user types in a
choice other than 1, 2, 3, or 4.
Here are some sample runs of the program; the output of your program
must look exactly the same.
What would you like to convert?
1. Slugs to kilograms.
2. Kilograms to slugs.
3. Degrees Kelvin to degrees Farenheit.
4. Degrees Farenheit to degrees Kelvin.
Enter your choice -> 1
How many slugs do you weigh? 1
You weigh 14.594 kilograms.
You need to eat more!
What would you like to convert?
1. Slugs to kilograms.
2. Kilograms to slugs.
3. Degrees Kelvin to degrees Farenheit.
4. Degrees Farenheit to degrees Kelvin.
Enter your choice -> 3
What is the temperature in degrees Kelvin? 274
That is 33.8 degrees Farenheit.
What would you like to convert?
1. Slugs to kilograms.
2. Kilograms to slugs.
3. Degrees Kelvin to degrees Farenheit.
4. Degrees Farenheit to degrees Kelvin.
Enter your choice -> 4
What is the temperature in degrees Farenheit? -5
That is 252.444 degrees Kelvin.
You should probably wear a sweater today.
Homework 1 FAQ.
Homework 1 Solution.