FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

C++ QUIZ

 


AhmedSalmanJamal
Can anyone please tell me the difference between the output of the two codes?

FIRST Code:

Code:
void Example1Chap2V1()
{
    cout << "Please enter your first name: ";
    string name;
    cin >> name;
    cout << endl;
   
    const string greetings = "Hello " + name + "!";
   
    const int pad = 1;
    const int rows = pad*2 + 3;
   
    const string::size_type cols = greetings.size() + pad*2 + 2;
   
    for(int r = 0; r < rows; ++r)
    {       
        string::size_type c = 0;
        while(c != cols)
        {
            if((r == pad + 1) && (c == pad + 1))
            {
                cout << greetings;
                c += greetings.size();
            }
            else
            {
                if((r == 0) || (r == rows - 1) || (c == 0) || (c == cols - 1) )
                {
                    cout << "*";
                }
                else
                {
                    cout << " ";                   
                }               
                ++c;
            }
        }                   
        cout << endl; 
    }
}


SECOND Code:

Code:
void Example1Chap2V2()
{
    cout << "Please enter your first name: ";
    string name;
    cin >> name;
   
    const string greeting = "Hello, " + name + "!";
   
    const int pad = 1;
   
    const int rows = pad * 2 + 3;
    const string::size_type cols = greeting.size() + pad * 2 + 2;
   
    cout << endl;
   
    for(int r = 0; r != rows; ++r)
    {
        string::size_type c = 0;
        while(c != cols)
        {
            if(r == pad + 1 && c == pad + 1)
            {
                cout << greeting;
                c += greeting.size();
            }
            else
            {
                if(r == 0 || r == rows - 1 || c == 0 || c == cols - 1)
                {
                    cout << "*";
                }
                else
                    cout << " ";
                ++c;
            }
        }
        cout << endl;
    }
}
mogyoro
Your jockeing right? I just run thru the code ,so waht's tha point, that was easy...

cout << endl; //is the only difference in output, right?
mogyoro
and the "greetings" part... so...
BruceTheDauber
No difference that I can see. There are several small differences in the code, but nothing significant (unless I missed it).
AhmedSalmanJamal
The difference in the output is quite significant although the differences between the two pieces of codes look quite subtle. If you compile and run both the codes then you will find the difference... we should never underestimate the subtle differences in codes... If you wish you may try to find the differences in the code again Smile I can assure you that there is a big difference in the outputs of both the codes Exclamation
n0obie4life
This forum isn't your contest forum Evil or Very Mad.

Run your contests in the contests forum Wink.
http://www.frihost.com/forums/vf-11.html

-close-
This topic is locked: you cannot edit posts or make replies.    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.