Lab05 C

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

lab05.

c
// Lab05.c : Defines the entry point for the console application.
#include "studentrecord.h"
#include "myfunctions.h"

int main(void)

{
//

PrintName();

// Prints student data to the screen

//lab02
//

DealCards();

//

DiceGame();

//lab03
//

PrintRange();

//lab04
//

TestArrayFn();

//lab05
StudentInformation();
//Pause();
return;
}

studentrecord.c
#include<stdio.h>
#include "studentrecord.h"

void StudentInformation(void)
{
char choice;
int status=0;
int SID=0;
int SRecord[MAXRECS] = {0};
printf("Student Information\n");

while (1)
{
printf("\nEnter 'R' to Register a Student\n");
printf("Enter 'D' to De-Register a Student\n");
printf("Enter 'S' to Display Student Information\n");
printf("Enter 'C' to Display Class Information\n");
printf("Enter 'Q' to Quit\n");
scanf(" %c", &choice);
switch(choice)
{
case 'r':
case 'R':

status = RegisterStudent(GetStudentID(),SRecord);

if (status == 2)
{
printf("\nID is already Registered\n");
}
else if (status == 1)
{

printf("\nRecord Added\n");
}
else if (status == 0)
{
printf("\nOut of Record Space\n");
}
break;
case 'd':
case 'D':
status = DeregisterStudent(GetStudentID(), SRecord);
break;
case 's':
case 'S':
status = DisplayStudentInformation(GetStudentID(), SRecord);

break;
case 'c':
case 'C':
DisplayClassInformation(SRecord);

break;
case 'q':
case 'Q':
return;
default:
printf("\nInvalid Menu Selection ...\n");

}
}
}
int RegisterStudent(int SID, int SRecord[MAXRECS])
{
int i = 0;

for (i = 0; i < MAXRECS; i++)


{
if (SID == SRecord[i])
{
return 2;
}

}
for (i = 0; i< MAXRECS; i++)
{
if (SRecord[i] == 0 )
{

SRecord[i] = SID;
return 1 ;
}
}
return 0;

int DeregisterStudent(int SID, int SRecord[MAXRECS])


{
int i = 0;
for (i = 0; i <MAXRECS; i++)
{
if (SID == SRecord[i])
{
SRecord[i] = 0;
printf("\nRecord Deleted\n");
return 1;
}
}
printf("\nStudent Record Not Found\n");
return 0;
}

int DisplayStudentInformation(int SID, int SRecord[MAXRECS])


{

int i = 0;
for (i = 0; i< MAXRECS; i++)
{
if ( SID == SRecord[i])
{
printf("\nStudent Information\nStudent ID\n\n%d\n", SID );
return 1;
}
}
return 0;
}
void DisplayClassInformation(int SRecord[MAXRECS])
{
int i = 0;

printf("\nDisplay Class Information\n");


printf("\nStudent ID\n\n");
for (i = 0; i<MAXRECS; i++)
{
if(SRecord[i] != 0)
{
printf("%.5d\n", SRecord[i]);
}
}
}
int GetStudentID(void)

{
int SN;
while (1)
{
printf("\nEnter a 5 Digit Student Number: ");
scanf("%d", &SN);

if(SN >10000 && SN < 99999 )


{
return SN;
}
else
{
printf("\nInvalid ID.. Try Again\n");
}
}

studentrecord.h
#ifndef STUDENTRECORD_H
#define STUDENTRECORD_H
#define MAXRECS 10

//function prototypes
void StudentInformation(void);

int RegisterStudent(int SID, int SRecord[MAXRECS]);


int DeregisterStudent(int SID, int SRecord[MAXRECS]);
int DisplayStudentInformation(int SID, int SRecord[MAXRECS]);
void DisplayClassInformation(int SRecord[]);
int GetStudentID(void);

#endif

makefile
lab05: lab05.o myfunctions.o studentrecord.o
gcc -g -o lab05 lab05.o myfunctions.o studentrecord.o -lm
lab05.o: lab05.c myfunctions.h studentrecord.h
gcc -g -c lab05.c
myfunctions.o: myfunctions.c myfunctions.h
gcc -g -c myfunctions.c
studentrecord.o: studentrecord.c studentrecord.h

gcc -g -c studentrecord.c

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy