|
|
|
|
|
|
|
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;
}; |
|
|
|
 |
|
|
|
|
Write declarations for the following class objects. |
|
|
|
 |
|
|
|
|
a. An object obj1, initialized to 0.0. |
|
|
|
 |
|
|
|
|
b. An object obj2, initialized to 8.6. |
|
|
|
 |
|
|
|
|
c. An array arr1 of class objects, each initialized to 8.6. (If it cannot be done, explain why.) |
|
|
|
 |
|
|
|
|
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 |
|
|
|
|
|