. 10 Case Study . Previous -- Algorithms .See ./09.html .Open Prepare . 4.13 Software Engineering Case Study: Identifying Class Attributes in the ATM System . 4.14 Wrap-Up Review the fundamental of control structure: algorithms, Pseudocode, if, if-else, while, plus assignment and increment/decrement operators. .Close Prepare . Deliver -- Question + P5 . Exercise 4.22 .See ./ex04_22.cpp .Open Answers to Questions . Why do you not place a space between a unary operator and its operand It looks better: .As_is -3.2 * y + -x .As_is - 3.2 * y + - x . Can you set a string equal to a variable like string=variable+variable Only if the variable are string variables. C++ does not convert numbers to strings. . What about this nested if... .As_is if(x<10) .As_is if(y<10) .As_is cout<< "The answer is less than 10"; .As_is else .As_is cout<< "The number is greater than 10"; First match the else with the previous unmatched "if". And insert braces and indents in the resulting if-else: .As_is if(y<10) .As_is { .As_is cout<< "The answer is less than 10"; .As_is } .As_is else .As_is { .As_is cout<< "The number is greater than 10"; .As_is } Next put {} around the above and reassemble the whole thing .As_is if(x<10) .As_is { .As_is if(y<10) .As_is { .As_is cout<< "The answer is less than 10"; .As_is } .As_is else .As_is { .As_is cout<< "The number is greater than 10"; .As_is } .As_is } Now we can figure out what it "means" or does, may be an activity chart may help .Image 10example.png [activity chart of code above] I also find that putting the possibilities in a table helps me understand complex logic: .Table Condition .Row x<0 T T F .Row y<0 T F - .Row Action .Row Output <0 X - - .Row Output >0 - X - .Close.Table . Is there a way to put a function in loop and have it coming out not satisfying the condition While-loops repeat until a condition is false. If you want the reverse use the "not" Boolean operator like this .As_is while( not ( condition ) ) ... If you want the condition to repeat the loop to depend on something that happens in the loop.... then use a variable to remember what happens like this: .As_is int condition=1; .As_is while (condition) .As_is { .As_is ... .As_is if(....) .As_is condition=0; .As_is ... .As_is } Using a Boolean variable (next chapter) helps clarify this.... so do Boolean expressions (using not, and, or). For more see .See ./FAQ.html#loop-and-a-half pattern in the Frequently Asked Questions. . What is the difference between a controlled repetition and a counter controlled repetition The presence of a counter -- a variable that is initialized before the loop, tested at the start of each repetition, and either incremented or decremented at the end of each repetition. . When defining a function for a class when are two colons used Inside the class you don't need the colons -- the compiler can see which class the function belongs to. Outside the class you need the colons to tell the compiler which class the function belongs to. . Is it better to keep all class definitio0n in one header file or in multiple header files As the problem gets more complex and solution demands more and more classes the better it is to have multiple files -- one per class. A rough guide, when you find yourself repeatedly scrolling up and down the file from class to class... it would be wise to spit up the file. . What is the importance of attributes Attributes reflect the properties of real objects. Most problems involve object with many properties... and so solution that have many attributes. . How do indicate the initial value of an attribute in UML .As_is name : type = initialValue . How do indicate the initial value of an attribute in UML You have to put the initialization into a constructor. . How many classes should you have On for each type of object in the problem. You need to think about what differences are important and so need to appear in code. . How many classes can you have There is no limit. . How many attributes can you As many as you want. No limit. . Do attributes in the model reflect the variables in the program They represent the named data field in the classes. . Why does the book always use the ATM example (1) To show you a realistic project from soup to nuts. (2) Thinking up a new example is difficult. (3) So you don't have to learn about a new situation in each chapter. . How do develop an error message when the wrong data is input Very carefully! You end up with a lot of if-then-else logic and some loops that ask the user to try again. . How is UML Boolean is equivalent to the bool C++ type By design. The difference in name comes from C and a liking for short names in typed code. To types of data are equivalent if the same operations give similar results. . How is Boolean used in source code (1) Conditions return the two Boolean value: true and false. (2) You declare Boolean variables like this .As_is bool ok; (3) We can combine Booleans like this .Table Example Meaning .Row not(A) negation, opposite value, true<->false .Row (A)and(B) conjunction, true only if both are true. .Row (A)or(B) disjunction, true if one is true or if both .Close.Table . What is a Boolean attribute A Boolean attribute is a true/false property of an object. An example for a Pet or a Person might be: .As_is alive : Boolean and we would code this as .As_is bool alive; inside class Pet or class Person... or even both .Close . Quiz 4 -- on control structures . Next -- More Complex Control Structures .See ./11.html