CP Lab 3

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

19CS78

Roll No. _19CS78_ Date of Conduct: _______________________

Submission Date: _________________________ Grade Obtained:


________________________
LAB DATA ANALYSIS ABILITY TO
SUBJECT CALCULATION OBSERVATION/R
PERFORMANCE AND CONDUCT PRESENTATION SCORE
KNOWLEDGE AND CODING ESULTS
INDICATOR INTERPRETATION EXPERIMENT

EXERCISE 03

1. Write a single C++ statement to accomplish each of the following (assume that
using directives have not been used):

a. Declare the variables c, thisIsAVariable, q76354 and number to be of type int.


b. Prompt the user to enter an integer. End your prompting message with a colon (: )
followed by a space and leave the cursor positioned after the space.
c. Read an integer from the user at the keyboard and store it in integer variable age.
d. Print the message "This is a C++ program" on one line.
e. Print the message "This is a C++ program" on two lines. End the first line with C++.
f. Print the message "This is a C++ program" with each word on a separate line.
g. Print the message "This is a C++ program". Separate each word from the next by a
tab.

1
19CS78

2. Write a statement (or comment) to accomplish each of the following (assume


that using directives have been used for cin, cout and endl ):

a. State that a program calculates the product of three integers.


b. Declare the variables x, y, z and result to be of type int (in separate statements).
c. Prompt the user to enter three integers.
d. Read three integers from the keyboard and store them in the variables x, y and z.
e. Compute the product of the three integers contained in variables x, y and z, and
assign the result to the variable result.
f. Print "The product is " followed by the value of the variable result.
g. Return a value from main indicating that the program terminated successfully.

2
19CS78

3. Using the statements you wrote in Exercise 2, write a complete program that
calculates and displays the product of three integers. Add comments to the
code where appropriate. [Note: You’ll need to write the necessary using
directives.]

4. What, if anything, prints when each of the following C++ statements is


performed? If nothing prints, then answer “nothing.” Assume x = 2 and y = 3.

a. cout << x;
b. cout << x + x;
c. cout << "x=";
d. cout << "x = " << x;
e. cout << x + y << " = " << y + x;
f. z = x + y;
g. cin >> x >> y;
h. // cout << "x + y = " << x + y;
i. cout << "\n";

3
19CS78

5. Write a program that asks the user to enter two numbers, obtains the two
numbers from the user and prints the sum, product, difference, and quotient
of the two numbers.

6. Write a program that prints the numbers 1 to 4 on the same line with each
pair of adjacent numbers separated by one space. Do this several ways:

a. Using one statement with one stream insertion operator.


b. Using one statement with four stream insertion operators.
c. Using four statements.

4
19CS78

7. Write a program that reads in the radius of a circle as an integer and prints
the circle’s diameter, circumference and area. Use the constant value 3.14159
for π. Do all calculations in output statements.

8. Write a program that prints a box, an oval, an arrow and a diamond as follows:

5
19CS78

9. The formulas for calculating Body Mass Index (BMI) are

Create a BMI calculator application in C++ that reads the user’s weight in
pounds and height in inches (or, if you prefer, the user’s weight in kilograms
and height in meters), then calculates and displays the user’s body mass
index.

You might also like