943,840 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 982
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
May 11th, 2008
0

help

Expand Post »
Could sum1 plz help me undastand these Questions
just wna no how it is done

fank u





3. If DoSomething is a void function that takes an int expression as an argument, which of the following is an incorrect statement? (Assume all variables are int variables.)

A) DoSomething(n);
B) DoSomething(3*n + 24);
C) length = DoSomething(width);
D) b and c above
E) a, b, and c above

4. Given that x is a float variable and num is an int variable containing the value 38, what will x contain after execution of the following statement:

x = num / 4 + 3.0;

A) 12.5
B) 13
C) 12
D) 12.0
E) nothing; a compile-time error occurs


10. Given the constant declaration

const int FACTOR = 95;

which of the following is not a valid use of FACTOR?

A) cout << FACTOR * 3;
B) FACTOR = 24;
C) cin >> FACTOR;
D) a and c above
E) b and c above


14. Assuming alpha and beta are int variables, what is the output of the following code (which is indented poorly)?

alpha = 3;
beta = 2;
if (alpha < 2)
if (beta == 3)
cout << "Hello";
else cout << "There";

A) Nothing is output.
B) Hello
C) There
D) HelloThere



27. The function heading

float TenToThePower( /* in */ int n )

is for a function that returns 10.0 raised to any integer power. Which of the following statements represents an appropriate use of the TenToThePower function?

A) someFloat = 4.96 * TenToThePower(8) + 2.5;
B) TenToThePower(6);
C) if (TenToThePower(someInt) > someFloat)
beta = 3;
D) a and b above
E) a and c above



29. Given the function definition

int Mystery( /* in */ float someVal )
{
if (someVal > 2.0)
return 3 * int(someVal);
else
return 0;
}

what is the value of the expression Mystery(4.2) ?

A) 12
B) 12.0
C) 0
D) 0.0
E) nothing--the function call is invalid




35. Which of the following is a valid use of the C++ cast operation?

A) gamma = short(delta);
B) beta = (long double) alpha;
C) beta = long double(alpha);
D) a and b above
E) a, b, and c above


38. Given the declarations

enum MovieRatings {G, PG, PG13, R, X};
MovieRatings thisOne;

and assuming that thisOne currently contains a value less than X, which of the following statements can be used to "increment" thisOne?

A) thisOne = thisOne + 1;
B) thisOne++;
C) MovieRatings(thisOne++);
D) thisOne = MovieRatings(thisOne + 1);
E) thisOne = MovieRatings(thisOne) + 1;


39. Given the declarations

struct RecType1
{
int length;
float width;
};
struct RecType2
{
int length;
float width;
};
RecType1 myRec;
RecType2 yourRec;

which of the following assignment statements is valid?

A) myRec.length = yourRec.length;
B) myRec = yourRec;
C) myRec.length = yourRec;
D) a and b above
E) none of the above


41. Assume that myclass.h and myclass.cpp are files for a class MyClass and that someprog.cpp is a client of class MyClass. Which file(s) must #include the file myclass.h?

A) someprog.cpp
B) myclass.cpp
C) myclass.h
D) a and b above
E) a, b, and c above


42. Consider the class declaration

class SomeClass
{
public:
void Func();
private:
int m;
int n;
};

and client code

SomeClass alpha;
SomeClass beta;
...

Considering both pieces of code above, which identifiers are names of class objects?

A) m and n
B) alpha and beta
C) SomeClass, m, and n
D) alpha, beta, m, and n
E) Func, m, and n


45. After execution of the code fragment

int arr[5];
int i;

for (i = 0; i < 5; i++)
{
arr[i] = i + 2;
if (i >= 3)
arr[i-1] = arr[i] + 3;
}

what is contained in arr[1]?
A) 2
B) 3
C) 7
D) 8
E) none of the above

51. What does the following C++ statement do?

ptr = new RecType;

A) It allocates a dynamic variable named ptr.
B) It allocates a dynamic variable and stores the address into ptr.
C) It deallocates the variable ptr.
D) It deallocates the dynamic variable that is pointed to by ptr.


52. Given the declaration

int* somePtr;

which of the following is a valid statement?

A) somePtr = new int*;
B) delete somePtr;
C) delete *somePtr;
D) a and c above
E) a, b, and c above






57. Given the declarations

struct ListNode
{
float volume;
ListNode* link;
};
ListNode* ptr;

what is the data type of the expression ptr.volume ?

A) ListNode*
B) ListNode
C) float
D) *ListNode
E) none--the expression is invalid
Reputation Points: 10
Solved Threads: 0
Newbie Poster
3m4d is offline Offline
5 posts
since May 2008
May 11th, 2008
1

Re: help

What is there you cannot understand? If you expect someone to hand out the answers then you are wrong.
Last edited by hammerhead; May 11th, 2008 at 6:09 am.
Reputation Points: 46
Solved Threads: 24
Posting Whiz in Training
hammerhead is offline Offline
248 posts
since May 2006
May 11th, 2008
1

Re: help

Quote ...
sum1 plz
wna no
fank u
Use real words...
Reputation Points: 1429
Solved Threads: 129
Posting Virtuoso
William Hemsworth is offline Offline
1,542 posts
since Mar 2008
May 11th, 2008
0

Re: help

no i no what the answers are dont worry,lol

just wanted to no how it is
like Q3 i no the answer is C and stuff just wanted to no how it is
Reputation Points: 10
Solved Threads: 0
Newbie Poster
3m4d is offline Offline
5 posts
since May 2008
May 11th, 2008
0

Re: help

You should stop talking like a kid. 'No' and 'know' are two different words. You could also use some CAPS. Read the rules (the part called 'keep it clean')

But on topic: how do you know that the answer is 'c' if you don't know why?
If the teacher gave you the answers you could ask him for help right?
Last edited by Nick Evan; May 11th, 2008 at 2:23 pm.
Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is online now Online
4,132 posts
since Oct 2006
May 11th, 2008
0

Re: help

i probably am a kid thats why im talking the way it is

and yeah we got the answers along with the questions, just wanted to know how it is that it works out to be that, could put up the answer if it helps
Reputation Points: 10
Solved Threads: 0
Newbie Poster
3m4d is offline Offline
5 posts
since May 2008
May 11th, 2008
0

Re: help

Lets take Q3, you have to know that void means that the function does not return any value. That means that option C is incorrect and A is perfectly valid. Option B is where one might get stuck, but since 3*n + 24 amounts to an int, option B is also valid. That means that only option C is incorrect and hence C is the answer.

Why dont you give a shot at all the questions in similar manner and post here why you think a option is the answer. We will correct you if you are wrong.
Reputation Points: 46
Solved Threads: 24
Posting Whiz in Training
hammerhead is offline Offline
248 posts
since May 2006
May 11th, 2008
0

Re: help

Thanks

4. Given that x is a float variable and num is an int variable containing the value 38, what will x contain after execution of the following statement:

x = num / 4 + 3.0;

A) 12.5
B) 13
C) 12
D) 12.0
E) nothing; a compile-time error occurs


With Q4 the answer is D 12.0 but if u work it out you get 12.5 ??


Q10 ive worked out now

Q14:
Assuming alpha and beta are int variables, what is the output of the following code (which is indented poorly)?

alpha = 3;
beta = 2;
if (alpha < 2)
if (beta == 3)
cout << "Hello";
else cout << "There";

A) Nothing is output.
B) Hello
C) There
D) HelloThere


the answer is A)
but i thought it would b C)there as it fails on both the if's and it said

else cout>>"there"
Reputation Points: 10
Solved Threads: 0
Newbie Poster
3m4d is offline Offline
5 posts
since May 2008
May 11th, 2008
0

Re: help

> With Q4 the answer is D 12.0 but if u work it out you get 12.5 ??
Think about the difference between integer division, and float division.
Which applies in this case?

> else cout>>"there"
Consider which of the 'if' statements this else statement binds to?
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
May 11th, 2008
0

Re: help

integer division

and the else statement is binded to the second IF statement ?

but say right that the first IF statement was to work and the second didnt what would have been the outcome then ?

Question 27 is something which i havnt understood at all

27. The function heading

float TenToThePower( /* in */ int n )

is for a function that returns 10.0 raised to any integer power. Which of the following statements represents an appropriate use of the TenToThePower function?

A) someFloat = 4.96 * TenToThePower(8) + 2.5;
B) TenToThePower(6);
C) if (TenToThePower(someInt) > someFloat)
beta = 3;
D) a and b above
E) a and c above
Reputation Points: 10
Solved Threads: 0
Newbie Poster
3m4d is offline Offline
5 posts
since May 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Problems with threads in Borland C++ Builder3.
Next Thread in C++ Forum Timeline: Select Row in dataGridView





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC