C++ code examples for job interviews

Q: Write a short code using C++ to print out all odd number from 1 to 100 using a for loop(Asked by Intacct.com people)

for( unsigned int i = 1; i < = 100; i++ )
    if( i & 0x00000001 )
        cout << i<<",";

ISO layers and what layer is the IP operated from?( Asked by Cisco system people)

cation, Presentation, Session, Transport, Network, Data link and Physical. The IP is operated in the Network layer.

3.Q: Write a program that ask for user input from 5 to 9 then calculate the average( Asked by Cisco system people)

A.int main()
{
int MAX=4;
int total =0;
int average=0;
int numb;
cout<<"Please enter your input from 5 to 9";
cin>>numb;
if((numb <5)&&(numb>9))
cout<<"please re type your input";
else
for(i=0;i<=MAX; i++)
{
total = total + numb;
average= total /MAX;
}
cout<<"The average number is"<<average<<endl;

return 0;
}

4.Q: Can you be bale to identify between Straight- through and Cross- over cable wiring? and in what case do you use Straight- through and Cross-over? (Asked by Cisco system people)

A. Straight-through is type of wiring that is one to to one connection Cross- over is type of wiring which those wires are got switched

We use Straight-through cable when we connect between NIC Adapter and Hub. Using Cross-over cable when connect between two NIC Adapters or sometime between two hubs.

5.Q: If you hear the CPU fan is running and the monitor power is still on, but you did not see any thing show up in the monitor screen. What would you do to find out what is going wrong? (Asked by WNI people)

A. I would use the ping command to check whether the machine is still alive(connect to the network) or it is dead.

This entry was posted in C++. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

16 Comments on C++ code examples for job interviews

  1. Tharuna Dylan
    Posted 1/2/2004 at 7:24 pm | Permalink

    Q2 answer is all wrong. see my earlier post which got truncated for some odd reason.

  2. Tharuna Dylan
    Posted 1/2/2004 at 7:25 pm | Permalink

    In Q2:
    if((numb 9))
    The above is always false.
    It should be written as:
    if ( (numb 9) )

    The for loop in there simply adds the same number (numb) MAX+1 times i.e 5 times. And averages it by dividing by 4.
    The for loop should iterate to take user input and then add that to the total and then divide it by the number of inputs entered by the user.

    Of course, this needs a proper loop termination condition. that would depend on whether the user is expected to enter a number only once or multiple times. if multiple times, how many times before we set off do to the average.

    correct me if i am missing something here.

  3. Tharuna Dylan
    Posted 1/2/2004 at 7:27 pm | Permalink

    I am sorry, special chars like %,& seem to truncate the message.

    What i mean above is that there should be a logical OR comparison, not logical AND.

    And i was asking why we couldnt use modulus by 2 to find out if a number was even or odd? thanks!

  4. George Swan
    Posted 1/27/2004 at 7:58 am | Permalink

    In the first example the test for whether the number is odd, in the second statement, would be unnecessary, if i was incremented by 2 in the for loop, rather than by 1, as in the example.

  5. George Swan
    Posted 1/27/2004 at 8:13 am | Permalink

    It seems to me that question 3 is so poorly written that it is entirely unclear what the writer meant. The program you put as the correct answer makes no sense. It is not a sensible thing to do. The complicated operations in your example answer are logically equivalent with merely dividing the number the user specified by 2. The answer given here suggests the person being tested was someone who lacks a familiarity with basic arithmetic.

    I suspect that the person who wrote the original question wanted the program to ask for input from the user five to nine times.

  6. George Swan
    Posted 1/27/2004 at 8:51 am | Permalink

    In question 5, if the computer in question had a keyboard, the first thing I would try would be to tap the shift key. If the computer had turned off the display, to save power, after a period of inactivity, tapping a key would be enough to cause the display to light up again. The shift key counts as keyboard activity, but does not send an actual character. This would be important if the computer had been running an application that was waiting for user input prior to turning off the display due to keyboard inactivity.

    If that did not produce a result the next step would be system independent. Your question did not specifiy what operating system the computer in question was running. But checking to see if the cables for the monitor remained attached should always be safe.

    Fow what it is worth, this question looks like it was posed by someone who doesn’t know about computer hardware. Modern computers usually come with at least two fans — one in the power supply and one on the CPU. It would be extremely unusual to be able to hear the CPU fan over the power supply fan.

  7. George Swan
    Posted 1/27/2004 at 9:07 am | Permalink

    Regarding question 4 — ethernet cables are not the only kind of cables that come in straight-through and cross-over flavors. Serial cables, like those used between a computer and an external modem, also come in straight-through and cross-over flavors.

    The question might have been asking how to distinguish between a straight-through and a cross-over cable. The answer to this question is that the wires in an ethernet cable are color-coded. If you hold up the two RJ45 connectors on an ethernet cable, and compare the colours, they will be in the same order on each connector if the cable is a straight through. And some of the wires will be in a different order if the cable is a cross-over cable.

    What the answer given as correct leaves out is that when using a cross-over cable to connect to computers you are restricted to only having those two computers on the network.

  8. Posted 1/27/2004 at 11:14 am | Permalink

    Thanks for the input, George, I will take some of the quotes and incorporate them into the main page.

  9. Tim
    Posted 11/12/2004 at 7:17 am | Permalink

    for #5 to extend George Swan’s comment: on PCs I ususally try CapsLock first.

  10. Vishwa
    Posted 3/20/2005 at 4:00 pm | Permalink

    I think this is the answer for Q2..please correct me if its wrong

    #include “iostream.h”

    void main()
    {
    for(int i=1;i

  11. Vishwa
    Posted 3/20/2005 at 4:03 pm | Permalink

    #include “iostream.h”
    void main()
    {
    for(int i=1;i

  12. Wattos
    Posted 5/5/2005 at 12:56 pm | Permalink

    for number one:
    a much better and faster way is the following:
    Loop is way shorter and doesnt involve any testing ^_^

    for( unsigned int i = 1; i

  13. yonas
    Posted 1/5/2007 at 2:33 pm | Permalink

    #include
    #include
    #include
    #include
    #define size 51

    void mainm(void);
    void entry(void);
    void modify(void);
    void delet(void);
    void view(void);

    // Structure

    struct hoteldata
    {
    char name[size][30], nic[size][20],rdate[size][12],cdate[size][12];
    };

  14. Bhaskar Krishna
    Posted 1/12/2008 at 10:05 am | Permalink

    Write a short code using C++ to print out all odd number from 1 to 100 using a for loop(Asked by Intacct.com people)

    for(int i=1; i

  15. Bhaskar Krishna
    Posted 1/12/2008 at 10:06 am | Permalink

    for (int i=1; i

  16. ben
    Posted 11/1/2008 at 2:09 pm | Permalink

    I think the following code is a short code using C++ to print out all odd number from 1 to 100 using a for loop
    correct me if there is any logical or even syntax error
    answer:
    for(int i=0;i<=100;i++)
    {
    int n=i%2;
    if(n==1)
    {
    cout<<i<<”\n”;
    }
    }

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*