You are on page 1of 2

Week 1

1. Write a program that reads an integer value from standard input into a variable.

2. Assume that x is a float variable to be scanned. Write a statement that prints it out with exactly three
digits to the right of the decimal point no matter what how big its value is.

Example Input: Example Output:


250.563782963 250.564

3. Consider the following codes: what values are printed?


4. Consider this code: "int s = 20; int t = s++ + --s;".
What are the values of s and t?

5. Write a program that reads the dimensions of room A (width and length) and the
dimensions of room B (width and length) into two other variables. Write a
single expression whose value is the total area of the two rooms AND print the final
value. Write a single expression whose value is the average area of the two rooms AND
print the final value.

Example Input: Example Output:


10 42.5
2.5 21.25
5
3.5

6. Write programs called PrintPatternX.cpp (where X from A to D) to print EACH of the following
patterns. Use one "cout <<" for each line of outputs. End each line by printing an "endl"

Print the above patterns using ONE "cout <<" statement.

7. Write a program called CircleComputation.cpp that asks the user for the radius of a
circle and compute its area and circumference.

8. Write a program called IntegerArithmetic.cpp that asks the user for two integers and
prints their sum, difference, product, and quotient.

9. Write a program called NumberofTrees.cpp that asks the user to enter two integers
(length and width) of a rectangular piece of land in meters. If you know that the tree
needs 2 m2. How many trees could be planted in the given land (the number of trees
could not be in decimal).

You might also like