CIS 112 – COMPUTER PROGRAMMING 1
Jacqueline A. Emslie, MS, Instructor
ASSIGNMENT 4 – MODELS
This is part of your Assignments Grade. This program will produce a list of models using input records
and produce an output file. You may select which environment you wish to develop your program in.
Submit what you have completed in the Assignment 4 drop box by the due date. If developing in the IDE,
zip the folder and include the ModelOutput.txt. If developing in Notepad, put the xxx.cs and
ModelOutput.txt in the drop box.
INPUT
The input file is Models.txt and is found in the Assignment 4 folder. The record layout is as follows:
FIELD NAME
Name
Weight
Height
Eye Code
Hair Code
Gender Code
LENGTH
24
3
2
1
1
1
TYPE OF DATA
string
integer
integer
char (1 = blue, 2 = brown, 3 = other)
char (1 = blonde, 2 = brown, 3 = other)
char (M = Male, F = Female)
PROCESSING
Write out the headings.
For each model record
Add height to total height
Add weight to total weight
Add 1 to model counter
If male, add 1 to mail counter
If brown eyes, add 1 to brown eye counter
If model meets one of the two sets of criteria
Determine word for the eye color code
Determine word for the hair color code
Determine word for the gender code
Write out name, gender, weight, height, eye color, hair color
After all model records have been processed
Write out number of male models
Write out number of brown eyed models
Write out average height of all models
Write out average weight of all models
CRITERIA:
1) blonde hair, blue-eyed males over 6 foot tall and weighing between 185 and 200 inclusive
2) brown hair, brown-eyed females between 5’2” and 5’6” and weighing between 110 and 125 inclusive
OUTPUT
Name the output text file ModelOutput.txt.
CIS 112 – COMPUTER PROGRAMMING 1
Jacqueline A. Emslie, MS, Instructor
OUTPUT FORMAT:
MODEL REPORT
Name
Tom Smith
Gender
M
Male Models: 999
Brown Eyed Models: 999
Average Height: 999
Average Weight: 999
Weight
190
Height
73
Eye Color
Blonde
Hair Color
Blue
CIS 112 – COMPUTER PROGRAMMING I
Jacqueline Emslie, MS, Instructor
READING FROM AND WRITING TO TEXT FILES
FILE PLACEMENT:
Put the input file (ModelsInput2.txt) in the bin/Debug folder.
Output file (models.txt) will be created if it does not exist.
CODE TO READ AND WRITE:
using System;
using System.IO;
class Program
{
static void Main()
{
//ATTENTION: The default path for the streamreader is the same directory of the
EXE file. Which is in the debug folder.
// Create an instance of StreamReader to read from a file.
// The using statement also closes the StreamReader.
string strInputPath = “ModelsInput2.txt”;
string strOutputPath = “Models.txt”;
using (StreamReader sr = new StreamReader(strInputPath))
using (StreamWriter sw = new StreamWriter(strOutputPath))
{
// input line
string strInputLine;
while ((strInputLine = sr.ReadLine()) != null)
{
Sw.WriteLine(strInputLine);
}
}
}
}