< previous page page_899 next page >

Page 899
class SomeClass
{
public:
    float Func1() const;
     .
     .
     .
    SomeClass( /* in */ float f );
        // Precondition:
        //     f is assigned
        // Postcondition:
        //     Private data is initialized to f
    SomeClass();
        // Postcondition:
        //     Private data is initialized to 8.6
private:
    float someFloat;
};
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Write declarations for the following class objects.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a. An object obj1, initialized to 0.0.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b. An object obj2, initialized to 8.6.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
c. An array arr1 of class objects, each initialized to 8.6. (If it cannot be done, explain why.)
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
d. An array arr2 of class objects, each initialized to 24.7. (If it cannot be done, explain why.)
11. The C++ compiler will signal a syntax error in the following class declaration. What is the error?
class SomeClass
{
public:
    void Func1( int n );
    int Func2();
    int SomeClass();
private:
    int privateInt;
};
Programming Warm-Up Exercises
1. The TimeType class supplies two member functions, Equal and LessThan, that correspond to the relational operators == and <. Show how client code can simulate the other four relational operators (!=, <=, >, and >=) using only the Equal and LessThan functions. Specifically, express each of the following pseudocode statements in C++, where time1 and time2 are objects of type TimeType.
a. IF time1   time2
     Set n = 1

 
< previous page page_899 next page >