LAB01

advertisement
CS110 Lab 1: First programs
Due by Tuesday, September 24, 2013
This lab assignment will require you to write four programs in C++.
Goals
-
:
To understand the C++ environment.
To write simple computer programs in C++.
To write simple input and output statements.
To use fundamental types.
To write simple decision-making statements in C++.
Your programs are graded on both correctness and style. Please review the comments regarding
programming style on the main page.
1. Write the Word "WELCOME TO C++"
- Write a program that print the word "Welcome To the C++".
2. Pounds to Kilograms Conversion
One pound is equivalent to 0.45359 kilograms. write a program to convert a weight given in pounds to its
equivalent weight in kilograms. Here are some sample runs:
This program converts pounds to kilograms.
Enter a weight in pounds: 125
125 pounds is equivalent to 56.69875 kilograms
This program converts pounds to kilograms.
Enter a weight in pounds: 200
200 pounds is equivalent to 90.718 kilograms
3. Print Cubes
Write a program that asks the user for an integer n and then prints all of the cubes between 1 and n inclusive.
Here are some example runs of a working program:
This program prints the cubes of 1 to n
Enter a value for n: 10
1 8 27 64 125 216 343 512 729 1000
This program prints the cubes of 1 to n
Enter a value for n: 4
1 8 27 64
It is okay if your program prints one cube value per line rather than all values on the same line as shown
below:
This program prints the cubes of 1 to n
Enter a value for n: 3
1
8
27
4. Exchange Rate Conversion Table
On October 23, 2013, 1 US Dollars was worth 3.751 SA Riyal. Write a program that prints a conversion
table of Riyal to US Dollars. The user will enter a starting and ending dollar value for the range of
conversions to print.
To get the values to line up in columns you can print out one or more tab characters ("\t") between printing
the two amounts on each line. For example, try these print statements in python and see what happens:
print 3, "\t\t", 4
print 3, "\t", 4
Don't worry about getting the decimal points to line up for values with different numbers of digits before the
decimal point (e.g. 99.123 and 999.123). We will learn how to do that later this semester.
Here are some example runs of a working program:
This program prints a conversion table for SAR to US Dollars.
Enter the starting SAR amount: 10
Enter the ending SAR amount: 18
SAR
US Dollars
10
2.666
11
2.933
12
3.200
13
3.466
14
3.733
15
4
16
4.266
17
4.532
18
4.799
This program prints a conversion table for SAR to US Dollars.
Enter the starting SAR amount: 70
Enter the ending SAR amount: 76
SAR
US Dollars
70
18.663
71
18.929
72
19.196
73
19.462
74
19.727
75
19.993
76
20.260
Submit
Once you are satisfied with your programs, Save them in your document that has your name. and send it to
me by the end of this weekend.
NOTE
You will loss marks for late submission .
Grade
This Lab worth 10 marks 7 for correctness and 3 for style.
BEST WISHES ☺☺
NISREEN ALZAHRANI
Download