Velocity Reviews > C++ > What does Accelerated C++ exercise 5-5 mean?

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

Lambda
Guest
Posts: n/a

 04-19-2008
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

utab
Guest
Posts: n/a

 04-19-2008
On Apr 19, 1:34 pm, Lambda <(E-Mail Removed)> 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,

Lambda
Guest
Posts: n/a

 04-20-2008
On Apr 19, 9:14 pm, utab <(E-Mail Removed)> wrote:
> On Apr 19, 1:34 pm, Lambda <(E-Mail Removed)> 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,

utab
Guest
Posts: n/a

 04-20-2008
On Apr 20, 4:00 am, Lambda <(E-Mail Removed)> wrote:
> On Apr 19, 9:14 pm, utab <(E-Mail Removed)> wrote:
>
>
>
> > On Apr 19, 1:34 pm, Lambda <(E-Mail Removed)> 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,

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

You are welcome !
>
> > HTH,

utab
Guest
Posts: n/a

 04-20-2008
On Apr 20, 9:40 am, utab <(E-Mail Removed)> wrote:
> On Apr 20, 4:00 am, Lambda <(E-Mail Removed)> wrote:
>
>
>
> > On Apr 19, 9:14 pm, utab <(E-Mail Removed)> wrote:

>
> > > On Apr 19, 1:34 pm, Lambda <(E-Mail Removed)> 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,
>
>
>
>
>
> > 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.