knokap5 - /*...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: /* *************************************************** Name - Kimberly Okafor Email - knokafor@uh.edu ECE 3331 Computer Problem 5 Semester - Spring 2010 *************************************************** Purpose - add and drop a number of students into and out of different courses *************************************************** Data files cp5_cour.txt - input data file that course title terminated by a semicolon, the class code terminated by a semicolon, and the quota cp5_reg.txt - a 9-digit student ID the name terminated by a semicolon either an A for add or a D for drop the 5 digit section code. knokap5.out - output file to which results will be written *************************************************** */ /*included files*/ #include <stdio.h> #include <math.h> #include <stdlib.h> #include <string.h> #include <ctype.h> /* user defined student type*/ typedef struct student { char name[30]; unsigned int id; struct student *next; } STUDENT; /*user defined course type*/ typedef struct course { char title[50]; unsigned int code; int cur_enrollment; int quota; STUDENT *student; struct course *next; } COURSE; /*declarations of functions*/ COURSE *buildcourse (FILE* fin); int addcourse(char stuname[30], unsigned int stuid, unsigned int sec, COURSE *courseptr); int dropcourse(char stuname[30], unsigned int stuid, unsigned int sec, COURSE *courseptr); void printrolls (COURSE* class, FILE* fout); STUDENT *buildmaster(STUDENT *masterptr,char stuname[30],unsigned int stuid); void printstud(STUDENT *masterptr,COURSE *courseptr,FILE *fout); /*start of main*/ main() { COURSE *masterclass; /*the pointer to the first class in the linked list*/ STUDENT *masterstu; /*the pointer to the first student in the linked list*/ char stuname[30]; /*the name that has been read in*/ unsigned int stuid; /*student id that is being read in*/ char action; /*D ->drop or A ->add*/ unsigned int cnum; /*the code of the course that the student wants to add of drop*/ int result; /*result of the addcourse or drop course function*/ COURSE *findit; /*dummy pointer used to find the course that wants to be dropped or added by the student*/ int flag=0; /*indicator of change*/ int i,count; /*counter*/ /*file pointers*/ FILE *fcourse; FILE *freg; FILE *fout; /*open files*/ fcourse=fopen("cp5_cour.txt","r"); freg=fopen("cp5_reg.txt","r"); fout=fopen("knokap5.out","w"); /*build the COURSE linked list*/ masterclass=buildcourse(fcourse); /*initalize masterstu*/ masterstu=NULL; /*initiate findit*/ /*findit=masterclass; /*find space for the first student in the registration file*/ /*first=malloc(sizeof(STUDENT)); /*the first student to be read in will be the first current student*/ /*current=first; /*keep reading in students until the end of file is reached*/ while(fscanf(freg,"%u%[^;];%c%u",&stuid,stuname,&action,&cnum)>0) { /*set the next field in the STUDENT struct to be NULL*/ /*current->next=NULL; /*allocate space for the next student to be read in*/ /*nextone=malloc(sizeof(STUDENT)); /*initiate the findit pointer to the first course in the list*/...
View Full Document

Page1 / 11

knokap5 - /*...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online