-
program design question
Hello everyone,
I came across a programming problem that I was wondering someone could help me out with.
-----------------------------------------------------------------------------------
the problem:
A file of student records contains name, gender (M or F), age, and
marital status (single or married) for each student. Design an
algorithm that will read through the file and calculate the
numbers of married men, single men, married women, and single women. Print these
numbers on a Student Summary Report. If any single men are over 30 years of age,
print their names and ages on a separate Eligible Bachelors Report.
-----------------------------------------------------------------------------------
Now, the part that stumped me about this was how I should go about creating the Bachelor Report.
My idea was to set up 2 while loops, the first one would set up the total number of married and
single people all under the student summary heading. Then, when that loop terminated,
print to the screen the Bachelor heading and then create another while loop
to read the file AGAIN and test for single men over 30. This felt very cumbersome,
and I was wondering if my logic is off.
my pseudocode:
Code:
print 'STUDENT SUMMARY REPORT'
read student record
WHILE more records exist
IF gender = M THEN
IF status = married THEN
married_men++
ELSE
single_men++
ENDIF
ELSE
IF status = married THEN
married_women++
ELSE
single_women++
ENDIF
ENDIF
read student record
ENDWHILE
print 'ELIGIBLE BACHELOR REPORT'
read student record (from beginning)
WHILE more records exist
IF gender = M THEN
IF status = single THEN
IF age > 30 THEN
print name, age
ENDIF
ENDIF
ENDIF
read student record
ENDWHILE
First off...I didnt realize I posted twice. My internet connection has been a little weird and probably caused me to do that.
Second...I'm having trouble deleting the other thread, cant say I didnt try.
Third...Formatting has NEVER been an issue when I've posted before (I've been posting for a long time), I find it funny that all of a sudden I have to manually insert line breaks...interesting...
And by the way, thanks for the reply, but sadly you were too focused on my posting shortcomings to provide any real insight :) thanks for the response though! :)
-
First, edit your post and add line breaks to the quote in the code tags.
Then, pick one of the two duplicate threads to use and delete the other or edit out the post so people will only use one.
Then, consider using some sort of container to store the information you are reading in.