CS307 Final Part 2

The flashcards below were created by user rinyu on FreezingBlue Flashcards.

  1. 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.
  2. What is the purpose of a friend function?
    Tells the function that it is a friend and can touch its private parts.
  3. 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);
  4. Show how you would indicate in the definition of the class DemoClassChild that it is a subclass of DemoClass.
    class DemoClassChild : public DemoClass;
  5. 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**
  6. List and briefly explain four values of bundling programs into objects.
    • 1) Modularity: The source code for an object can be written and maintained independently of the source code for other objects.
    • 2) Information-hiding**: By interacting only with an object's methods, the details of its internal implementation remain hidden from the outside world.
    • 3) Code re-use: If an object already exists (perhaps written by another software developer), you can use that object in your program.
    • 4) Pluggability and debugging ease: 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.
  7. 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
  8. 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
  9. 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.
  10. 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.
  11. 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.
  12. 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
  13. 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
  14. 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
  15. What are the four types of Relationships?
    • 1. Dependency
    • 2. Association
    • 3. Generalization
    • 3. Realization
  16. 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};
  17. What are the three places in memory where variables and instances of structs and classes can be allocated?
    Stack, Heap, and Microprocessor
  18. 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
  19. 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;
  20. 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(‘A’);
    • 2) long *lpt = reinterpret_castx;
    • 3) int nc = const_castx;
    • 4) cRectangle *r = dynamic_cast(s);
    • 5) int x = static_cast(7.9);
    • 6) long l = reinterrupt_cast(iptr);
  21. 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;
  22. 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);
  23. 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);
  24. 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(…) { }
  25. 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
  26. 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);
  27. 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.
  28. 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);
  29. 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);
  30. 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
  31. 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
Card Set
CS307 Final Part 2
Part 2 of the CS307 Final
Show Answers