Name: __________________________
CS 0449: Lab 2 – Console I/O in C
As we’ve learned in class, in C the size of data types are not exactly defined. In this lab, you will write a program that displays the size of the various data types.
Using the sizeof() keyword, determine the size of the following data types:
int
short
long
long long
unsigned int
char
float
double
long double
Have the output be displayed to the screen in the following tabular (use tabs to align the column of sizes) format:
int 4 bytes
.
.
.
When you are done, we can use a feature of the UNIX shell to submit the output. Text that is displayed to the screen in UNIX can be captured into a file using the > (redirection) command.
Run your program like (assuming you named the output file “lab2a”):
./lab2a > lab2a.txt
And now the file lab2a.txt will contain the output, and the screen will be empty. You can open lab2a.txt in pico to check the output.
Hint:
· Look at your first lab for information on how to compile and run a program
You may remember from high school science that while mass is a constant, your weight is actually dependent on your mass multiplied by how strong the gravitational pull of the planet is. So if you were to travel to different planets, your weight would change. In this lab, you are asked to compute just how much someone would weigh on the other planets in our solar system.
Here is the table of relative gravitational strength as compared to earth:
Planet |
Relative Strength |
Mercury |
0.38 |
Venus |
0.91 |
Mars |
0.38 |
Jupiter |
2.54 |
Saturn |
1.08 |
Uranus |
0.91 |
Neptune |
1.19 |
What you need to do
Your task is to write a program which:
· Asks the user to input a weight
· Displays that weight scaled appropriately on each of the other 8 planets
Example
Please enter the weight you’d like to convert: 100
Here is your weight on other planets:
Mercury 38 lbs
Venus 91 lbs
Mars 38 lbs
Jupiter 254 lbs
Saturn 108 lbs
Uranus 91 lbs
Neptune 119 lbs
Pluto 6 lbs
Redirect the output to a file named lab2b.txt
tar cvf USERNAME_lab2.tar *.txt
gzip USERNAME_lab2.tar
cp USERNAME_lab2.tar.gz ~jrmst106/submit/449