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

Switch - Case - Default Statement

C++ is the topic of the document. It provides an introduction and overview of C++ programming concepts like variables, data types, and the switch-case statement. Examples and exercises are included to help explain how to declare and assign variables, use switch-case to output text based on age values, and what happens when the break statement is missing from a case. The document is written in Arabic and aims to teach 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)
36 views

Switch - Case - Default Statement

C++ is the topic of the document. It provides an introduction and overview of C++ programming concepts like variables, data types, and the switch-case statement. Examples and exercises are included to help explain how to declare and assign variables, use switch-case to output text based on age values, and what happens when the break statement is missing from a case. The document is written in Arabic and aims to teach 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/ 17

C++ Language

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

1
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
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
Lecture 5
Switch - Case - default statement

switch (Expression)
{ Expression It could be an integer constant
case constant 1: 1, 2, or 3, or an expression that evaluation to
Action statements; integer.
break; Constant : is a specific value.
case constant 2:
Action statements;
break;
case constant 1:
Action statements;
break;
default:
Action statements;
}

4 ‫ﻋﻣﻠﻲ‬
Lecture 5
Switch - Case - default statement

5 ‫ﻋﻣﻠﻲ‬
Lecture 5
Switch - Case - default statement

switch (Expression)
{ Expression It could be an integer constant
case constant 1: 1, 2, or 3, or an expression that evaluation to
Action statements; integer.
Switch (10.0);
(10);
break; Constant : is a specific value.
case constant 2:
Action statements; int i;
Case 50
>= :50 :
break; Swich (i);
case constant 1:
Case 40
a ++b;10:
Action statements; Swich (i +j * k);
break;
default: Swich (23 + 45 % 4 * k)
Action statements;
}

6 ‫ﻋﻣﻠﻲ‬
Lecture 5
Switch - Case - default statement

7 ‫ﻋﻣﻠﻲ‬
Lecture 5
Switch - Case - default statement

8 ‫ﻋﻣﻠﻲ‬
Lecture 5
Switch - Case - default statement

9 ‫ﻋﻣﻠﻲ‬
Lecture 5
Switch - Case - default statement

Result

10 ‫ﻋﻣﻠﻲ‬
Lecture 5
Switch - Case - default statement

Example :
Write a C++ program that reads an integer number x and
compute, print value of y where : use switch

3𝑥𝑥 − 7 𝑖𝑖𝑖𝑖 𝑥𝑥 = −3
y = �5𝑥𝑥 2 𝑖𝑖𝑖𝑖 𝑥𝑥 = 2 𝑜𝑜𝑜𝑜 5
𝑥𝑥 − 4 𝑥𝑥 3 𝑖𝑖𝑖𝑖 𝑥𝑥 = −4 𝑜𝑜𝑜𝑜 4

11 ‫ﻋﻣﻠﻲ‬
Lecture 5
Switch - Case - default statement

12 ‫ﻋﻣﻠﻲ‬
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7
Fill in the blanks to print ’you can drive a car’ if the variable ‘age’ equals 16, print ”
buy a lottery ticket” if the ‘age’ is equal to 18.

int age;
cin

18

13
Quiz 2021 Quiz C++ Programing

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

14
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7
Fill in the blanks to test age variable against 16, 18, and 21 values and print
corresponding texts to the screen ?
switch

case

break

15
Quiz 2021 Quiz C++ Programing

C++ Programing
Assignment 7
What would occur if we forget to insert ‘break’ after a ‘case’?

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

17

You might also like