1 / 13

CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I – Exercises

CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I – Exercises. UTPA – Fall 2012. Objectives. In this chapter, you will do some exercises about: basic control structures in Visual C#. Precedence of Operators. . new ++ (postfix) -- (postfix)

toshi
Download Presentation

CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I – Exercises

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I – Exercises UTPA – Fall 2012

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

  3. Precedence of Operators • . new ++ (postfix) -- (postfix) • ++ -- + - (unary) • * / % • + - • < <= > >= • == != • ? : • = += -= *= /= %= 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

  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

  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.

  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.

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

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

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

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

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

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

More Related