What does Accelerated C++ exercise 5-5 mean?

Discussion in 'C++' started by Lambda, Apr 19, 2008.

  1. Lambda

    Lambda Guest

    I'm trying to complete all the exercises of Accelerated C++.

    I'm not sure what does the exercise 5-5 mean. And how about 5-9?

    Thanks
    Lambda, Apr 19, 2008
    #1
    1. Advertising

  2. Lambda

    utab Guest

    On Apr 19, 1:34 pm, Lambda <> wrote:
    > I'm trying to complete all the exercises of Accelerated C++.
    >
    > I'm not sure what does the exercise 5-5 mean. And how about 5-9?
    >
    > Thanks


    That is quite obvious from the text I guess ;)

    Let me explain, there are some functions given in chapter 5 to frame
    and concatenate some text, this is an extension of those functions.

    + You should write the text centered in the frame. Hint: think about
    how can a text can be centered in a frame. And this will also answer
    the question if this is possible or not.

    + for 5.9 lets say you keep the words in a vector:

    try
    TRY
    accelerated
    ACCELERATED

    so the new order should be

    accelerated
    try
    TRY
    ACCELERATED

    Hint you might use a function "isupper" or "islower" from cctype

    HTH,
    utab, Apr 19, 2008
    #2
    1. Advertising

  3. Lambda

    Lambda Guest

    On Apr 19, 9:14 pm, utab <> wrote:
    > On Apr 19, 1:34 pm, Lambda <> wrote:
    >
    > > I'm trying to complete all the exercises of Accelerated C++.

    >
    > > I'm not sure what does the exercise 5-5 mean. And how about 5-9?

    >
    > > Thanks

    >
    > That is quite obvious from the text I guess ;)
    >
    > Let me explain, there are some functions given in chapter 5 to frame
    > and concatenate some text, this is an extension of those functions.
    >
    > + You should write the text centered in the frame. Hint: think about
    > how can a text can be centered in a frame. And this will also answer
    > the question if this is possible or not.


    Does that mean convert
    **************
    * this is an *
    * example *
    * to *
    * illustrate *
    * framing *
    **************
    to
    **************
    * this is an *
    * example *
    * to *
    * illustrate *
    * framing *
    **************
    ?
    It's always possible except for strings that is too long,
    for example, more than 80 characters.

    >
    > + for 5.9 lets say you keep the words in a vector:
    >
    > try
    > TRY
    > accelerated
    > ACCELERATED
    >
    > so the new order should be
    >
    > accelerated
    > try
    > TRY
    > ACCELERATED
    >
    > Hint you might use a function "isupper" or "islower" from cctype


    The question does not mention the order inside the upper and lower
    groups.
    I think I just need to separate the input to two groups, right?

    I can always get usefull information from this group, thank you utab.

    >
    > HTH,
    Lambda, Apr 20, 2008
    #3
  4. Lambda

    utab Guest

    On Apr 20, 4:00 am, Lambda <> wrote:
    > On Apr 19, 9:14 pm, utab <> wrote:
    >
    >
    >
    > > On Apr 19, 1:34 pm, Lambda <> wrote:

    >
    > > > I'm trying to complete all the exercises of Accelerated C++.

    >
    > > > I'm not sure what does the exercise 5-5 mean. And how about 5-9?

    >
    > > > Thanks

    >
    > > That is quite obvious from the text I guess ;)

    >
    > > Let me explain, there are some functions given in chapter 5 to frame
    > > and concatenate some text, this is an extension of those functions.

    >
    > > + You should write the text centered in the frame. Hint: think about
    > > how can a text can be centered in a frame. And this will also answer
    > > the question if this is possible or not.

    >
    > Does that mean convert
    > **************
    > * this is an *
    > * example *
    > * to *
    > * illustrate *
    > * framing *
    > **************
    > to
    > **************
    > * this is an *
    > * example *
    > * to *
    > * illustrate *
    > * framing *
    > **************
    > ?
    > It's always possible except for strings that is too long,
    > for example, more than 80 characters.


    Ok of course it is limited. a sample output which also gives
    indications if the lines could be centered or not:

    Info for the lines whether they can be centered or not
    Line 1 can be centered
    Line 2 can be centered
    Line 3 can not be centered
    Line 4 can not be centered
    Line 5 can not be centered
    *********************************************************************************************
    * this is a good this is a good this is a good this is a good this is
    a good this is a good *
    *
    example *
    *
    to *
    *
    illustrate *
    * centered
    framing *
    *********************************************************************************************

    Ok you are done. Concerning its feasibility for evenness: there are
    things to check there are two '*' chararacters
    on the text part of the picture. So a simple algebra should lead to
    somewhere right, for instance;

    Lets say: the string is "Hello lambda, how are you?" consists of 26
    chars.

    If this is the longest one in the whole text you are using, then the
    adjustment should be done to accommodate this fact, which you solved
    above. To adjust a string of length, say 14 chars, what do you do?

    How many spacings should be on the right and left?
    if you have a string of 15 chars, then is it possible? (This was meant
    I guess by the feasibility ;) )
    >
    >
    >
    >
    >
    > > + for 5.9 lets say you keep the words in a vector:

    >
    > > try
    > > TRY
    > > accelerated
    > > ACCELERATED

    >
    > > so the new order should be

    >
    > > accelerated
    > > try
    > > TRY
    > > ACCELERATED

    >
    > > Hint you might use a function "isupper" or "islower" from cctype

    >
    > The question does not mention the order inside the upper and lower
    > groups.
    > I think I just need to separate the input to two groups, right?


    That was what I understood but Andrew Koenig also sometimes seems to
    post and answer questions on his book, if you are lucky or I am lucky,
    he can leave a message ;)

    >
    > I can always get usefull information from this group, thank you utab.
    >
    >

    You are welcome !
    >
    > > HTH,
    utab, Apr 20, 2008
    #4
  5. Lambda

    utab Guest

    On Apr 20, 9:40 am, utab <> wrote:
    > On Apr 20, 4:00 am, Lambda <> wrote:
    >
    >
    >
    > > On Apr 19, 9:14 pm, utab <> wrote:

    >
    > > > On Apr 19, 1:34 pm, Lambda <> wrote:

    >
    > > > > I'm trying to complete all the exercises of Accelerated C++.

    >
    > > > > I'm not sure what does the exercise 5-5 mean. And how about 5-9?

    >
    > > > > Thanks

    >
    > > > That is quite obvious from the text I guess ;)

    >
    > > > Let me explain, there are some functions given in chapter 5 to frame
    > > > and concatenate some text, this is an extension of those functions.

    >
    > > > + You should write the text centered in the frame. Hint: think about
    > > > how can a text can be centered in a frame. And this will also answer
    > > > the question if this is possible or not.

    >
    > > Does that mean convert
    > > **************
    > > * this is an *
    > > * example *
    > > * to *
    > > * illustrate *
    > > * framing *
    > > **************
    > > to
    > > **************
    > > * this is an *
    > > * example *
    > > * to *
    > > * illustrate *
    > > * framing *
    > > **************
    > > ?
    > > It's always possible except for strings that is too long,
    > > for example, more than 80 characters.

    >
    > Ok of course it is limited. a sample output which also gives
    > indications if the lines could be centered or not:
    >
    > Info for the lines whether they can be centered or not
    > Line 1 can be centered
    > Line 2 can be centered
    > Line 3 can not be centered
    > Line 4 can not be centered
    > Line 5 can not be centered
    > *********************************************************************************************
    > * this is a good this is a good this is a good this is a good this is
    > a good this is a good *
    > *
    > example *
    > *
    > to *
    > *
    > illustrate *
    > * centered
    > framing *
    > *********************************************************************************************
    >
    > Ok you are done. Concerning its feasibility for evenness: there are
    > things to check there are two '*' chararacters
    > on the text part of the picture. So a simple algebra should lead to
    > somewhere right, for instance;
    >
    > Lets say: the string is "Hello lambda, how are you?" consists of 26
    > chars.
    >
    > If this is the longest one in the whole text you are using, then the
    > adjustment should be done to accommodate this fact, which you solved
    > above. To adjust a string of length, say 14 chars, what do you do?
    >
    > How many spacings should be on the right and left?
    > if you have a string of 15 chars, then is it possible? (This was meant
    > I guess by the feasibility ;) )
    >
    >
    >
    >
    >
    > > > + for 5.9 lets say you keep the words in a vector:

    >
    > > > try
    > > > TRY
    > > > accelerated
    > > > ACCELERATED

    >
    > > > so the new order should be

    >
    > > > accelerated
    > > > try
    > > > TRY
    > > > ACCELERATED

    >
    > > > Hint you might use a function "isupper" or "islower" from cctype

    >
    > > The question does not mention the order inside the upper and lower
    > > groups.
    > > I think I just need to separate the input to two groups, right?

    >
    > That was what I understood but Andrew Koenig also sometimes seems to
    > post and answer questions on his book, if you are lucky or I am lucky,
    > he can leave a message ;)
    >
    >
    >
    >
    >
    > > I can always get usefull information from this group, thank you utab.

    >
    > You are welcome !
    >
    > > > HTH,


    Sorry for the output it can still be used for relatively long strings.
    utab, Apr 20, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pete
    Replies:
    14
    Views:
    911
    Roland Pibinger
    Jan 3, 2006
  2. utab

    Accelerated C++ exercise

    utab, Feb 13, 2006, in forum: C++
    Replies:
    2
    Views:
    459
    Diego Martins
    Feb 14, 2006
  3. utab
    Replies:
    3
    Views:
    378
  4. utab
    Replies:
    8
    Views:
    518
    Default User
    Apr 16, 2006
  5. arnuld
    Replies:
    10
    Views:
    736
Loading...

Share This Page