next_inactive up previous


Assignment 7

CS 135: Computer Science I

Spring 2008

Objectives

  1. Learn and demonstrate use of the while and for loop statements in C/C++
  2. Demonstrate use of file I/O in C/C++
  3. Demonstrate use of the switch and if else statements in C/C++
  4. Learn and demonstrate use of relational operators in C/C++
  5. Demonstrate prototyping, defining, and calling value returning functions.

Finding Minimum, Maximum and Average (12 points)

Design, implement, and test a complete C/C++ program that uses a while loop and reads ten ($10$) first names and ages from a file ("names.txt") and finds the minimum, maximum, and average age of the people listed in the file. Your program should print the following information to standard output.

  1. The name and age of the person with the minimum (youngest) age
  2. The average age of all the people listed in the file
  3. The name and age of the person with the maximum (oldest) age

Suppose "names.txt" contains

John 78
Jane 89
pat         56
sarah 23
foo    3
bar 55
connor 101
matt 23
clark 78
lois 21

Then your program's output may look like:

Name: John Age: 78
Name: Jane Age: 89
Name: pat Age: 56
Name: sarah Age: 23
Name: foo Age: 3
Name: bar Age: 55
Name: connor Age: 101
Name: matt Age: 23
Name: clark Age: 78
Name: lois Age: 21

=============================================
Youngest person is: foo and their age is: 3

=============================================
The average age is: 52.7

=============================================
Oldest person is: connor and their age is: 101

=============================================

Note that the output is not aligned very well. You may use the prettyPrint functions to produce better looking output.

Automating RBC counting (8 points)

Modify the red blood cell counting and diagnosis program from assignment five to use a for loop and read the names of the exactly ten ($10$) files containing subject data from a file named "subjectFilenames.txt", and produce a diagnosis report that is written to the file "diagnosis.txt". For each subject file, your program should print the name of the subject file being processed to standard output. If "subjectFilenames.txt" contains 1 :

data/subject0.txt
data/subject1.txt
data/subject2.txt
data/subject3.txt
data/subject4.txt
data/subject5.txt
data/subject6.txt
data/subject7.txt
data/subject8.txt
data/subject9.txt

Then your output (to standard output) should look like:

Processing subject filename: data/subject0.txt
Processing subject filename: data/subject1.txt
Processing subject filename: data/subject2.txt
Processing subject filename: data/subject3.txt
Processing subject filename: data/subject4.txt
Processing subject filename: data/subject5.txt
Processing subject filename: data/subject6.txt
Processing subject filename: data/subject7.txt
Processing subject filename: data/subject8.txt
Processing subject filename: data/subject9.txt

And your output file "diagnosis.txt" can be seen on the assignment's web page.

Handing it in

Turn in a Folder (Binder) containing:

  1. Cover sheet with
    1. Assignment Number
    2. Section Number
    3. Your name
    4. Your email
    5. Your TA's name
  2. Source code (.cpp) file(s) for each part of the assignment on a CD/USB stick with your name and section number written on your CD/USB stick.
  3. Executables for all parts of the assignment on the CD/USB stick.

  4. Output files for all error-free test cases
  5. Testing on at least one case where you catch a file I/O error for each part of the assignment
  6. Hardcopy of your source code (printout)
  7. Screen captures of your program running

Ask an instructor or TA if you have questions.

About this document ...

Assignment 7

This document was generated using the LaTeX2HTML translator Version 2002-2-1 (1.71)

Copyright © 1993, 1994, 1995, 1996, Nikos Drakos, Computer Based Learning Unit, University of Leeds.
Copyright © 1997, 1998, 1999, Ross Moore, Mathematics Department, Macquarie University, Sydney.

The command line arguments were:
latex2html -split 1 as7S08

The translation was initiated by Sushil Louis on 2008-03-09


next_inactive up previous
Sushil Louis 2008-03-09