If you can't read please download the document
Upload
kristina-booth
View
226
Download
0
Embed Size (px)
Citation preview
Nested Control Structures
* Conditional Operator (?:)* Preincrement and Postincrement* Predecrement and Postdecrement* Counter-Controlled Repetition* Nested Control Structure Dr. Ming Zhang
Condition Operator (?:)* Conditional Operator (?:) - Ternary Operator Operand1 ? Operand2 : Operand3* First Operand Condition Expression* Second Operandthe value for the entire conditional expression if the condition is true.* Third Operandthe value for the entire conditional expression if the condition is false. Dr. Ming Zhang
Preincrement and Postincrement* Preincrement ++a Increment a by 1, then use the new value of a in the expression in which a resides.
* Postincrement a++ Use the current value of a in the expression in which a resides, then increment a by 1 Dr. Ming Zhang
Predecrement and Postdecrement* Predecrement --a Decrement a by 1, then use the new value of a in the expression in which a resides.
* Postdecrement a-- Use the current value of a in the expression in which a resides, then decrement a by 1 Dr. Ming Zhang
Nested Control Structures (1)A college offers a course that prepares students for the state licensing exam for real estate brokers. Last year, several of the students who completed this course took the licensing examination. Naturally, the college wants to know how well its students did on the exam. You have been asked to write a program to summarize the results. You have been given a list of these 10 students. Next to each name is written a 1 if the student passed the exam and a 2 it the student failed. Dr. Ming Zhang
Nested Control Structures (2)Your program should analyze the results of the exam as follow:1. Input each test result. Display the message Enter result on the screen each time the program requests another test result.2. Count the number of test results of each type.3. Display a summary of the test results indicating the number of students who passed and the number of students who failed.4. If more than 8 students passed the exam, print the message Raise tuition. Dr. Ming Zhang
Nested Control Structures (3)Top:Analyze exam results and decide if tuition should be raised.
First Refinement:Initialize variablesInput the ten quiz grades and count passes and failuresPrint a summary of the exam results and decide if tuition should be raised. Dr. Ming Zhang
Nested Control Structures (4)Fig. 2.11.......while (studentCounter result; if (result == 1)passes = passes +1;elsefailures = failures + 1;studentCounter = studentCounter + 1; } Dr. Ming Zhang