# C++ logics

• 09-10-2001
charlie
C++ logics
Please just give me the correct and explain a lil bit on why u choose it... thank you

What is the output of the following code?

#include <iostream.h>

int main ()
{
int i=6;
i /= i -2;
cout << i;
return 0;
}

a) error and will not complie?
b) 1
c) 1.5
d) 2
e) 4

(2)
Which of the following does not correctly compute the mathmatical average of the int variables a , b and c

a)float (a+b+c) / 3.0
b) (a+b+c) / 3
c) float ((a+b+c) / 3)
d) float (a+b+c) /3

(3)
sum =0;
outercount =1;
while (outercount <= 3)
{
inntercount 1;
while (innercount <= innercount )
{
sum = sum + innercount;
innercount ++;
}
outercount ++;
}
cout << sum <<endl;

a) 1 b) 4 c) 10 d) 20 e) 35

4)
How many time will this loop iterate?

int x=0,
y=0,
z= 10;

do
{
y=x;
x += z;
}
while ( z++ < 9)

a) 0 b) 1 c) 9 d) 10 e) infinite number of timez

5)
consider the function definition

void demo ( int intval, float & floatval )
{
intval = intval *2;
floatval = float (intval) + 3.5;
return;
}

what are the values of myint and myfloat after the following code fragment is executed?

int myint = 20;
float myfloat = 4.8;
demo (myint, myfloat);

a)myint =20 and myfloat = 43.5
b)myint = 40 and myfloat = 4.8
c) myint = 20 and myfloat = 4.8
d) myint = 40 and myfloat = 43.5
e) none of the above.

6)
After the execution of the code fragment
int ar[5];
int i;
for ( i=0; i< 5; i++)
{
ar[i] = i +2;
if ( i > =3 )
ar [i-1] = ar [i] +3;
}

what is contained in ar[2]?
a) 8 b) 4 c) 3 d) 2 e) none of the above

7)
Given a 5000 element array beta, which of the code fragments below could used to print out the values of beta [0],
beta[2],beta [4] abd so forth? ( all variables are of type int )

a)
for ( i=0; i < 5000 ; i+=2)
cout << beta [i] <endl;
b)
for ( i=0 ; i <2500 ; i++)
cout << beta [2*i] << endl;
c)
for ( i= 0; i < 2500 ; i++)
cout << beta [i] *2 <<endl;
d)
a and c

e ) a,b,c
• 09-10-2001
Govtcheez
Y'know - in the time it took you to type out all that stuff, you coulda looked up the answers and actually solved them....
• 09-10-2001
iain
i detect a homework question!
• 09-10-2001
kermi3
Is this homework?
Is this your homework assignment? If so the board is not made for other people to do all of your homework for you...however, if you need help understanding the basics of logic I'm sure someone would be more than happy to get you started...
• 09-10-2001
charlie
Quote:

Originally posted by Govtcheez
Y'know - in the time it took you to type out all that stuff, you coulda looked up the answers and actually solved them....
I have the answers i just wanna confirm it with you.....seriously...
• 09-10-2001
Govtcheez
Really... Well, then, post the answers and we'll tell you if they're right.
• 09-10-2001
iain

is it correct that......

and someone will help you, this is nothing personal against you, but homework is for a purpose - you are meant to do it.
• 09-10-2001
charlie
Quote:

Originally posted by iain
i detect a homework question!

1) e
2) b or d
3) b
4 ) d
5) a
6) d
7 ) d
• 09-10-2001
charlie
Quote:

Originally posted by Govtcheez
Really... Well, then, post the answers and we'll tell you if they're right.
1) e
2) b or d
3) b
4 ) d
5) a
6) d
7 ) d

correct me if iam wrong and why please....?
i learn off others teaching me also
• 09-10-2001
Stoned_Coder
if you have your own compiler then it would take zero effort to check your answers yourself. If you dont then get one.How can you expect to learn c++ without a compiler. Go here to get one that is free!

Put a little effort in and you will learn much faster.