Lab 23

File Input/Output

CS211 Lab Policy:

Instructions:

Create one program named Lab23 that includes code that implements the tasks specified below. Save your program in a file named Lab23.m.

  1. Begin your Lab23() function by clearing the command window.
     
  2. Prompt and get from the user a positive integer value that represents the size of a "Pascal triangle." A "Pascal triangle" is a series of numbers in the shape of a triangle where each value in the interior of the triangle is calculated by summing the two values "above it". All numbers on the "edges" are equal to one. Several example are shown below.
     
  3. Prompt for and get from the user a string of characters that specifies a file name. The file name should have no extension.
     
  4. Using the MATLAB statement below, create a Pascal triangle of the user specified size.

        Triangle = abs(pascal(User_size, 1));
     
  5. Now create 3 different printouts of the Pascal triangle and store each printout in a distinct file.
    1. The first file should be named with the user specified name appended with "_left.txt". The numbers of the triangle should be left justified to form a lower triangular matrix. (See examples below.)
       
    2. The second file should be named with the user specified name appended with "_centered.txt". The numbers of the triangle should be centered to form a triangle with its top value in the middle of the page. (See examples below.)
       
    3. The third file should be named with the user specified name appended with "_right.txt". The numbers of the triangle should be right justified to form a triangle with the right side forming a vertical line. (See examples below.)

Some examples:

Hints:

Turn-in:

Submit your Lab23.m file and one example of each output text file.