Skip to main content
ICT
Lesson A13 - Exceptions and File I/O
 
Main   Previous
 

LAB ASSIGNMENT A13.3 page 12 of 12

Squeeze

Assignment:

  1. Students will be provided with a text file, squeeze.txt, containing lines of text, which may or may not have spaces in front of the lines. You will write a class which reads in the lines of text, counts the number of spaces at the beginning of each line, and will write the lines to remove the blanks at the beginning of each line and replace them with an integer count of the number of blanks present.

  2. The number of lines in the file is unknown.

  3. Here is an example of how the data could be changed:

Before squeezing:

// A short example file

private double singleTax ()
{
    if (income <= 27050.0)
        return (income * 0.15);
    else if (income <= 65550.0)
        return (4057.5 + (0.275 * (income - 27050.0)));
    else if (income <= 136750.0)
        return (14645.0 + (0.305 * (income - 65550.0)));
    else if (income <= 297350.0)
        return (36361.0 + (0.355 * (income - 136750.0)));
    else
        return (93374.0 + (0.391 * (income - 297350.0)));
}

After squeezing:

0  // A short example file
0
0  private double singleTax ()
0  {
4  if (income <= 27050.0)
8  return (income * 0.15);
4  else if (income <= 65550.0)
8  return (4057.5 + (0.275 * (income - 27050.0)));
4  else if (income <= 136750.0)
8  return (14645.0 + (0.305 * (income - 65550.0)));
4  else if (income <= 297350.0)
8  return (36361.0 + (0.355 * (income - 136750.0)));
4  else
8  return (93374.0 + (0.391 * (income - 297350.0)));
0  }


Main   Previous
Contact
 © ICT 2006, All Rights Reserved.