Question: COP 2 2 2 0 - Programming in C Programming Assignment 7 : Registrar Database ( 2 1 points ) First, watch my videos on

COP 2220- Programming in C
Programming Assignment 7: Registrar Database (21 points)
First, watch my videos on pointers, strings, structures, and files.
Then read ALL the following instructions CAREFULLY BEFORE writing any
code. That way, you can ask me questions or correct me if I made a
mistake.
Make sure that you have downloaded the accompanying text file,
registrar.txt, and placed it in a folder that can be accessed by your
program when it is running. If you don't know how to do this, email
me and I will set up a Zoom meeting to show you.
Create a C program and save it as registrarYourInitials.c in your
cop2220 folder. (Replace YourInitials with your own initials.)
The program will be designed so that it contains functions that you
will write. ALL function bodies are to be written BELOW the main
function but the prototypes for those functions must be written just
above the main.
I will NOT be specifying the algorithms for all functions in this
assignment since you need to learn how to come up with these
algorithms yourselves.
Put your name, the date, and the assignment number as comments at the
top of the program.
Include the stdlib.h and the string.h libraries just below the
include to stdio.h.
Type in the following preprocessor constant above the main:
#define MAX_LENGTH 10
Define the following structure type:
typedef struct dataRecord
{
int courseID;
char course[MAX_LENGTH+1];
int numSeats;
int numRegistered;
Programming Assignment 7- Registrar Database
Page 2
} RECORD_TYPE;
Function prototypes:
int menu();
void loadDatabase(FILE * infile, RECORD_TYPE ** database, int
numRecords);
void processChoice(FILE * infile, FILE * outfile, int choice,
RECORD_TYPE ** database, int numRecords);
void displayDatabase(RECORD_TYPE ** database, int numRecords);
void searchDatabase(RECORD_TYPE ** database, int numRecords);
void writeReport(FILE * outfile, RECORD_TYPE ** database, int
numRecords);
The algorithm for the main function follows: (Pay attention to
indentation in the algorithm.)
char * infilename = "registrar.txt";
char * outfilename = "report.txt"; //Make sure that you DON'T
have a file by that name already. If you do, change this name.
FILE * infile;
FILE * outfile;
int numRecords;
RECORD_TYPE ** database;
Attempt to open the infilename for reading. If not successful,
print an error message and get out of the main function.
Attempt to open the outfilename for writing. If not successful,
print an error message and get out of the main function.
Read the first line of the file that has an integer
representing the number of data records following in the file.
Read that integer into the numRecords variable.
Create space for that many record pointers using malloc and
assign that space to the database variable.
Call the function loadDatabase and give it the parameters it
needs.
Declare an integer variable named choice.
Start a do/while loop as follows.
do:
Programming Assignment 7- Registrar Database
Page 3
Call a function named menu and collect what it returns in
the variable called choice. The function does not take any
parameters.
Call a function named processChoice and pass it the
infile, outfile, the choice, the database, and the
numRecords in that order. This function does not return
anything.
while choice is not equal to 4.
Close the infile.
Close the outfile.
The description of the loadDatabase function follows:
Declare an integer variable named i.
Declare integer variables named courseID, numSeats, and
numRegistered.
Declare a string variable named course of size MAX_LENGTH +1.
Start a for loop using i from 0 to less than numRecords. Inside
the loop do:
Read the course ID, course, number of seats, and number
registered from the infile into the corresponding
variables using an fscanf.
Create space using malloc for one RECORD_TYPE and assign
it to database[i].
Assign the values read in from the file to the
corresponding structure that you just created. Remember
that, for the course, you need to use strcpy.
The description of the menu function follows:
Present the user with the following menu:
1) Display contents of database.
2) Search the database.
3) Write report.
4) Quit.
Collect the user's selection and return it.
The algorithm for the processChoice function follows:
Use a switch statement to determine what choice was passed into
the function:
Programming Assignment 7- Registrar Database
Page 4
Case 1: call the displayDatabase function and pass it the
database and the number of records.
Case 2: call the searchDatabase function and pass it the
database and the number of records.
Case 3: call the writeReport function and pass it the
outfile pointer, the database, and the number of records.
Case 4: print "Bye!"
Default: print a message stating that the choice was
invalid.
The description of the displayDatabase function follows:
The function should display a header row with the follow

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!