Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   I have final exam tomorrow and i need some help (http://www.go4expert.com/forums/i-final-exam-tomorrow-i-help-t25325/)

HITCHHIKER 23Mar2011 14:30

I have final exam tomorrow and i need some help
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?

  int Value = 16;
  int *ptrValue = &value; // address of value is 0095FF9C
  cout << value << " " << *ptrValue << " " << ptrValue;
  cout << &value << " " << &*ptrValue << " " << *&ptrValue;


  int X[] = { 1, 2, 3 };
  int *ptr = x;
  for ( int idx = 2; idx >= 0; idx -- )
    cout << * ( x + idx ) << " " << * ( ptr + idx );


  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:


  virtual void print ();
  virtual void print () = 0;

Q3- Following is a class called Numbers, with a declaration of prototype for overloading operator+.

  class AddValue
            int x;
            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


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

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

# 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.

xpi0t0s 24Mar2011 14:10

Re: I have final exam tomorrow and i need some help
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.

Q2 Read http://en.wikipedia.org/wiki/Virtual_function
It answers the question.

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:

class Circle
// ...

for starters?

>radius : a double
What, you're telling us you don't know how to define "radius: a double"? What about:

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?

xpi0t0s 25Mar2011 16:01

Re: I have final exam tomorrow and i need some help
OK, maybe I was a bit harsh, and shouldn't have assumed this problem was due to you slacking off. Maybe the problem is that you've got a crap teacher, and have in fact been trying your hardest. If this is the case then your fellow students should have similar problems and the pass rate should be very low across the whole class; you can take this as evidence of poor teaching to the head of the faculty.

So don't panic. Do your best, and if you fail then either (a) the teacher was crap or (b) this subject just isn't for you; sometimes no matter how hard you try you just can't get your head round something; don't worry about this and just focus on what you *can* do.

All times are GMT +5.5. The time now is 09:15.