Question: COP 2 2 2 0 - Programming in C Programming Assignment 7 : Registrar Database ( 2 1 points ) First, watch my videos on
COP Programming in C
Programming Assignment : Registrar Database 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
cop 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 MAXLENGTH
Define the following structure type:
typedef struct dataRecord
int courseID;
char courseMAXLENGTH;
int numSeats;
int numRegistered;
Programming Assignment Registrar Database
Page
RECORDTYPE;
Function prototypes:
int menu;
void loadDatabaseFILE infile, RECORDTYPE database, int
numRecords;
void processChoiceFILE infile, FILE outfile, int choice,
RECORDTYPE database, int numRecords;
void displayDatabaseRECORDTYPE database, int numRecords;
void searchDatabaseRECORDTYPE database, int numRecords;
void writeReportFILE outfile, RECORDTYPE 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;
RECORDTYPE 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 dowhile loop as follows.
do:
Programming Assignment Registrar Database
Page
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
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 MAXLENGTH
Start a for loop using i from 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 RECORDTYPE and assign
it to databasei
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:
Display contents of database.
Search the database.
Write report.
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 Registrar Database
Page
Case : call the displayDatabase function and pass it the
database and the number of records.
Case : call the searchDatabase function and pass it the
database and the number of records.
Case : call the writeReport function and pass it the
outfile pointer, the database, and the number of records.
Case : 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
