Computer Science and Programming

Rowan University
Prof. Gregory Safko

Lab 9

Assigned: April 28, 2003

Due April 30, 2003

 


1. External Data Formatting, Part A (lab09a.cpp)

Write a program that will take an external flat file, and remove spaces following commas. Many times, this is how programmers receive data from external sources. Sometimes the "sending" programmer doesn't know how to cut off spaces after the commas, so it's up to the "receiving" programmer (us!)  to do their job for them ;)

 

As a test, given the following external file data:

 

Samuel Adams, 38, Boston

Homer Simpson, 41, Springfield

Tony Soprano, 48, Newark

Jack Gallo, 61, New York

 

When you run it against your program, it should re-format it to the following:

 

Samuel Adams,38,Boston

Homer Simpson,41,Springfield

Tony Soprano,48,Newark

Jack Gallo,61,New York

 

(You can assume that only one space will follow the commas)

 


2. External Data Formatting, Part B (lab09b.cpp)

Write a program that will take an external flat file, and add a comma to the end of the line.

 

As a test, given the following external file data:

 

Samuel Adams,38,Boston

Homer Simpson,41,Springfield

Tony Soprano,48,Newark

Jack Gallo,61,New York

 

When you run it against your program, it should re-format it to the following:

 

Samuel Adams,38,Boston,

Homer Simpson,41,Springfield,

Tony Soprano,48,Newark,

Jack Gallo,61,New York,

 


3. External Data Formatting, Part C (lab09c.cpp)

Write a program that will take an external flat file, and count the lines of data in it.

 

As a test, given the following external file data:

 

Samuel Adams,38,Boston,

Homer Simpson,41,Springfield,

Tony Soprano,48,Newark,

Jack Gallo,61,New York,

 

When you run it against your program, it should report the following: :

 

4

 

 

As another test, given the following external file data:

 

Samuel Adams,38,Boston,

Homer Simpson,41,Springfield,

 

Tony Soprano,48,Newark,

Jack Gallo,61,New York,

 

When you run it against your program, it should report the following: :

 

5

 

(It counted the blank line as valid data, which is correct!)

 


 

4. External Data Formatting, Part D (lab09d.cpp)

Write a program that will take an external flat file, and write the lines in reverse order to an external file

 

As a test, given the following external file data:

 

Samuel Adams,38,Boston

Homer Simpson,41,Springfield

Tony Soprano,48,Newark

Jack Gallo,61,New York

 

When you run it against your program, it should write it to another external file as follows::

 

Jack Gallo,61,New York

Tony Soprano,48,Newark

Homer Simpson,41,Springfield

Samuel Adams,38,Boston

 

(Hint: Use a stack object)

 


 

Back to the main course page