0% found this document useful (0 votes)
61 views

Practical No: 2: Exercise

This document provides examples and exercises for practicing C++ statements, including: 1) Declaring variables, prompting user input, reading input, and printing output 2) A program to calculate and output the product of three integers 3) Examples of printing output from expressions and variables 4) A program to input a radius and output the diameter, circumference, and area of a circle

Uploaded by

Ameer Jaan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views

Practical No: 2: Exercise

This document provides examples and exercises for practicing C++ statements, including: 1) Declaring variables, prompting user input, reading input, and printing output 2) A program to calculate and output the product of three integers 3) Examples of printing output from expressions and variables 4) A program to input a radius and output the diameter, circumference, and area of a circle

Uploaded by

Ameer Jaan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

PRACTICAL NO : 2

EXERCISE

1. Write a single C++ statement to accomplish each of the following

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.

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.
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.

3. 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;
PRACTICAL NO : 2
f. z = x + y;
g. cin >> x >> y;
h. // cout << "x + y = " << x + y;
i. cout << "\n";

4. 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 π.

You might also like