Thread: C++ logics

  1. #1
    charlie
    Guest

    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

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    Y'know - in the time it took you to type out all that stuff, you coulda looked up the answers and actually solved them....

  3. #3
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385
    i detect a homework question!
    try it yourself first, come back with the answers youve got and then we'll help you.
    Monday - what a way to spend a seventh of your life

  4. #4
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595

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

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  5. #5
    charlie
    Guest
    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...

  6. #6
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    Really... Well, then, post the answers and we'll tell you if they're right.

  7. #7
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385
    Post your answers along with the questions, or rephrase your question to include the answers

    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.
    Come back with your answers.
    Monday - what a way to spend a seventh of your life

  8. #8
    charlie
    Guest
    Originally posted by iain
    i detect a homework question!
    try it yourself first, come back with the answers youve got and then we'll help you.
    1) e
    2) b or d
    3) b
    4 ) d
    5) a
    6) d
    7 ) d

  9. #9
    charlie
    Guest
    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

  10. #10
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    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.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with some game logics
    By godhand in forum Game Programming
    Replies: 1
    Last Post: 05-12-2004, 03:52 AM