0% found this document useful (0 votes)
56 views7 pages

Exercise CSC415

try3

Uploaded by

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

Exercise CSC415

try3

Uploaded by

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

CSC415

FUNDAMENTALS OF COMPUTER PROBLEM SOLVING

EXERCISE

PART A

1. Describe statement demonstrates the appropriate way to declare and initialize a variable
name employee to 0?

A. double employee;
B. double employee = 0;
C. int employee;
D. int employee = 0;

2. Which of the following statements are TRUE in C++?


I. A semicolon is used to terminate the statement.
II. Commas are used to separate items, example of variables declaration.
III. Space is used to input separate numbers
IV. Brackets are used to enclose the body of a function or a program segment

A. I, II, III
B. I, II, IV
C. II, III, IV
D. I, II, III, IV

3. Given the following variables declaration:


int w = 3, x = -5 , y = 3, z = 500;
Select which of the following Boolean expression is TRUE?

A. y > x && y > z


B. z > 100 || w != y
C. y == w && z < x
D. y * 200 < z

4. Text in the /* */ will

A. give command to preprocessor


B. cause syntax error
C. serve as documentation to human reader
D. declare some memory location

5. What would be the best choice for the data type for a person’s take home pay?

A. int
B. float
C. char
D. string
6. Which of the following statements is correct?

A. float num1; num2;


B. int day, night;
C. int blue = 5.0;
D. string black = ‘white’;

7. What is the value of the following arithmetic expression if the variables have these values:
p = 5; s = 20; x = 6;
p+3*x–s

A. -37
B. 3
C. 28
D. 59

8. There is no limit on the size of the numbers that can be stored in the int data type.
A. True
B. False

9. There are only two possible values for the bool data type.
A. True
B. False

10. Show the output display by the statement.


cout<<sqrt(pow(3, 2) + sqrt(49));
A. 4
B. 7
C. 9
D. 16
PART B

Question 1

Convert the following arithmetic equations into C++ assignment statements (Hint: can use
mathematical functions)

i.

ii.

iii. Z= (

Question 2:
Suppose x, y, z are int variables and x = 5 and y = 6. What value is assigned to each variable after
each statement executes? If a variable is undefined at a particular statement, report UND
(undefined).
x y z
x= (y++) + 3;

z= 2* x + (++y);

y= 2 * (++z)- (x++)

Question 3

Trace the following program and determine the output.

a) int a = 11, c = 4, b;
double jumlah;

b = 20 + c;
c = ( b + 3 ) % c + 3;
cout<< "Value c is:" << c << " and b is: "<< b <<endl;

a = a + c;
jumlah = a / 2;
cout<< jumlah <<" is the value of jumlah. " <<endl;
b) int category = 2;
switch (category)
{
case 1 : cout<< “ Pelajar sahaja ”;
case 2 : cout<< “ Pensyarah sahaja ”;
case 3 : cout<< “ Kakitangan Kontrak sahaja ”; break;
default : break;
}

c) product = 0; value = 33;


if (value > 99)
cout << ”Invalid value”;
else
{
cout << ”Calculate the product of value : ” << value;
product = value * value;
cout << “The product is : << product;
}

Question 4
Trace the following program and determine the output. [

a)
int bmi; OUTPUT
cout << “\n Enter BMI value “;
cin >> bmi;
if (bmi >=0 && bmi <=7)
cout<<”Thin”<<endl;
if (bmi >=8 && bmi <=10)
cout<<”Slim”<<endl;
if (bmi >=10 && bmi <=19)
cout<<”OK”<<endl;
if (bmi >=20)
cout<<”Fat”<<endl;

The input is 15.


b)
OUTPUT
int a, b, c, d;
a = 4;
b = 12;
c = 37;
d = 51;

if ( a < b )
cout << "a < b" << endl;
if ( a > b )
cout << "a > b" << endl;

if ( d <= c )
cout << "d <= c" << endl;

if ( c != d )
cout << "c != d" << endl;

c)
int x = 12; OUTPUT
if (x > 12)
{if ( x < 15)
cout << "HELLO";}
else
cout << "BYE";
cout << "FRIEND";
Question 5

Convert the following flowchart into C++ program


Question 6

Write a complete C++ program that display the following prompts:

Enter the radius :


Enter the height :

The volume of the cylinder is :

Let user input the value for radius and height. After that you calculate the volume of a cylinder using
the values. Use the formula:

volume = pi x radius2 x height

Set value pi as 3.1416.

You might also like