Page 289 - Learn to Program - Basic-256
P. 289

Chapter 18: Files – Storing Information For Later.                              Page 273



                              Windows or gEdit in LINUX, and type in the data below.

                                     Jim,M,47
                                     Mary,F,23
                                     Bob,M,67
                                     John,M,13
                                     Sue,F,18

                              Write a program that will read in the data from the people file.
                              Use string handling functions from Chapter 16 to break each line
                              into three parts: 1) name, 2) gender, and 3) age. Tally the total of
                              the ages, the number of people, and the number of males as you
                              read the file. Once you have read all the records display the
                              percentage of males and the average age of the people in the file.

                              3. Create a file in the directory where you save your programs
                              named “assignments.txt”. Open it with a text editor, like Notepad
                              in Windows or gEdit in LINUX, and type in the data below.

                                     Jim,88,45
                                     Joe,90,33
                                     Mary,54,29
                                     Maury, 57,30

                              Write a program that will read in the data from the assignments
                              file and write out a new file named “finalgrade.txt” with the
                              student's name, a comma, and their course grade. Calculate the
                              course grade for each student based on the two assignment
                              grades. The first assignment was worth 100 points and the second
                              assignment was worth 50 points.


                              The output should look something like:

                                     Jim,88
                                     …






                                                           © 2019 James M. Reneau (CC BY-NC-SA 3.0 US)
   284   285   286   287   288   289   290   291   292   293   294