Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
35 views
11 pages
C - Lab4 - Eng - Ruqaih Salman Final 2022
Uploaded by
أحمد واصل الغالى
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save C _Lab4_Eng_Ruqaih Salman Final 2022 For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
35 views
11 pages
C - Lab4 - Eng - Ruqaih Salman Final 2022
Uploaded by
أحمد واصل الغالى
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save C _Lab4_Eng_Ruqaih Salman Final 2022 For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save C _Lab4_Eng_Ruqaih Salman Final 2022 For Later
You are on page 1
/ 11
Search
Fullscreen
false. J true Wel ee ANI I Lal le Ade ae 1. Mark the following statements as true or false. lint sete!) gilatall poet Sas hal OS The reul ofs logicl expresioncommotbc algae to anit varie, eh owe OS «if (Score>=60); Chef he gh pul ay A fe Lots any 431i) « one-way selection ‘Mila Gace if b. Ina one-way selection, if a semicolon is placed after the expression Se) statement as if (score>=60); , the expression in the if statement is always true.. else ste if ke UD a ons ©. Every if statement must have a corresponding else. nee tl gle Ws da oy If Sue a ll el : always evaluates to true. . The expression in the ‘(core = 30) grade ‘ch> ='Z j\'ch
&& ch <='Z') evaluates to false if either ch < "A &8 ch <='Z) ss eu is oreh e. . The expression: (eh Suppose the input is 5. The output of the code is: Num is zero Num is zero 2.8m 3,8!) cla) 5 9 QS! ol ve A Ly x CAS 1 ad sae 6 [EDO] ae |. The expression {(x > 0) is true only if x is a negative number. Aah Jalye fl] 5 [1] ase ++ Ct © h. InC++, both ! and != are logical operators. 2. Evaluate the following expressions: cfalse el true Waly ya Ut | all cats 13) Le a 6.28/3<3-1.2 abd By Eng: Ruqaih Salman rugaihw3 salmanw3@ gmail.com3. Suppose that x, y, and are int variables, and x = 10, y = 15, and z = 20. Determine whether the following expressions evaluate to true or false. SE AVA Si ual CaS 1) Lose 2 = 20 sy = 15 9x = 10 Nx > 10) (I= 5) && ( peaoge x
=2||e+y>=2) (x <=y- 2) && (y >=7) || @-2!= 20) clint SL kte oe Bhe 2 sy 5 x ol asl false eltrue 4, Suppose that x, y, z, and w are int variables, and x = 3, y = 4, z= 7, and w= 1. What is the output of the following statements? » cout <<" cout << "x != peaos IGN cl lal gl ga Lew cout << "I> w): 15257 sy a4 5x = 356 int ohne a wz sy 9x ol ati y) << endl; ) << endl; +3) << endl; << (z> w) << endl; cout << "x+y
= 68) cout << "You pass. else; «<< endl; cout << "You fail." << endl; abd By Eng: Ruqaih Salman rugaihw3 salmanw3@ gmail.com8. Write C++ statements that output Male if the gender is 'M', Female if the gender is gender otherwise and invalid invalid.» «gender = "F" GS 8) Female 85 s gender = "M" JIS 15 Male cA! gill ++ C Hah gai cS! ally gender 4a oé 9. What is the output of the following program? SAD ali yl gs ga Le winclude
using namespace std; int main() { int myNum = 10; int yourNum = 30; if (yourNum % myNum { 3) yourNum = myNum = 15 } else if (yourNum % myNum { yourNum myNum = 2; yourNum myNum = 3; + cout << myNum << return @; << yourNum << endl; SyourNum = 12 5 myNum =5 JS 15) « (9 cpt!) Sal cal gh alt ll ga Le 10. What is the output of the program in previous exercise (Exercise 9) , if myNum =5 and yourNum = 12? SyourNum = 33.5 myNum = 30 JS 15) « (9 ca nl) ell Ca pall G8 a pl Sw 111 What is the output of the program in previous exercise (Exercise 17), if myNum = 30 and yourNum = 33? Laba By Eng: Ruqaih Salman rugaihw3 salmanw3@ gmail.com12, Suppose that score is an int variable. Consider the following if statements: : : AIF SLLe el fee int ye score 45 Gl Ua il a. 10) couts<"GradeisC."<
=y) Z=K-Y; else ZEY-X b. if (hours >= 40.0) wages = 40 * 7.50 + 1.5 * 7.5 * (hours - 40); else wages = hours * 7.50; ©. if (score >= 60) str = "Pass"; else str = "Fail"; 14, Rewrite the following expressions using an if..else statement. (Assume that all variables are declared properly.) (-intganno JS Ol yt! gua Ce ge eaill Sl ye fl) Lf. else She ail Ul Gil all 46 sel a. (<5)? y=10:y=20; b. (fuel >= 10) ? drive = 150 : drive = 30; €. (booksBought >= 3) ? discount = 0.15 : discount = 0.0; 15, Suppose that you have the following conditional expression, (Assume that all the variables are properly declared.) (gone JS cil gg Ce cu nal pl al) gh) yal al) i Laba By Eng: Ruqaih Salman rugaihw3 salmanw3@ gmail.com(0 < backyard && backyard <= 5000) ? fertilizingCharges = 40.00: fertilizingCharges = 40.00 + (backyard - 5000) * 0.01; © backyard=3000 448 cals |} fertilizingCharges + a le a, What is the value of fertilizingCharges if the value of backyard is 3000? © backyard=5000 448 <5 | fertilizingCharges 448 A Leb c. What is the value of fertilizingCharges if the value of backyard is 5000? £ backyard=6500 48 Suis \3) fertilizingCharges +8 2 Le dd. What is the value of fertilizingCharges if the value of backyard is 6500? 16, State whether the following are valid switch statements. If not, explain why. Assume that n and digit are int variables, Cl gia digit 91n OI Ga sll call Cpt « AIS GS pL) allen Jia SI he Ge She A) SI jhall CAS 1] L se, -int a. switch (n <= 2){ case @: cout << "Draw." << endl; break; case 1: cout << "Win." << endl; break; case 2: cout << “Lose.” << endl; break; iE b. switch (digit / 4) { case 8, case 1: cout << “low.” << endl; break; case 1, case 2: cout << "middle." << endl; break; case 3: cout << “high.” << endl; ¢. switch (n % 6) case 1: case 2: case 3: case 4: case 5: cout << n3 break; case @: cout << endl; break; Laba By Eng: Ruqaih Salman rugaihw3 salmanw3@ gmail.com+ d.switch (n % 10) { case 2: case 4: case 6: case 8: cout << "Even"; break; case 1: case 3: case 5: case 7: cout << "Odd"; break; + 17.8 that alph: it variable. Cons nppoes thot apne isan it variable, Gon alt eal er the following C++ code: : $4 Casale! i ae int yi alpha oi vail cin >> alpha; switch (alpha % 6) { case @: alpha--5 break; case 1: case 2: alpha = alpha * 25 break; case 3: break; case 4: alpha = case 5: alphat+; break; default: alpha = } alpha - 55 alpha / 3; a. What is the output if the input is 8? b. What is the output if the input is 3? $8 JAY! JS gill a £3 DA2Y! GS i] gill ya Le aba By Eng: Ruqaih Salman rugaihw3 salmanw3@ gmail.com¢. What is the output if the input is 17? 117 Das! JS 13) gil a Le d. What is the output if the input is 24? $24 Js! GIS 13) Gill a 18. n the following code, correct any errors that would prevent the program from compiling or running: Sail lanl Cg geal pall gia ob Ua! gl quate lll SI) include
main() { int num1, num2; bool found; cout << "Enter two integers: ; cin >> num1 >> num2; cout << endl; if (num1 >= num2) && num2 > 2 switch (num % num2) { case 1 found = (num / num2) >= 63 break; case 2: case 3 num = num2 / 2; brake; default: num2 = numd * num2; + else { found = (2 * num2 < num1); if found cin >> num2 num 1 = num2 ~ num1; temp = (num1 + num2) / 16; if num2 { num = num2; num2 = temp; H cout << numi <<" " << num << endl; 3} Laba By Eng: Ruqaih Salman rugaihw3 salmanw3@ gmail.comAfter correcting the code, answer the following questions. (If needed, insert prompt lines to inform the user for the input.) pokhud sey lines prompt 4flaa) slau! Jest «513 1) APM LAY Ge Gag Glad) a6] gy ony (dary a. What is the output if the input is 10 8 6?» S271 JS 13) gall we b. What is the output if the input is 4.9.11)? Jss¥! dS 14 ull wl 19. Suppose the input is 3. What is the value of beta after the following C++ code executes? Sold) C +48 MS beta Led a 3 8 Jay ol Le cin >> beta; switch (beta) { case 3: beta = beta + 3; case 1: betat+5 break; case 5: beta = beta + 5; case 4: beta = beta + 4; + 20. Suppose the input is 6. What is the value of a after the following C++ code executes? iz fall CHAS Mi aw a ga 6s DRY GI a cin >> a if (a > @) switch (a) { case 1: a=a+ 3; case 3: att; break; case 6: a=a+6; aba By Eng: Ruqai Salman rugaihw3 salmanw3@ gmail.comcase 8: aza*s; break; default t else aza+2 21. The following program contains errors. Correct them so that the program will run and output w =21. W = 21 class qa nll GES py Cans Lgmsmety Bolas! le Il ali ll og ng #include
using namespace std; const int SECRET = 5 main() { int x, y, w, 25 z=95 if z2> 10 xX = 12; y = 5, w= x + y + SECRET; else x y = 4, w= x + y + SECRET; cout << << w << endl; } 22. write a C++ program to ask student to enter his grade then print the result “pass” or “failed” Bays DAN say Gaal ol ald ALN GIS 1) Gaon aay CaS 23. write a C++ program to print the number if the number is divided by 5 § Bacall le Raul) Jud saat GAS 18) Gaal gal» cS! 24. (Guess game) write a C++ program to initial value in variable then ask the user to guess number if the number which the user guess equal your number print * you win’ else print * you lost” (Gus85 Sp )2g60) Sts pall Riga gl sal) id poll J ge Sell sal GIS 1 Gye aly 8) abd By Eng: Ruqaih Salman rugaihw3 salmanw3@ gmail.com25.Write a C++ program That calculates the rate of student If the grade >=90 print “Excellent” €te, $ switch plssiuh s joy if SS 8 yo psill dolly Ub dy ys JAY gai GS! 26. Write a C++ program doing a traffic signal if the red prints stop whether yellow prints prepared if the Green prints move Vi gh Lhasa dy aM la AOU eal yl SI Real elang yy ell I pl aly SI Seal 27.Write a C++ program to solve the second degree equation ( Note :use #include
with sqrt() function). 2 #includecmath.h> eSi3 yas pial) gle Jpaall bade PEt ead Jal eal iS! Xt=-besqrt(delta) /2* ks Gay.) SSRN sqrt () Ul sus aX? +bX + c= Ofor any real a, b and ¢ Ifyou know x=-b+ yi /2%a A=b*b - 4tatc 1f.>0 you find two solution Xteb+ VE 12a X2eb- VE 12a If.1=0 you find one solution Xebitta If. <0 you cannot find any solution 28.Write a C++ program that scans the state of the atmosphere if it hot or cold or cool G4 BLESS Gly Cold yal 73.5 12 cu OS 11 HOt ed 73 G+ p51 CAS 1 AdaaN 5 J yall a 2 Gea way OSS! © cool ui 12 29.write a C++ program that checks if the user enters the dimensions of square or rectangle aba By Eng: Ruqaih Salman rugaihw3 salmanw3@ gmail.comSAM pl ga le Lay Juin gl gee GIS 1 IGE aa aa aly Ca 30. Write a C++ program which calculates the age group(child , young ,old) © Syne hs gl ile GIS 13) Saal joall anil gall y ci! 31.Write a C++ Program like a calculator for the basic operations, the user enter two numbers and operation the program calculate the result. Rewrite the same program with Switch switchpsicb Shall ea pl) AMS 20 8 Helse ifplSiub Uae Sule al peel ely CSS) 32.Write a C++ Program that calculates the volume of blood if it is a natural between 4-6 AB oe SS Hel lS GI Cam 8S ell fe gag Gall US I Gena gal a. If less is suffering from a decrease in blood 2 iB coe lly 4b I, aS ola a GB cas 13) b. Ifit has more than an increase in blood volume blood BS co lly A lly yas oa ya 51 cs 1 33.Write a C++ program to print * Saturday’ if the user enter 1 “Sunday” if the user enter 2 ... etc. Write above program twice by using a. (if ...else if)’ b. (switch) switchalssiah cal AUS se) iF Sat Hag pak ay pals Schade Dy g pl egy LLY eal cS! aba By Eng: Ruqaih Salman rugaihw3 salmanw3@ gmail.com
You might also like
Final Exam CPP
PDF
No ratings yet
Final Exam CPP
2 pages
Revision 2
PDF
No ratings yet
Revision 2
20 pages
Fundamentals of Programming - 1 02 Class Notes DECODE DSA With C 2.0 64e49f97f4cb5500180ad522
PDF
No ratings yet
Fundamentals of Programming - 1 02 Class Notes DECODE DSA With C 2.0 64e49f97f4cb5500180ad522
22 pages
C++ in 10 Hours PDF
PDF
No ratings yet
C++ in 10 Hours PDF
234 pages
Introduction To Programming-1
PDF
No ratings yet
Introduction To Programming-1
73 pages
Soalan C++
PDF
No ratings yet
Soalan C++
11 pages
C - in 10 Hours PDF
PDF
No ratings yet
C - in 10 Hours PDF
100 pages
Ch4 Excercise
PDF
No ratings yet
Ch4 Excercise
54 pages
Presentation Conditional Statements in C++
PDF
No ratings yet
Presentation Conditional Statements in C++
26 pages
CSC233-CSC211 2024 - 2025 Lecture 2
PDF
No ratings yet
CSC233-CSC211 2024 - 2025 Lecture 2
62 pages
Psudeo With Explainations2
PDF
100% (1)
Psudeo With Explainations2
33 pages
Lec 07
PDF
No ratings yet
Lec 07
46 pages
Making Decisions: Namiq Sultan
PDF
No ratings yet
Making Decisions: Namiq Sultan
61 pages
Lec 5
PDF
No ratings yet
Lec 5
57 pages
Chap4 ControlStructures
PDF
No ratings yet
Chap4 ControlStructures
46 pages
ECEG 1052 CH 3 - Compressed
PDF
No ratings yet
ECEG 1052 CH 3 - Compressed
59 pages
CS101 TSC
PDF
No ratings yet
CS101 TSC
38 pages
Midterm Exam MCQ Part SU23 Attempt Review
PDF
No ratings yet
Midterm Exam MCQ Part SU23 Attempt Review
2 pages
Control Structures I (Selection)
PDF
No ratings yet
Control Structures I (Selection)
62 pages
Program Flow Control Final
PDF
No ratings yet
Program Flow Control Final
45 pages
Lec 11 PF
PDF
No ratings yet
Lec 11 PF
29 pages
2 Conditionals
PDF
No ratings yet
2 Conditionals
18 pages
C++ Lecture 4 PPT PDF
PDF
No ratings yet
C++ Lecture 4 PPT PDF
22 pages
Examples
PDF
No ratings yet
Examples
23 pages
If Statements
PDF
No ratings yet
If Statements
18 pages
61308شيت اساسيات البرمجة
PDF
No ratings yet
61308شيت اساسيات البرمجة
27 pages
Conditional Pseudocode
PDF
No ratings yet
Conditional Pseudocode
12 pages
Physics Assignment Exercise 2
PDF
No ratings yet
Physics Assignment Exercise 2
19 pages
03 Expressions Statements Control Flow
PDF
No ratings yet
03 Expressions Statements Control Flow
44 pages
CH 6 Part 2
PDF
No ratings yet
CH 6 Part 2
12 pages
Lab 2 Part 2
PDF
No ratings yet
Lab 2 Part 2
13 pages
Midterm Part1
PDF
No ratings yet
Midterm Part1
10 pages
Practiceexam1 Q&A
PDF
No ratings yet
Practiceexam1 Q&A
9 pages
Quiz 1
PDF
No ratings yet
Quiz 1
10 pages
Midterm Exam - Solution
PDF
No ratings yet
Midterm Exam - Solution
6 pages
01 135241 016 117132112492 01032024 084258pm
PDF
No ratings yet
01 135241 016 117132112492 01032024 084258pm
10 pages
Chapter 1 4 Progbook
PDF
No ratings yet
Chapter 1 4 Progbook
15 pages
CS31 Worksheet 2
PDF
No ratings yet
CS31 Worksheet 2
4 pages
CS101 E Quiz 2
PDF
No ratings yet
CS101 E Quiz 2
5 pages
C++final Revision Fall 2024
PDF
No ratings yet
C++final Revision Fall 2024
8 pages
Experiment No 03 (Conditional Statement)
PDF
No ratings yet
Experiment No 03 (Conditional Statement)
11 pages
1) Explain The Arithmetic, Relational and Logical Operators With Suitable Example
PDF
No ratings yet
1) Explain The Arithmetic, Relational and Logical Operators With Suitable Example
14 pages
Ii Unit Test Question Bank (Cs1) : 1) Select The Most Appropriate Option and Rewrite The Following Statements
PDF
No ratings yet
Ii Unit Test Question Bank (Cs1) : 1) Select The Most Appropriate Option and Rewrite The Following Statements
5 pages
1stexam Sol
PDF
No ratings yet
1stexam Sol
6 pages
COMP108 - Review Questions With Answers 2
PDF
No ratings yet
COMP108 - Review Questions With Answers 2
11 pages
PF LAB 03 (Conditional Statements)
PDF
No ratings yet
PF LAB 03 (Conditional Statements)
4 pages
25-05-2021 LAb Journal
PDF
No ratings yet
25-05-2021 LAb Journal
5 pages
Answer Mid Term Programming 2024
PDF
No ratings yet
Answer Mid Term Programming 2024
4 pages
Output:: Prepared By: Mohammad H. Ryalat
PDF
No ratings yet
Output:: Prepared By: Mohammad H. Ryalat
5 pages
Mid Term Programming 2024
PDF
No ratings yet
Mid Term Programming 2024
3 pages
LAB 9 C++ Part 2
PDF
No ratings yet
LAB 9 C++ Part 2
2 pages
نسخة Midterm CSC 115 Spring 2020
PDF
No ratings yet
نسخة Midterm CSC 115 Spring 2020
3 pages
I. Multiple Choices. Write The Letter of Your Choice For Each of The Items On The Answer Sheet
PDF
No ratings yet
I. Multiple Choices. Write The Letter of Your Choice For Each of The Items On The Answer Sheet
8 pages
Xi Cs First Setb2 Sol
PDF
No ratings yet
Xi Cs First Setb2 Sol
10 pages
Midterm Examination Computer Programming 1 (IT 112/IT 31) : Seek GOD's Help and Guidance
PDF
No ratings yet
Midterm Examination Computer Programming 1 (IT 112/IT 31) : Seek GOD's Help and Guidance
4 pages
GENG 106 Lab3
PDF
No ratings yet
GENG 106 Lab3
4 pages
Assignment Operators and Expressionswith Answers
PDF
No ratings yet
Assignment Operators and Expressionswith Answers
8 pages
CSC131 Exercise
PDF
No ratings yet
CSC131 Exercise
5 pages
Question - Quiz New Year
PDF
No ratings yet
Question - Quiz New Year
5 pages