Programming Assignment 2 for Computer System Concepts | CS 350, Assignments of Computer Science

Material Type: Assignment; Professor: Cukic; Class: Computer System Concepts; Subject: Computer Science; University: West Virginia University; Term: Fall 2007;

Typology: Assignments

Pre 2010

Uploaded on 07/30/2009

koofers-user-alz
koofers-user-alz 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 350, Fall 08
PROGRAMMING ASSIGNMENT #2
Type-Justification in Word Processing
(You may download this assignment statement from http://www.csee.wvu.edu/~cukic)
Deadline: 11:59 PM, Friday, October 17th, 2007
Generally speaking, the success of computing is attributable to the exciting growth in word processing. One important function
in word processing systems is type-justification, i.e., the alignment of words to both the left and the right margins of the page.
This generates professional looking documents. Type justification can be accomplished on computer systems by inserting one
or more characters between each of the words in a line, so that the rightmost word aligns with the right margin.
Write a program that reads text from a text file and prints this text in a type-justified format. Assume that the text is to be
printed on 8 ½-inch-wide paper, and that one inch margins are to be allowed on both the left and the right sides of the printed
page. Assume that the computer prints 10 characters to the horizontal inch. Therefore, in essence, your program should print
between 5 ½ inches of text (55 characters per line) and 8 inches (80 characters per line).
As in the previous assignment, your program should start by asking the user for the name of the file in which the text is stored.
Then, user should be asked to type in the number of characters per line in the right justified printout. Your program should
proceed by reading the text (read the whole file) and converting it in the internal representation. Please note that 25% of the
grade will be taken off from programs that do not conform with the input file specification. The program MUST then ask
for the line size. Please have in mind that the input file can contain any ASCII character, not just letters or numbers.
Since there are no limitations on the length of the text, the internal representation should be built using the dynamic data
structures. Each token (word, number or punctuation mark) from the paragraph should be stored internally in a structure,
consisting of a string, a pointer to the next word from the text and, possibly, some additional information. For example, let us
assume the input file para1.txt contains the following paragraph.
A knowledge and appreciation of interrelationship between places and events
is essential if we are to make informed decisions about their place in the
world community. Therefore,
the extent of basic geographic and historical literacy may play crucial role in decision making in global international
markets.
An abstraction of the internal representation of this paragraph is:
AÆknowledgeÆandÆappreciationÆofÆinterrelationshipÆbetweenÆplacesÆandÆeventsÆisÆessentialÆifÆwe
ÆareÆtoÆmakeÆinformedÆdecisionsÆaboutÆtheirÆplaceÆinÆtheÆworldÆcommunityÆ.ÆThereforeÆ,Æthe
ÆextentÆofÆbasicÆgeographicÆandÆhistoricalÆliteracyÆmayÆplayÆcrucialÆroleÆinÆdecisionÆmakingÆin
ÆglobalÆinternationalÆmarketsÆ.ÆEOF
Please note that this representation ignores all the white space characters, as they are not important for type-justification. Your
program should create the left and right aligned printout of this (and any other) paragraph by placing exactly the required
number of characters (including white spaces) per line. Words in the text must not be hyphenated (split across 2 lines). The
white spaces included in a line of printout should be evenly distributed throughout the line. Each line should contain the
maximal possible number of words, i.e., do not start a new line unless the next word in the list cannot be fit in the current line.
Make your own decisions regarding the policy of inserting white space characters (padding the line). Make sure that your
program frees dynamically allocated memory space once it is not needed. One of the valid printouts of the paragraph from file
para1.txt using a 65 characters long line is as follows:
pf2

Partial preview of the text

Download Programming Assignment 2 for Computer System Concepts | CS 350 and more Assignments Computer Science in PDF only on Docsity!

CS 350, Fall 08

PROGRAMMING ASSIGNMENT

Type-Justification in Word Processing

(You may download this assignment statement from http://www.csee.wvu.edu/~cukic)

Deadline: 11:59 PM, Friday, October 17th, 2007

Generally speaking, the success of computing is attributable to the exciting growth in word processing. One important function in word processing systems is type-justification , i.e., the alignment of words to both the left and the right margins of the page. This generates professional looking documents. Type justification can be accomplished on computer systems by inserting one or more characters between each of the words in a line, so that the rightmost word aligns with the right margin.

Write a program that reads text from a text file and prints this text in a type-justified format. Assume that the text is to be printed on 8 ½-inch-wide paper, and that one inch margins are to be allowed on both the left and the right sides of the printed page. Assume that the computer prints 10 characters to the horizontal inch. Therefore, in essence, your program should print between 5 ½ inches of text ( 55 characters per line) and 8 inches (80 characters per line).

As in the previous assignment, your program should start by asking the user for the name of the file in which the text is stored. Then, user should be asked to type in the number of characters per line in the right justified printout. Y our program should proceed by reading the text (read the whole file) and converting it in the internal representation. Please note that 25% of the grade will be taken off from programs that do not conform with the input file specification. T he program MUST then ask for the line size. Please have in mind that the input file can contain any ASCII character, not just letters or numbers.

Since there are no limitations on the length of the text, the internal representation should be built using the dynamic data structures. Each token (word, number or punctuation mark) from the paragraph should be stored internally in a structure, consisting of a string, a pointer to the next word from the text and, possibly, some additional information. For example, let us assume the input file para1.txt contains the following paragraph.

A knowledge and appreciation of interrelationship between places and events is essential if we are to make informed decisions about their place in the world community. Therefore, the extent of basic geographic and historical literacy may play crucial role in decision making in global international markets.

An abstraction of the internal representation of this paragraph is:

AÆknowledgeÆandÆappreciationÆofÆinterrelationshipÆbetweenÆplacesÆandÆeventsÆisÆessentialÆifÆwe ÆareÆtoÆmakeÆinformedÆdecisionsÆaboutÆtheirÆplaceÆinÆtheÆworldÆcommunityÆ.ÆThereforeÆ,Æthe ÆextentÆofÆbasicÆgeographicÆandÆhistoricalÆliteracyÆmayÆplayÆcrucialÆroleÆinÆdecisionÆmakingÆin ÆglobalÆinternationalÆmarketsÆ.ÆEOF

Please note that this representation ignores all the white space characters, as they are not important for type-justification. Your program should create the left and right aligned printout of this (and any other) paragraph by placing exactly the required number of characters (including white spaces) per line. Words in the text must not be hyphenated (split across 2 lines). The white spaces included in a line of printout should be evenly distributed throughout the line. Each line should contain the maximal possible number of words, i.e., do not start a new line unless the next word in the list cannot be fit in the current line. Make your own decisions regarding the policy of inserting white space characters (padding the line). Make sure that your program frees dynamically allocated memory space once it is not needed. One of the valid printouts of the paragraph from file para1.txt using a 65 characters long line is as follows:

A knowledge and appreciation of interrelationship between places and events is essential if we are to make informed decisions about their place in the world community. Therefore, the extent of basic geographic and historical literacy may play crucial role in decision making in global international markets.

However, if the user wants the same text right-aligned with 72 characters per line, the result is as follows:

A knowledge and appreciation of interrelationship between places and events is essential if we are to make informed decisions about their place in the world community. Therefore, the extent of basic geographic and historical literacy may lay crucial role in decision making in global international markets.

Once you solve the problem of type-justification of a paragraph, the next step is to allow input files that contain multiple paragraphs. The indication of a new paragraph in the input file will be the two or more “new line” characters in sequence. Your program may treat paragraphs independently and create different linked lists for each.

Submission

In order to be graded, you must submit the following:

  1. Submit all the program files following the procedure described in my Web page (http://www.csee.wvu.edu/~cukic/CS350 follow the link “How to submit programming assignments”). Programs submitted through e-mail will be rejected! It is your responsibility to submit programs successfully. 2. Submit program documentation in class on Tuesday, Oct. 21st. The documentation should contain a short description of program’s main data structures (what is the structure you use for representing the tokens, which fields it includes, is it a single or double linked list, etc.), description of your algorithm (how do you determine the position for line breaks, how do you treat punctuation characters, your approach to padding with white space characters…), and the algorithm imposed limitations (if any). If your program does not work properly or if it does not compile, state this clearly in the documentation. 3. Submit the listing of your code. Use a small font for printing your code. Please make sure that your program is well documented, use in-line comments to explain what certain parts of your program do. The header of the file MUST contain your name, and your account name. I will not grade your assignment unless I have program documentation and listing.

Please note that UNIX keeps track of the submission time. You are advised to keep a copy of your submission in your own account (with the original time-stamp). To receive full credit, your program must be submitted by the deadline. Remember that late assignments will be penalized by 5% of the grade for each day of delay. No programs or their accompanying documentation will be accepted after midnight, Sunday, Oct. 26th.

Programs that cannot be compiled will receive up to 40% of the assignment grade. Only well written, well documented, fully functional programs, will receive a full credit.

Academic Honesty:

Each student is expected to develop his/her assignment alone. Do not share programs, or program parts, with your colleagues. Violators of this policy will be held responsible for academic dishonesty, and will bear consequences in accordance to the rules and regulations of West Virginia University.