Thread: program design question

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    153

    program design question

    Hello everyone,
    I came across a programming problem that I was wondering someone could help me out with.

    the problem:
    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.
    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
    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!
    Last edited by Salem; 06-24-2005 at 08:22 AM. Reason: wrappage

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. program crashes + fscanf() question
    By happyclown in forum C Programming
    Replies: 27
    Last Post: 01-16-2009, 03:51 PM
  2. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  3. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  4. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM