CS307 Test #1.2

Card Set Information

CS307 Test #1.2
2011-11-26 15:03:39
CS307 Test

1.2 Test for CS307
Show Answers:

  1. An object is a software “bundle,” usually thought of as being a class or structure consisting of a set of variables which defines the states the object can exist in, and a set of functions that defines the behavior of the object.
  2. List and briefly explain the three characteristics of an object?
    • 1. State – the member variables or fields
    • 2. Defined Behavior – the member functions
    • 3. Defined ways of modifying the state – by the member functions.
  3. What is the purpose of a friend function?
    Tells the function that it is a friend and can touch its private parts.
  4. Show how to declare a function, not part of a class, as a friend function.

    char *presentTime(time_class tz) {}
    • friend char *presentTime(time_class tz);
  5. A single version of an object/class.
  6. The process of creating a new version of an object/class.
  7. The header file, one of the two files needed to define a class. Contains the definition of the class, using a syntax similar to that for defining a data structure.
    Interface File
  8. The second file needed to define a class. It contains all of the functions that are members of that class.
    Implementation File
  9. In C++ classes you can assign to the variables and functions an access scope using: public, private, and protected.
    Member Access Specifiers
  10. A function that is not a part of a class, but has been given access to the private members (variables and functions) of the class.
    Friend Function
  11. A mechanism by which one class acquires the properties (member variables and member functions) of another class.
  12. A class can have more than one superclass.
    Multiple Inheritance**
  13. The ability to use the same named functions in sub-classes of a parent class to perform different actions.
  14. Show how you would indicate in the definition of the class DemoClassChild that it is a subclass of DemoClass.
    class DemoClassChild : public DemoClass;
  15. 1. Show how you would indicate in the definition of the class cString that it is a subclass of both cShape and String.
    2. What is the name of this process?
    • 1. class cString : public cShape, public String
    • 2. Multiple Inheritance**
  16. The source code for an object can be written and maintained independently of the source code for other objects.
  17. By interacting only with an object's methods, the details of its internal implementation remain hidden from the outside world.
    Information Hiding**
  18. If an object already exists (perhaps written by another software developer), you can use that object in your program.
    Code re-use
  19. If a particular object turns out to be problematic, you can simply remove it from your application and plug in a different object as its replacement.
    Pluggability and debugging ease
  20. A block of code in an application which can be written, compiled, and maintained independently of the rest of the code in the application.
  21. Reducing the interdependency of objects in an application to make the application more flexible and to enable modifying an object without affecting other objects in the application.
    Loose Coupling
  22. When an object needs to perform a certain task, but instead of doing that task directly it "asks" another object to handle the task, or sometimes just part of the task.
  23. Hiding the internal state of an object and requiring all interaction to be performed through an objects methods. (Note: the answer is not Data Hiding)
  24. What is the Structured or Classical paradigm approach to software engineering that was primarily used from 1975 to 1985.
    • 1. Structured Systesm Analysis
    • 2. Data Flow Analysis
    • 3. Structured Programming
    • 4. Structured Testing
  25. What are the six steps in the Unified Process of Software Engineering developed by Booch, Jacobson, and Rumbaugh?
    • 1. Requirements workflow
    • 2. Object-oriented analysis workflow
    • 3. Object-oriented design workflow
    • 4. Object-oriented implementation workflow
    • 5. Post-delivery maintenance
    • 6. Retirement
  26. What are the "three easy steps" to developing great software?
    • 1. Great software must satisfy the customer. Make sure the software does what the customer wants it to do.
    • 2. Great software is well-designed, well-coded, and easy to extend. Apply basic OO principles to add flexibility.
    • 3. Great software can be reused. Strive for a maintainable, reusable design.
  27. Given one of the eight Design Principles discussed in class be able to briefly explain what it means relative to object oriented software design.
    • 1. Identify the aspects of your application that vary and separate them from what stays the same.
    • 2. Program to an interface, not an implementation.
    • 3. Favor composition over inheritance.
    • 4. Strive for loosely coupled designs between objects that interact.
    • 5. Classes should be open for extension, but closed for modification.
    • 6. Depend on abstractions. Do not depend on concrete classes.
    • 7. Principle of Least Knowledge – talk only to your immediate friends.
    • 8. A class should have only one reason to change.
  28. An expression of desired behavior for a software system. It is specific thing your system has to do to work correctly.
  29. What are the four steps which should be followed in determining the requirements of a system?
    • 1. Elicitation – Find out what the requirements are.
    • 2. Analysis – Make sure you understand the requirements.
    • 3. Specification – Clearly state the requirements.
    • 4. Validation – Make sure they are correct.
  30. Determining a set of components (objects, classes, etc.) and interfaces between those components in a software system that will satisfy the requirements and solve the problem.
    Object Oriented Design*
  31. The Unified Modeling Language (UML) consists of what three parts?
    • 1. The basic building blocks
    • 2. Rules controlling how the blocks are put together
    • 3. Common mechanisms that apply throughout the language
  32. What are the three types of building blocks (one of the three parts) that make up the Unified Modeling Language (UML)?
    • 1. Things
    • 2. Relationships
    • 3. Diagrams
  33. What are the four types of things (one of the three types of building blocks) that make up the Unified Modeling Language (UML)?
    • 1. Structural Things
    • 2. Behavior Things
    • 3. Grouping Things
    • 4. Annotation Things
  34. What are the four types of Relationships?
    • 1. Dependency
    • 2. Association
    • 3. Generalization
    • 3. Realization
  35. A semantic relationship in which a change on one thing (the independent thing) may cause changes in the other thing (the dependent thing).

  36. A structural relationship describing links between objects. May also include labels to indicate number and role of the links.

  37. A specialization relationship. Simply put this describes the relationship of a parent class to its subclasses.

  38. Defines a relationship in which one class specifies something that another class will perform.

  39. Draw the Structural thing in UML: Class
  40. Draw the Structural thing in UML: Interface**
  41. Draw the Structural thing in UML: Collaboration
  42. Draw the Structural thing in UML: Use Case
  43. Draw the Structural thing in UML: Active Class
  44. Draw the Structural thing in UML: Component
  45. Draw the Structural thing in UML: Node
  46. Draw the Behavior thing in UML: Interaction
  47. Draw the Behavioral thing in UML: State Machine
  48. Draw the Grouping thing in UML: Package
  49. Draw the Annotational thing in UML: Node
  50. Show how you would define an enumerated data type called RoyalCards with 4 values, JACK, QUEEN, KING, and ACE with each set to corresponding values, i.e. 11, 12, 13, and 14.
    enum RoyalCards{JACK=11, QUEEN, KING, ACE};
  51. What are the three places in memory where variables and instances of structs and classes can be allocated?
    Stack, Heap, and Microprocessor
  52. Give examples of variables declarations that would be allocated in each of the three location.

    int gVal;
    void someTestFunction(int x, double y) {
    double d;
    static float f;
    int *iptr;
    iptr = new int();
    register int rx;
    • int gVal; = Heap
    • void someTestFunction(int x, double y) { = Stack
    • double d; = Stack
    • static float f; = Heap
    • int *iptr; = Stack
    • iptr = new int(); = Heap
    • }
    • register int rx; = Microprocessor
  53. Refers to where a variable can be accessed in
    a program.
  54. A specifier used to specify access to a global variable in one source file when the actual global variable is defined in another source file.
  55. A variable defined this way will be allocated on the heap.
  56. Identifying, at run time, the sub-class type of an object given only a parent class pointer or reference to the object.
  57. Given an int variable (int iCount) show how you would declare a reference variable called iRef and set it to reference iCount.
    int &iRef = iCount;
  58. Show the proper C++ type casting syntax in each of the following cases. Note this is NOT the simple C type-casting such as int c = (int)(‘A’);

    1) Cast ‘A’ to 65 (ASCII value of ‘A’): int x = ____________
    2) Cast int x = 0 to long pointer: long *lpt = ____________
    3) Cast const int x to non-constant: int nc ____________
    4) Cast cShape *s to cRectangle pointer cRectangle *r = ____________
    5) Cast 7.9 to 7 int x = ____________
    6) Cast int *iptr (address sotred in iptr) to long; long l = ____________
    • 1) int x =static_cast<int>(‘A’);
    • 2) long *lpt = reinterpret_cast<long *>x;
    • 3) int nc = const_cast<int>x;
    • 4) cRectangle *r = dynamic_cast<cRectangle *>(s);
    • 5) int x = static_cast<int>(7.9);
    • 6) long l = reinterrupt_cast<long>(iptr);
  59. Show how you would define a pointer to a function called fptr when the function it must point to is: int testFunction(double d, char *c). Also show how you would set fptr pointing to testFunction.
    • int(*fptr)(double, char *);
    • fptr = testFunction;
  60. Given the following code, fill in the blank with a line which will test for value being positive using the assert test.

    double value, sqRoot; // code to set value
    // test for value not negative using assert
    sqRoot = sqrt(value); // If positive proceed
    with the calculation
    assert(value >= 0);
  61. Given the following code, fill in the blank with a line which will test for division by zero using the assert test.

    double dividend, divisor, quotient;
    // code to set value of dividend and divisor is here
    // test for zero divisor using assert
    assert ___________________;
    // If positive proceedwith the calculation
    assert(divisor != 0);
  62. Show how you would write a try…catch block in which the value of a char variable, ch, is tested. If it is a digit (‘0’ … ‘9’) throw and int exception, if it is an upper case letter (‘A’ – ‘Z’) throw a char * (character array-string) exception, and for all non-printable characters (ASCII value < 32 or > 127) throw a general exception (…). (Hint: In conditional statements like: if ((ch < 97) || (ch > ‘z’)) you can test both characters and ASCII values, e.g. if ((ch < 97) || (ch >122)) will both be true if ch is not a lower case letter. ‘a’ = ASCII 97 and ‘z’ = ASCII 122)
    • try {
    • if((ch >= ‘0’) && (ch <= ‘9’)) throw 0;
    • else if((ch >= ‘A’) && (ch <= ‘Z’)) throw “opps!”;
    • else if((ch < 32) || (ch > 127)) throw;
    • }
    • catch(int i) { }
    • catch(char *) { }
    • catch(…) { }
  63. List and briefly define three of the five ways discussed in class on controlling access to shared resources in threads.
    • 1. Semaphores
    • 2. Mutexes
    • 3. Event Objects
    • 4. Waitable Timers
    • 5. Critical Sections
  64. Show two ways of passing a pointer into a function so that the function can change what the pointer is point to, i.e. passing a pointer to a pointer or passing a reference to a pointer.
    • Pass a pointer to a pointer (a handle) to the
    • function:
    • incPointerWithHandle(&iptr);

    • Pass a pointer reference to the function:
    • incPointerWithReference(iptr);
  65. What is a function prototype and why is it needed?
    The purpose of a function prototype is to tell the compiler the correct syntax required to call the function.
  66. Show how to create an overloaded function in a class.
    • bool MyList::insert(Node *newNode);
    • bool MyList::insert(list of args giving data to insert into a new Node);
  67. Explain what default arguments to functions are and show how you would declare default values for arguments to a function.
    void someFunction(int x=0, double d=1.0, char c=’a’, long l = 1);
  68. What are virtual functions? Why is it best to make a function in a parent class virtual so that sub-classes have to implement it, i.e. explain early vs. late binding.
    • Early / Static / Compile time binding
    • Late / Dynamic / Run time binding
  69. A section of code (usually one or more functions) in a program that is running independently of the rest of the program. Threading is a type of multi-tasking, and there are two types: Process based and Thread based.
  70. If a function in a parent class is labeled this, all subclasses are forced to override and implement their own version of that function.
  71. A system that allows a software designer to graphically layout and model a software application.
  72. The process of creating the design by starting at a high level of abstraction and iteratively working down to more detail.
    Step-Wise Refinement
  73. The process of studying and analyzing what the customer wants in order to develop a stated list of requirements.
    Requirement Analysis
  74. Flags if a resource is being used.
  75. Works like a token in a token ring network.
  76. A way for threads to communicate between themselves.
    Event objects
  77. Another way for threads to communicate or time events.
    Waitable timers
  78. Provides synchronization similar to mutex.
    Critical Sections
  79. List two to four ways of referring to the relationship between a subclass and its' parent class.
    • 1) A-Kind-Of
    • 2) Is-A
    • 3) Part-Of
    • 4) Has-A