hello everyone...I really need ur help guys
i dont really understand C++ well...and i hav final exem tomorrow..hope u gonna help me :)
I have some questions :
many questions but hope u understand the situation coz my final exam tomorrow
Q1- what is the output?
1 2 3 4 5
|
int Value = 16;
int *ptrValue = &value; // address of value is 0095FF9C
cout << value << " " << *ptrValue << " " << ptrValue;
cout << &value << " " << &*ptrValue << " " << *&ptrValue;
|
1 2 3 4 5
|
int X[] = { 1, 2, 3 };
int *ptr = x;
for ( int idx = 2; idx >= 0; idx -- )
cout << * ( x + idx ) << " " << * ( ptr + idx );
|
1 2 3 4
|
int y[] = { 10, 20, 30, 40, 50 };
int *yPtr = y;
cout << y[4] << " " << *( yPtr + 1 ) << " " << yPtr[2];
|
Q2- Identify the following function header and explain the differences and it use:
1 2
|
virtual void print ();
virtual void print () = 0;
|
Q3- Following is a class called Numbers, with a declaration of prototype for overloading operator+.
1 2 3 4 5 6 7 8 9
|
class AddValue
{
private:
int x;
private:
AddValue operator+ (AddValue & );
};
|
a) Write a possible implementation for the operator+.
b) Assume result,first and second are all instances of the Numbers class,and perform the following statement:
result = first + second;
i. Does the following code statement is similar with the above code? Explain your answer.
result = first.operator+(second);
ii. How does the operator+ function will be called?
iii. Which object is passed as an argument into the operator+ function?
Q4- Assume a class named Bird exists. Write the header for a member function that overloads the <operator for that class.
Q5- Write a Circle class that has the following member variables:
radius : a double
pi : a double initialized with the value 3.142
The class should have the following member function:
Default Constructor - that sets radius to 0.0
Constructor - Accepts the radius of the circle as an argument
setRadius - A mutator function for the radius variable
getRadius - An accessor function for te radius variable
getArea - return the area of the circle
print - to display circle's area
Formula:
Circle's area = pi * radius * radius
Note: No need to write the function main().
Q6- Write a Cylinder class that inherit from the Circle class and specifies additional variable named length to hold the cylinder's length value. This class must include function that calculate and return the value and surface's area. Redefine function print() from the class Circle class in order to get the following output:
Sample output:
---------------------------------
Enter the circle's radius: 3
Enter the cylinder's length: 7
Circle's Radius: 3
Circle's Surface Area: 28.278
Cylinder's Length: 7
Cylinder's Volume: 197.946
Cylinder's Surface Area: 131.964
----------------------------------
Formula:
Cylinder's Volume = length * pi * radius * radius
Cylinder's Area = 2 * length * pi * radius
Write a program that demonstrates the Cylinder class by asking the user for the circle's radius, cylinder's length and creating a Cylinder object.
Q7-(Template) Write a complete C++ program as follows.
# First write a class template couple that can be instantiated to hold two
values of two different types.The template should provide a constructor and
two simple access function.
# Next write a class template ThreeTime that can be instantiated to hold three
values of three different types.The Times template should be derived from the
couple tenplate. It should provide a constructor and three simple access
function.
# Finally write a main function that creates and uses a couple object and a ThreeTime object. The pair should hold an integer value and a string value,and the triple should hold a character value and a double value and a Boolean value.
Invoke the access function and print all values in both the couple and ThreeTime objects.