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:
    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!
    Last edited by Chaplin27; 06-23-2005 at 09:03 PM.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    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.

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