text-formatting program c++ problem

S

shoo

Any one know how to do this? thank


Write a simple text-formatting program that produces neatly printed
output from input text containing embedded command lines that
determine how to format the output; all lines begin with a period are
command lines. The task of the program is to collect words from input
lines, fill output lines with those words, adjust the margins, and
print the result. Your programs should handle the commands shown in
Table 1 and should make use of functions.


Table 1 Text formatting commands for Lab #2
Command

..ce n
..ce
..in ±n
..in n
..in
..po ±n
..po n
..po
..ll n
..ll
..ls n
..ls
..sp n
..sp
..ad
..na
Description

Centre the next n lines (n might be 0)
Centre the next line
Increase (decrease) the indentation by n spaces
Set the indentation to n spaces
Reset indentation to default (0 spaces)
Increase (decrease) the left margin (page offset) by n spaces
Set the left margin (page offset) to n spaces
Reset margin to default (10 spaces)
Set line length to n spaces
Reset line length to default (100 spaces)
Set interline spacing to n (n = 2 gives double spacing)
Reset to single spacing
Put (n * CurrentLineSpacing) blank lines in the output
Put (1 * CurrentLineSpacing) blank lines in the output
Start adjustment of right margin (default; works in fill mode only)
Stop adjustment of right margin


When the program is filling output lines with input words, it is said
to be operating in fill mode. When not operating in fill mode, lines
should be printed exactly as they appear in the input. When operating
in fill mode, the program also may have to pad each output line evenly
with blank characters to produce a straight right margin; the program
is said to be operating in adjust mode when operating in this manner.
When not in adjust mode, the program will fill output lines but the
right margin will be jagged.

Your program should begin execution using the following default
values: line length is 100 characters, line spacing is 1 (single
spacing), margin is 10 characters, indentation level is 0 characters.
The program begins execution in fill mode, adjusting the right margin.
These defaults should remain in effect until changed by the
appropriate commands. A period, question mark, or exclamation point
should be followed by 2 blank spaces in the output, unless it is at
the end of an output line. A new paragraph should be separated from
the previous by an extra CurrentLineSpacing lines.
 
J

Johan

shoo said:
Any one know how to do this? thank


Write a simple text-formatting program that produces neatly printed
output from input text containing embedded command lines that
determine how to format the output; all lines begin with a period are
command lines. The task of the program is to collect words from input
lines, fill output lines with those words, adjust the margins, and
print the result. Your programs should handle the commands shown in
Table 1 and should make use of functions.


Table 1 Text formatting commands for Lab #2
Command

.ce n
.ce
.in ±n
.in n
.in
.po ±n
.po n
.po
.ll n
.ll
.ls n
.ls
.sp n
.sp
.ad
.na
Description

Centre the next n lines (n might be 0)
Centre the next line
Increase (decrease) the indentation by n spaces
Set the indentation to n spaces
Reset indentation to default (0 spaces)
Increase (decrease) the left margin (page offset) by n spaces
Set the left margin (page offset) to n spaces
Reset margin to default (10 spaces)
Set line length to n spaces
Reset line length to default (100 spaces)
Set interline spacing to n (n = 2 gives double spacing)
Reset to single spacing
Put (n * CurrentLineSpacing) blank lines in the output
Put (1 * CurrentLineSpacing) blank lines in the output
Start adjustment of right margin (default; works in fill mode only)
Stop adjustment of right margin


When the program is filling output lines with input words, it is said
to be operating in fill mode. When not operating in fill mode, lines
should be printed exactly as they appear in the input. When operating
in fill mode, the program also may have to pad each output line evenly
with blank characters to produce a straight right margin; the program
is said to be operating in adjust mode when operating in this manner.
When not in adjust mode, the program will fill output lines but the
right margin will be jagged.

Your program should begin execution using the following default
values: line length is 100 characters, line spacing is 1 (single
spacing), margin is 10 characters, indentation level is 0 characters.
The program begins execution in fill mode, adjusting the right margin.
These defaults should remain in effect until changed by the
appropriate commands. A period, question mark, or exclamation point
should be followed by 2 blank spaces in the output, unless it is at
the end of an output line. A new paragraph should be separated from
the previous by an extra CurrentLineSpacing lines.

Hi,

Pay me $5.000 and I do for you

John
 
T

Thomas Matthews

[snip -- homework assignment details]
Hi,

Pay me $5.000 and I do for you

John

Was that five dollars (accurate to 1/10 cent) or
was that five thousand dollars?

I wouldn't do this for five dollars since that barely
covers the cost of the frustration in transmission
of the product.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
 
T

Thomas Matthews

shoo said:
Any one know how to do this? thank
[snip -- homework assignment]

When asking for people to write your homework
assignment, it is customary to provide the
following information:

1. Instructor's email address
Homework assignments will be directly emailed
to you and the instructor to make sure there
is no corruption of the provider's material.
See "fraud".

2. Instructor's office phone number.
Include the country code.
The provider of the homework will want to
verify receipt of the homework from the
instructor.

The above information is also required in case
clarification is needed about the assignment.

3. Bartering / Payment suggestions.
Guaranteed payment will produce better work
from the homework provider. The higher the
payment, the better the work.

4. The due date of the assignment.
The provider needs to know when to deliver
the product. The more advanced notification,
the cheaper the price of the product or service.

Evil[1] and bad things will happen if any of the above
is left out.

***** EXCEPTION TO ABOVE RULES *****
Posting your assignment, along with your effort
or work will grant you free assistance and none
of the above is required. Read the FAQs below
on how to post.

------
[1] Some kinds of evil in a homework product are
1. Obfuscation -- Search web for "obfuscated code contest"
2. Using advanced topics or techniques.
3. Coding using assembly language.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
 
K

Karl Heinz Buchegger

shoo said:
Any one know how to do this? thank

The first thing you need to do is to define tasks you need
to do in order to solve the whole assignment. Don't get frustrated
by the complexity but break that complexity down into managable
chunks.

The first thing I notice in this assignment is that obviously
you have some sort of input. This input is organized into lines.
Those lines can be of 2 types, depending on the first character of
that line:
data lines
command lines

So your first subtask could be:
read the input and differentiate between those 2 types of input
lines.

That's your first subgoal in doing that assignment. When you reached that
goal, study the assignment again and decide what your next subgoal should
be, etc.. until the whole assignment is done.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top