FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free 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-
Related topics
Command and Conquer
Funny C variable
What can I do with C-Panel?
Quiz filmowy
HELP ME in C++
Languages in c++
C++ TUTORIAL : INTRODUCTION TO C++
I searching for a site
Image Processing in C++ by Shirish
C en C++
C# tutorials
C en C++
C#,Visual Basic.NET,Visual Studio.NET Videos
Earth Day Quiz
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-2011 Frihost, forums powered by phpBB.