Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley.

Similar presentations


Presentation on theme: "CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley."— Presentation transcript:

1 CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539 xiang.lian@utrgv.edu

2 Objectives In this chapter, you will do some exercises about: – basic control structures in Visual C# 2

3 Precedence of Operators. new ++ (postfix) -- (postfix) ++ -- + - (unary) * / % + - >= == != ? : = += -= *= /= %= 3 high low

4 Multiple Choices Which of the following is not an attribute of an airplane? – A. length B. wingspan C. fly D. number of seats All applications can be written in terms of three types of control structures except for: – A. sequence B. selection C. random D. repetition The ________ statement is used to execute one action when a condition is true and another when that condition is false. – A. repetition B. selection C. inheritance D. conditional Repeating a set of instructions a specific number of times is called _______ repetition. – A. EOF-controlled B. flag-controlled C. counter-controlled D. sentinel- controlled When it is not known in advance how many times a set of instructions will be repeated, a(n) ________ value cannot be used to terminate the repetition. – A. flag B. signal C. counter D. sentinel 4

5 Multiple Choices (cont'd) The _______ structure is built into C# -- by default, statements execute in the order they appear – A. sequence B. selection C. repetition D. goto Instance variables of type int are given the value ______ by default. – A. 0 B. NULL C. "" D. 1 C# is a ___________ language – it requires all variables to have a type. – A. strongly-typed B. weak-typed C. wield-typed D. object-typed If the increment operator is _____ to a variable, the variable is incremented by 1 first, then its new value is used in the expression – A. prefixed B. postfixed C. infixed D. None of the above The expression to the right of an assignment operator (=) is evaluated ______the assignment occurs. – A. before B. after C. at the same time D. none of the above 5

6 True/False Statements An algorithm is a procedure for solving a problem in terms of the actions to execute and the order in which these actions execute. A set of statements contained within a pair of parentheses is called a block. A selection statement specifies that an action is to be repeated while some condition remains true. A nested control statement appears in the body of another control statement. 6

7 True/False Statements (cont'd) C# provides the arithmetic compound assignment operators +=, -=, *=, /=, and %= for abbreviating assignment expressions. Specifying the order in which statements (actions) execute in an application is called program control. The unary cast operator (double) creates a temporary integer copy of its operand. Instance variables of type bool are given the value true by default Pseudo code helps you think out an application before attempting to write it in a programming language. 7

8 What are the Precedence of Operators in Expressions? 15*3%12+45/(9%2)*-2 Product *= x++; 8

9 Debug Errors public static main(string []args) { Int x=0; x=y; X=15*3%12+45/(8%2)*-2; WriteLine(x); } 9

10 Debug Errors (cont'd) public static main(string []args) { if (gender = 1) Console.WriteLine("Woman"); else; Console.WriteLine("Man"); } 10

11 Debug Errors (cont'd) public static main(string []args) { int counter = 0; While (counter > 10) { Console.WriteLine(counter); return; } 11

12 Programming Write 4 different C# statements that each add 1 to int variable x. 12

13 Programming (cont'd) Write a console program using nested while loop to output the following pattern to screen: * ** *** **** ***** 13


Download ppt "CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley."

Similar presentations


Ads by Google