CSC 110 Introduction to ProgrammingDATE 10/28/2018

CODING ASSIGNMENT #2 File IO and Report Formatting

Name______

Check List

Create Task List and define flowchart symbols
Draw flowchart and add pseudocode
Draw user interface and name objects
Fill out object property sheet
Code problem
Print code
Comments

Problem: College Faculty/Student Ratios

The purpose of this programming assignment is to:

  • give you experience with toolbox objects and their properties;
  • give you experience manipulating properties and methods at run time;
  • give you experience reading a file and displaying formatted information
  • let you practice the elements of good coding style, including commenting, proper indentation;
  • give you some experience with creating and saving projects.

Lets Begin:

Start a new project named Inclass2. Browse and save your project in you P-Drive folder, or save to your desktop in lab and move the folder into your p-drive when you are done.

  1. Use Problem 72 on Page 122 of your book to write a program to display the data from table 3.6.
  2. Download the data file (Colleges.txt) for this project from the class webpage.
  3. Use a Dim statement to declare a string variable to used with the StreamReader object to retrieve your data from your data file.

Dim sr as IO.StreamReader = IO.File.OpenText (“Colleges.txt”)

  1. Use the example, declare a format string and display your output in a listbox named lstCollegeData

.

Dim fmtString as String = “{0, 30} {1, 10} (2, 10} (3, 10)”

  1. Use the following example to code lines that will read the data from the Colleges.txt data file. Each record contains three lines of data:

strUniv= sr.ReadLine

dblStudents = CDbl(sr.ReadLine)

dblFaculty = CDbl(sr.ReadLine)

dblRatio = dblStudents / dblFaculty

  1. Insert code to add each college to your listbox using the following example:

lstCollegeData.Items.Add(String.Format(fmtStr, strUuniv, dblStudents, _ dblFaculty, dblRatio))

  1. Use the same format string to display a total line that shows the average of all the college faculty and student ratios.
  2. Accumulate the totals for faculty and students in properly declared variables.
  3. Be sure to include data for all four columns or include (“”,) for any column that does not contain data.
  4. Declare variables for input and output as needed. Refer to the example problem (73) on page 623 of your book for help
  5. Use proper naming for your variables as discussed in class.

The Report

Use a command button click event to display your data as a report in the list box on the user interface. After you read each record set, calculate the average and display a total line in your List box. Accumulate the totals and display the average on the last line with the appropriate label. Add a Header as the first line in the list box, or display a label above the list box to tell the user about the information being displayed.