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

IF, IF - Else, IF - Else If Statements

This document contains a C++ language quiz with multiple choice and code completion questions about basic C++ concepts like variables, data types, input/output, arithmetic operators, if/else statements, and functions. It includes 20 questions about concepts like declaring variables, using cin to take input, operator precedence, increment/decrement operators, and if/else statement syntax. The questions are part of an assignment to test a student's understanding of basic C++ programming.
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)
85 views

IF, IF - Else, IF - Else If Statements

This document contains a C++ language quiz with multiple choice and code completion questions about basic C++ concepts like variables, data types, input/output, arithmetic operators, if/else statements, and functions. It includes 20 questions about concepts like declaring variables, using cin to take input, operator precedence, increment/decrement operators, and if/else statement syntax. The questions are part of an assignment to test a student's understanding of basic C++ programming.
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/ 64

C++ Language

C++ ‫ﻟﻐـــــــــــﺔ‬
Dr. khaled Alwesabi

1 C++ Programing
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7

Fill in the blanks to declare variable a of type int and then assign 7as its value ?

____ a;

a_____7

bool

b. println a. int C. system d. =

2 C++ Programing
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7

How many times should a data type be mentioned for a variable?

a. When entering variable’s value using cin

b. Every where the variable is used

c. when printing a variable’s value

d. Only once : when declaring the variable

3 C++ Programing
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7

What is the purpose of cin?

a. includes a header file

b. print variable’s value

c. Take information (data) from the user

4 C++ Programing
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7

Type in a code to declare variable b and assign a’s value to b, and then print their
sum to the screen :

5 C++ Programing
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7

Type in the code that allows for entering a number and strong it in the variable a:

d. cin C. system a. cout b. println


6 C++ Programing
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7
Fill in the blanks to declare a variable var of type int , enter a value, and store it in
the variable var :

7 C++ Programing
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7

Type in a code to declare variable b and assign a’s value to b, and then print their
sum to the screen :

8 C++ Programing
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7

Fill in the missing parts of the code to declare sum as a variable, assign it the value
21 + 7, and print out its value :

9 C++ Programing
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7

Fill in the missing parts in the following code to print 12:

10 C++ Programing
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7

Which symbol is used to multiply variables in C++?

a. +
b. %
c. *
d. x

11 C++ Programing
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7

Fill in the blanks to declare variable x and assign it the value 81 divided by 3:

12 C++ Programing
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7

Which operator is used to determine the remainder?

a. *

b. +

c. %

d. &

13 C++ Programing
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7

Fill in the missing parentheses to have x’s value equal 14.

14 C++ Programing
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7

Which two statements are correct for arithmetic operations?

a. Subtraction is done first

b. Multiplication is done before addition

c. Parentheses first, then multiplication

d. Addition is done before multiplication

15 C++ Programing
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7

Fill in the missing parentheses to have x’s value equal 14.

16 C++ Programing
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7

X++ has the same meaning as:

a. X = x + 1;

b. X / = 17;

c. X = x – 4;

d. X *= 1

17 C++ Programing
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7

Fill in the blanks to increment x’s value by one using the ++ oprator and print its
value to the screen:

18 C++ Programing
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7

What’s the difference between ++x and x++? Select all that apply

a. ++x uses x’s value before incrementing;

b. ++x increments x’s value before using it ;

c. X++ uses x’s value then increments it ;

d. X++ increments x’s value before using it

19 C++ Programing
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7

Please type in a code that decrements x’s value using the – operator.

20 C++ Programing
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7

Please fill in the missing parts of the code to print “I love C++” on the screen.

21 C++ Programing
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7
Please type in a code that declares two variable of type int and parts their sum to
the screen.

22 C++ Programing
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7
In every C++ program : (Select all that apply)

a. Each variable must have its data type

b. Variables names should be either x or y

c. There must be a function named main

d. There must be at least two declared variables

23 C++ Programing
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7
What is the output of the following code?

24 C++ Programing
Lecture 4
IF , IF - Else , IF - Else If statements

25 C++ Programing ‫ﻋﻣﻠﻲ‬


Lecture 4
IF , IF - Else , IF - Else If statements
sequential execution transfer of control

26 C++ Programing ‫ﻋﻣﻠﻲ‬


Lecture 4
IF , IF - Else , IF - Else If statements

Selection (conditional) statement


1. if statement NO
is
2. if….else statements Condition True

3. Nested if statements
Yes

4. Switch statement Statement1

27 C++ Programing ‫ﻋﻣﻠﻲ‬


Lecture 4
IF , IF - Else , IF - Else If statements

28 C++ Programing ‫ﻋﻣﻠﻲ‬


Lecture 4
IF , IF - Else , IF - Else If statements

29 C++ Programing ‫ﻋﻣﻠﻲ‬


Lecture 4
IF , IF - Else , IF - Else If statements

30 C++ Programing ‫ﻋﻣﻠﻲ‬


Lecture 4
IF , IF - Else , IF - Else If statements

31 C++ Programing ‫ﻋﻣﻠﻲ‬


Lecture 4
IF , IF - Else , IF - Else If statements
Selection (conditional) statement(cont.)
If we wish to execute several statements if the condition is true,
use a block which is a set of statements enclosed in braces.

If (condition)
{
Statement 1;
Statement 2;
.
.
.
Statement n;
}

32 C++ Programing ‫ﻋﻣﻠﻲ‬


Lecture 4
IF , IF - Else , IF - Else If statements

if ( x > y )
false

if ( x > y )
true

33 C++ Programing ‫ﻋﻣﻠﻲ‬


Lecture 4
IF , IF - Else , IF - Else If statements

34 C++ Programing ‫ﻋﻣﻠﻲ‬


Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7
Which choice shows the correct syntax for the if statement in C++ ?

a. if ( test) { }

b. If test

c. If test

d. if { } ( test )

Write four different C statements that each add 1 to integer variable

35 C++ Programing
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7

Fill in the blanks to compare the variables and print “ hi there “ to the screen:

36 C++ Programing
Lecture 4
IF , IF - Else , IF - Else If statements

37 C++ Programing ‫ﻋﻣﻠﻲ‬


Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7

38 C++ Programing
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7

Which is the correct operator for equality testing?

a. =

b. ==

c. *=

d. <<

39 C++ Programing
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7

Fill in the blanks to compare the variables and print “ not equal “ to the screen:

40 C++ Programing
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7

Fill in the blanks to print the value of the greatest variable:

41 C++ Programing
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7

Fill in the blanks to check if the age variable is greater than 18 :

42 C++ Programing
Lecture 4
IF , IF - Else , IF - Else If statements

43 C++ Programing ‫ﻋﻣﻠﻲ‬


Lecture 4
IF , IF - Else , IF - Else If statements
Selection (conditional) statement(cont.)
If there is only one statement
The else if is used to decide
for any of the blocks, the
between two or more blocks
curly braces for that block
based on multiple conditions:
may be omitted:

44 C++ Programing ‫ﻋﻣﻠﻲ‬


Lecture 4
IF , IF - Else , IF - Else If statements

45 C++ Programing ‫ﻋﻣﻠﻲ‬


Lecture 4
IF , IF - Else , IF - Else If statements

46 C++ Programing ‫ﻋﻣﻠﻲ‬


Lecture 4
IF , IF - Else , IF - Else If statements

47 C++ Programing ‫ﻋﻣﻠﻲ‬


Lecture 4
IF , IF - Else , IF - Else If statements

48 C++ Programing ‫ﻋﻣﻠﻲ‬


Lecture 4
IF , IF - Else , IF - Else If statements

49 C++ Programing ‫ﻋﻣﻠﻲ‬


Lecture 4
IF , IF - Else , IF - Else If statements

50 C++ Programing ‫ﻋﻣﻠﻲ‬


Lecture 4
IF , IF - Else , IF - Else If statements

51 C++ Programing ‫ﻋﻣﻠﻲ‬


Lecture 4
IF , IF - Else , IF - Else If statements

52 C++ Programing ‫ﻋﻣﻠﻲ‬


Lecture 4
IF , IF - Else , IF - Else If statements

53 C++ Programing ‫ﻋﻣﻠﻲ‬


Lecture 4
IF , IF - Else , IF - Else If statements

54 C++ Programing ‫ﻋﻣﻠﻲ‬


Lecture 4
IF , IF - Else , IF - Else If statements

55 C++ Programing ‫ﻋﻣﻠﻲ‬


Lecture 4
IF , IF - Else , IF - Else If statements

56 C++ Programing ‫ﻋﻣﻠﻲ‬


Lecture 4
Conditional Operator
It sometimes called as ternary operator. Since it required three
expressions as operand and it is represented as (? , :).
SYNTAX:

exp1 ? exp2 :exp3


Here exp1 is first evaluated. It is true then value return will be exp2 . If false then
exp3.
EXAMPLE
void main()
{
int a=10, b=2
int s= (a>b) ? a:b;
printf(“value is:%d”);
}

57 C++ Programing ‫ﻋﻣﻠﻲ‬


Lecture 4
Conditional Operator
Sana’a University 2019 Quiz Faculty of Computer Science

Programming Language (C)


Assignment 1

float x,y ;
cout<< "Enter the values x ";
cin>> x ;
y = ( x>= 0 )? 5-x*x : 2*x*x*x;
cout <<"The value Y = “ << y;
return 0;

Rewrite the program by using statements if …. else?

58 C++ Programing ‫ﻋﻣﻠﻲ‬


Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7

Fill in the missing parts of the following code :

59 C++ Programing
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7

Fill in the blanks to compare the variables and print the “ printing in the else “ text
to the screen :

60 C++ Programing
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7

How many statements could be placed between if’s braces?

a. 2

b. 1

c. As many as you want

61 C++ Programing
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7

How many nested if statements can an if statement contain?

a. Only two

b. As many as you want

c. None

62 C++ Programing
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7

Fill in the missing parts of the nested if statements to print “it works !” to the screen

63 C++ Programing
C++ Language
C++ ‫ﻟﻐـــــــــــﺔ‬
Dr. khaled Alwesabi

64 C++ Programing

You might also like