# I have final exam tomorrow and i need some help

Discussion in 'C++' started by HITCHHIKER, Mar 23, 2011.

1. ### HITCHHIKERBanned

Joined:
Mar 23, 2011
Messages:
1
0
Trophy Points:
0
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?
Code:
```  int Value = 16;
int *ptrValue = &value; // address of value is 0095FF9C

cout << value << " " << *ptrValue << " " << ptrValue;
cout << &value << " " << &*ptrValue << " " << *&ptrValue;
```
Code:
```  int X[] = { 1, 2, 3 };
int *ptr = x;

for ( int idx = 2; idx >= 0; idx -- )
cout << * ( x + idx ) << " " << * ( ptr + idx );
```
Code:
```  int y[] = { 10, 20, 30, 40, 50 };
int *yPtr = y;

cout << y << " " << *( yPtr + 1 ) << " " << yPtr;
```

Q2- Identify the following function header and explain the differences and it use:

Code:
```  virtual void print ();
virtual void print () = 0;
```

Q3- Following is a class called Numbers, with a declaration of prototype for overloading operator+.
Code:
```  class AddValue
{
private:
int x;

private:

};
```
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:
Code:
`result = first + second;`
i. Does the following code statement is similar with the above code? Explain your answer.

Code:
`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:
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
getArea - return the area of the circle
print - to display circle's area

Formula:
Code:
`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 cylinder's length: 7

Circle's Surface Area: 28.278

Cylinder's Length: 7
Cylinder's Volume: 197.946
Cylinder's Surface Area: 131.964
----------------------------------

Formula:
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.

2. ### xpi0t0sMentor

Joined:
Aug 6, 2004
Messages:
3,009
203
Trophy Points:
63
Occupation:
Senior Support Engineer
Location:
England
This site is called Go4Expert, not Go4GullibleIdiot, or Go4HomeworkAnswers, or Go4FreeConsultancyCosI'mTooLazyToStudy.

Q1 These are very easy. Do you *really* not know? If so then you have been slacking for the entire course and should fail the exam.
I suggest you put these into a compiler and see what comes out.

Q3
a: Very simple. I can't believe that on the day before your exam you can't write code to add two numbers. You deserve to fail. Sorry, but that's what I really think if you don't have this level of knowledge. Get a compiler and try writing the code yourself.

b(i): Also very simple. I'll give you the answer: No. You must now explain it. (Actually part ii gives you this answer, because if it was Yes then they'd have just given you the answer.)

ii/iii: Actually this is a really crap way of trying to write operator+. It should be a non-class method, needs to be a friend because it has to access private data, and takes two arguments so that you can use a=b+c semantics. Maybe the problem with this course is therefore not you slacking off but a crap teacher.

Q4. Strange question. How can one bird be "less than" another bird? But anyway, you only have to write the header, so look at question 3 and change plus to less than.

Q5. Er, very easy. Where are you stuck? *How* can you be stuck? You're given in very much detail what to do. "Write a Circle class" for instance, ok, how about:
Code:
```class Circle
{
// ...
};
```
for starters?

What, you're telling us you don't know how to define "radius: a double"? What about:
Code:
```double radius;
```
You can't do that? And you're expecting to pass an exam on this stuff tomorrow? No, sorry, it isn't going to happen, and if the teachers have any integrity then they shouldn't pass you either. You can't give a pass to someone who simply doesn't know the subject. And people wonder why business doesn't value academia. Why do you think you should pass?

There's really no point going any further with this if you don't know how to define "radius: a double".

Q6. Easy, easy easy easy. Just have a go, OK? When you get stuck (and I mean AFTER trying it), post the code you have as a new thread and we'll help you out.

Q7. Not as easy as 6 but this is basic template stuff. If you have no idea where to start then you have no business being on the day before your final exam. Been slacking off, have we?

Joined:
Aug 6, 2004
Messages:
3,009