L.A.14.1 o squeeze

lab exercise

 

squeeze

 

 

Background:

 

When text files are saved to disk, there are various methods for compressing files to take up less space.  For C++ source codes, many lines of a program have leading blank spaces which take up unnecessary space.  One way of conserving disk memory is to count the number of blanks at the beginning of a line and save the count as an integer.

 

 

Assignment:

 

1.    In function main, open two file streams:

 

a.   An ifstream linked to the original text file, the before version.

b.   An ofstream linked to a new file name, the after version.

 

2.    The program will remove the blanks at the beginning of each line and replace them with an integer count of the number of blanks present.  Use a setw(2) format-specifier to print the integer.  Two spaces should follow after the integer value, then the rest of the line should be transferred unchanged.

 

 

Instructions:

 

1.    Run your program on an old source code text file that has a great amount of indentation.  Include at least three levels of indenting.

 

2.    Again, make sure the file name you are "saving as" does not wipe out an existing text file.

 

3.    Turn in your source code and then a "before" and "after" look.  If you want, run Squeeze.cpp on itself, but make sure you have a backup disk copy somewhere else.

 

4.    An example is provided on the next page.

 


Before Squeezing:

 

 

// A short example file

 

float singleTax (float income)

{

   if (income <= 20350.0)

      return (income * 0.15);

   else

      if (income <= 49300.0)

         return (3052.50 + (0.28 * (income - 20350.0)));

      else

         return (11158.50 + (0.31 * (income - 49300.0)));

}

 

 

After squeezing: 

 

 

 0  // A short example file

 0

 0  float singleTax (float income)

 0  {

 3  if (income <= 20350.0)

 6  return (income * 0.15);

 3  else

 6  if (income <= 49300.0)

 9  return (3052.50 + (0.28 * (income - 20350.0)));

 6  else

 9  return (11158.50 + (0.31 * (income - 49300.0)));

 0  }