I need help...I have final exam tomorrow

Pages: 12
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.
Seems like you have a range of basic to somewhat advanced concepts here. Video tutorials can help you here. Xoax has put together a great play list that will most likely cover all of this:

http://www.youtube.com/watch?v=WYbeLBVG34I&feature=BF&list=PLCCE82290D45D88E3&index=1

Search "Xoax X" (when X = what you need help on) and watch the video, it should help you understand the concept and answer the questions on your exam.

Edit: Everything in C++ console applications can be found in this tutorial: http://newdata.box.sk/bx/c/ even though for it to help you in time you will need to check the Table of Contents.
Last edited on
WriteGreatCode

thanx for the links but i cant watch the videos and answer the questions...I need to understand than answer
and if i tried to understand it will take long time and i dont hav enough time coz the exam is tomorrow

hope u understand guys

i will wait for someone who really understand C++ and can give me the answers direct
Those videos explain everything in a very nice and clear way. Watch a few to understand what I mean.
how can someone understand programming in a few hours just by watching videos?
I reaaly need someone to do that

if i hav enough time I will read or watch videos and understand.. but there s no time :(
final exam tomorrow - you are screwed
lol k, I'll answer them and edit in the answer when I'm done.
WriteGreatCode

thanx man

I really appreciate what u doing for me
bro, i would love to help you but i think right now you got WriteGreatCode in ur back ... he is a professional backUp ... and his answer is trusted .... good luck for the final Exam dude :)
M0ha wrote:
you got WriteGreatCode in ur back ... he is a professional


Given what he is about to do - that is debatable...
i am not sure about the answers but hope the guys here gonna help u if i have such mistakes... :)
for Q5 the answer is :

#include<circle.h>
using std::cout;
#define pi=3.142
Class circle{
Private:
Double radius;
Circle::circle(){
Radius=0.0;
}
Circle::circle(double r){
Radius=r;
}
Void setradius (double r){
Radius=r;
}
Double getradius (){
Return radius;
}
Double getarea(){
Return pi * radius * radius;
}
Void print {
Cout <<” the radius is: ”\n<<” ”<<
<<”the area is : ”\n;
}

#include<iostream>
Using namespace std;
Int main(){
Circle c ();
Cout<<”enter radius : ”;
Cin>>radius;
Cout<<” the radius is :”;
Cout<<”the area is ”<<” ”<<c.getarea();
Return 0;
}


and for Q6 is :

#include<cylinder.h>
Class cylinder{
Private:
Double radius, length;
Cylinder::cylinder(double l){
Length=l;
}
Void setradius (double r){
Radius=r;
}
Double getradius (){
Return radius;
}
Void setlength (double l){
length=l;
}
Double getlength (){
Return length;
}
Double getvolume(){
Return length * pi * radius * radius;
}
Double getarea(){
Return 2 * length * pi * radius;
}
Void print {
Cout <<” the radius is: ”\n<<” ”<<
<<”the cylinder length is : ”\n;
}
}
#include<iostream>
Using namespace std;
Int main(){
Cylinder cyl ();
Circle c ();
Cout<<”enter circle radius : ”;
Cin>>radius;
Cout<<” the circle radius is :”<<” ”<<c.getradius;
Cout<<”enter cylinder length : ”;
Cin>>length;
Cout<<” the cylinder length is :”<<” ”<<c.getcylinder;
Cout<<”cylinder volume is :”<<” “<<cly.getvolume();
Cout<<”the area is ”<<” ”<<c.getarea();
Return 0;
}



again im not sure about the answer Mr HITCHHIKER
come on guys .... help the guy for his final exam :))
Question one: what is the output?

These were really simple, all I did was copy the code into my IDE and compiled it. It will show the output.

Code one:
1
2
3
4
5
int Value = 16;
int *ptrValue = &value; // address of value is 0095FF9C

cout << value << " " << *ptrValue << " " << ptrValue;
cout << &value << " " << &*ptrValue << " " << *&ptrValue;


Output:
16 16 0x28ff0c0x28ff0c 0x28ff0c 0x28ff0c

Code Two:
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 );


Output:
3 32 21 1

Code Three:
1
2
3
4
int y[] = { 10, 20, 30, 40, 50 };
int *yPtr = y;

cout << y[4] << " " << *( yPtr + 1 ) << " " << yPtr[2];


Output:
50 20 30

Question Two: Identify the following function header and explain the differences and it use:

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


Read the first answer here: http://stackoverflow.com/questions/3970279/what-is-the-point-of-a-private-pure-virtual-function

He explained it better than I could.

Question Three: 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+.

This should be a possible implementation:
1
2
3
4
5
6
AddValue AddValue::operator+ (AddValue &i)
{
	AddValue cTemp;
	cTemp.x = x + i.x;
	return (cTemp);
}


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);

I don't believe so, the operator+ is used for overloading, not for addition.

ii. How does the operator+ function will be called?

Not too sure I got this one right

1
2
AddValue Object1;
AddValue b (Object2);


iii. Which object is passed as an argument into the operator+ function?

Object1.

Question Four: Assume a class named Bird exists. Write the header for a member function that overloads the operator for that class.

Don't think there is enough information to write a working example here but I tried my best:

//Header.h
1
2
3
4
5
void MemberFunction::operator+ (Bird &x)
{
	Bird Temp;
	return (Temp);
}


Question Five: 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().

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class Circle
{
	private:
		double radius;
		double pi;
	public:
	Circle ()
	{
		radius = 0.0;
		pi = 3.142;
	}
	Circle (double x)
	{
		radius = x;
	}
	void setRadius (double x)
	{
		radius = x;
	}
	double getRadius ()
	{
		return radius;
	}
	double getArea ()
	{
		return (pi * radius * radius);
	}
	void print ()
	{
		cout << getArea () << endl;
	}
};


Question Six:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
using namespace std;
class Circle
{
	public:
		double radius;
		double pi;
		Circle ()
		{
			radius = 0.0;
			pi = 3.142;
		}
		Circle (double x)
		{
			radius = x;
		}
		void setRadius (double x)
		{
			radius = x;
		}
		double getRadius ()
		{
			return radius;
		}
		double getArea ()
		{
			return (pi * radius * radius);
		}
		void print ()
		{
			cout << getArea () << endl;
		}
};

class Cylinder : public Circle
{
	private:
		int length;
	public:
		void Print ()
		{
			cout << "Enter the circle's radius: ";
			cin >> radius;
			cout << "\nEnter the cylinder's length: ";
			cin >> length;
			cout << "\n\nCircle's Radius: " << getRadius ();
			cout << "\nCircle's Surface Area: " << getArea ();
			cout << "\n\nCylinder's Length: " << length;
			cout << "\nCylinder's Volume: " << (length * pi * radius * radius);
			cout << "\tCylinder's Surface Areay: " << (2 * length * pi * radius);
		}
};

int main ()
{
	Cylinder q;
	q.Print ();
	cin.get ();
	return 0;
}





Sorry I couldn't finish question seven, I got to go to sleep, its 3:28 AM :P
Hopefully someone else can.

NOTE: I'm not too sure how I did on the operator+ questions. I never used them before so I had to read over a tutorial real quick to help
sorry HITCHHIKER !! i couldnt answer Question sex for u .... hope other guys can do it for u ,,,,
For the output questions, why can't you just compile them yourself and figure it out? We're not here to answer your homework questions for you. And why should we help you pass your final exam? If you didn't study, take the F. The market is flooded enough as it is without more poorly educated or UNeducated programmers out there.

Don't want to come off as a jerk, but I'm just being blunt with you.
Last edited on
how can someone understand programming in a few hours just by watching videos


You probably can't, which is typically why it's a good idea to STUDY before the last minute!



guys .. just help without telling any bullshit ... "market flooded enough" (he is not going to work in ur father company or in ur country.... so if u wan help just help him ... if u cant then save ur words ....

sorry for being rude but i wish u guyz help him, cuz i did my best to him ..


i will try to do for you Question 6 ....
ops.. i mean Question 7
@M0ha

http://cplusplus.com/forum/articles/31015/

After you read this then come back, and read his first post. Then ask yourself "has he done any work himself?", and if you determine the answer to that question is no, then ask yourself why SHOULD we help him?

If you determine that he does deserve help then feel free to help him, but at least think about why your helping anyone before you do.
i understand what you trying to tell him, but if you go and see what the lecturer teach nowaday then you will freely help him.... trust me i been in his situation during my study life, and i went through many trouble with my education bcuz of the lecturers .... i used to be bad student bcuz of the lecturers, even self study wont be helpful if there are no leading...

dont tell me we can do self study, otherwise i wont waste my money to go for school .... just remember that one day u will be in his position and u will seek for help where there is no one wanna stand by u ... i do believe thats not good to help people that dont want try hard, and i do believe how bad to get a full mark without doing effort, but u not next to him to judge, and maybe he did the best but he couldnt do anything... be a positive thinker plz ...

anyway, the guy asked me for Question7 and i couldnt help him, if u can then im sure he will be thankful.

i do wish u the best HITCHHIKER and hope next time you study hard !!
Pages: 12