Hello everyone,
I came across a programming problem that I was wondering someone could help me out with.
the problem:
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.Code: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.
my pseudocode:
While I'm at it, I was wondering...when I 'read a file'...what would be the c++ syntax for that action? I've been dealing so much with pseudocode I havent really touched into actual c++ implementation yet. Also, how would I go about reading a file from the beginning again? Thanks for any help! I apologize if I'm being too vague, let me know if there's anymore info I should post...Thanks!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



LinkBack URL
About LinkBacks


