[Skip Navigation] [CSUSB] / [CNS] / [Comp Sci & Eng Dept] / [R J Botting] / [CSci201] / 10
[Text Version] [Syllabus] [Schedule] [Glossary] [Labs] [Projects] [Resources] [Grading] [Contact] [Search ]
Notes: [01] [02] [03] [04] [05] [06] [07] [08] [09] <10> [11] [12] [13] [14] [15] [16] [17] [18] [19] [20]
Labs: [01] [02] [03] [04] [05] [06] [07] [08] [09] [10]
Fri Feb 13 13:18:57 PST 2009

Contents


    10 Case Study

    Previous -- Algorithms

    [ 09.html ]

    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.

    . . . . . . . . . ( end of section Prepare) <<Contents | End>>

    Deliver -- Question + P5

    Exercise 4.22

    [ ex04_22.cpp ]

    Answers to Questions

      Why do you not place a space between a unary operator and its operand

      It looks better:
       		-3.2 * y + -x
       		- 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...

       	if(x<10)
       	if(y<10)
       	cout<< "The answer is less than 10";
       	else
        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:
       	if(y<10)
       	{
       		cout<< "The answer is less than 10";
       	}
       	else
       	{
        	cout<< "The number is greater than 10";
       	}
      Next put {} around the above and reassemble the whole thing
       	if(x<10)
       	{
       		if(y<10)
       		{
       			cout<< "The answer is less than 10";
       		}
       		else
       		{
        		cout<< "The number is greater than 10";
       		}
       	}
      Now we can figure out what it "means" or does, may be an activity chart may help

      [activity chart of code above]

      I also find that putting the possibilities in a table helps me understand complex logic:
      Table
      Condition
      x<0TTF
      y<0TF-
      Action
      Output <0X--
      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
       		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:

       	int condition=1;
       	while (condition)
       	{
       		...
       		if(....)
       			condition=0;
       		...
       	}
      Using a Boolean variable (next chapter) helps clarify this.... so do Boolean expressions (using not, and, or). For more 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

       		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

       		bool ok;
      (3) We can combine Booleans like this
      Table
      ExampleMeaning
      not(A)negation, opposite value, true<->false
      (A)and(B)conjunction, true only if both are true.
      (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:
       		alive : Boolean
      and we would code this as
       		bool alive;
      inside class Pet or class Person... or even both

    Quiz 4 -- on control structures

    Next -- More Complex Control Structures

    [ 11.html ]

    Abbreviations

  1. Algorithm::=A precise description of a series of steps to attain a goal, [ Algorithm ] (Wikipedia).
  2. Gnu::="Gnu's Not Unix", a long running open source project that supplies a very popular and free C++ compiler.
  3. KDE::="Kommon Desktop Environment".
  4. OOP::="Object-Oriented Programming", Current paradigm for programming.
  5. Semantics::=Rules determining the meaning of correct statements in a language.
  6. SP::="Structured Programming", a previous paradigm for programming.
  7. Syntax::=The rules determining the correctness and structure of statements in a language, grammar.
  8. Q::software="A program I wrote to make software easier to develop",
  9. TBA::="To Be Announced", something I should do.
  10. TBD::="To Be Done", something you have to do.
  11. UML::="Unified Modeling Language".

End