|
Instead of user input with the scanf, we are to read from a .txt file with the fscanf function. Here is the assignment instructions.
Note: I am not looking for someone to do this assignment for me. I just need a little help.
Thanks
Your job is to write a Sentencing Guideline program for Mr. Magoo. It should read records from a file containing the students name, offense and other information. For each student, it should print to the console a recommended punishment for the offense. The program should be implemented in C and should use a user-defined datatype (i.e., a struct) along with an iteration control structure (while or for loop) and one or more conditional structures (if or switch statements). The fscanf and printf functions should be used for input/output requirements.
Program Input
The program should read its input from a text file using the fscanf function. One student record should appear on each line. The record should contain the student’s name, the offense, the number of times the student has committed that offense and the number of times the student has been in trouble overall. The record should be in a fixed format to make the input process easier. Once your program reads in a line the data should be copied into a struct and processed. It is acceptable for the program to hard code the number of students in the file, although you will not receive the enhancement points. A better approach is to read from the file until end-of-file is reached, and thus your program can process an arbitrary number of students. Your program should process at least ten students and handle at least five offenses.
Processing the Input
Your program should read and process each record from the input file, one record at a time. There is no need to create an array of records. You may use a while loop or for loop to read the records and drive the process. For each record, your program should consider the offense, the number of times it has been committed and the student’s overall record. After considering these factors, your program should choose a sanction and print the name of the student on the screen and the recommended punishment. This process repeats for each student.
To consider the offense and the other factors, you may use if statements or switch statements in any combinations you wish. Your program should be able to choose from at least three punishments. Not all punishments should be available for all offenses. However, at least two punishments should be available for most of the offenses. You may have one serious offense that qualifies automatically for the most severe punishment, but most should consider the number of times the offense has been committed and the student’s overall behavior record.
Make sure you close the input file before ending your program.
|