C++ For this assignment, you are developing a student registration system. For t
ID: 3919953 • Letter: C
Question
C++
For this assignment, you are developing a student registration system. For this system, you need to include the following classes a) Person: For this class add the required data members (e.g., name, dob, ssn, etc.), member functions, and operators b) Date: For this class add the required data members (e.g., day, month, and year), member functions, and operators. The dob data member in the Person class is of type Date c) Professor: Inherited from Person. For this class add data members (e.g., office, numberOfCourses, employmentStatus, etc.), member functions, and operators d) Student: Inherited from Person. For this class add the required data members (e.g., major, department, etc.), member functions (e.g., agreeToTeach, numberCourses), and operators e) Course: Include all the required data members (e.g., courseNo, courseName, credits), member functions (e.g., scheduleSection, addPrerequisite, hasPrerequisite), and operators. This class needs to have a member function that shows the list of the courses in your system. The information of the courses needs to be stored in a file named, "Courses.txt". f) Section: Inherited from Course. Include all required data members (e.g., sectionNo, dayOfWeek, timeOfDay, room, seatingCapacity), member functions (e.g., enroll, drop, confirmSeatAvailability), and operators Once you include complete definitions for the above classes, complete the definition of a function, named main) to prompt the user for different types of actions. This function should provide a menu for the user to select the type of action (e.g., Add New Student, Add New Course, Display Courses, Display Students, etc.)Explanation / Answer
//Courses.h
#ifndef COURSES_H
#define COURSES_H
class Courses
{
private:
struct CourseList
{
char courseNum[10];
char courseName[25];
char courseSch[20];
CourseList *next;
};
CourseList *head;
void displayArrayChar(char [], int);
public:
Courses(void)
{head=NULL;}
~Courses(void);
void appendCourse(char [],char [], char []);
void appendCourse(CourseList *);
void deleteCourse(char []);
bool searchforCourse(char []);
void displayAllCourses(void);
void editCourses(char [], char [], int );
void emptyCourses(void); //function called when a student is deleted
CourseList* getHead(void){return head;}
//friend void StudentInfo::insertStudent(char [], char [], int [], CourseList *);
};
#endif
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//studentinfo.h
#ifndef STUDENTINFO_H
#define STUDENTINFO_H
#include <iostream>
#include "Courses.h"
using namespace std;
class StudentInfo
{
private:
struct StudentList
{
char firstName[12];
char lastName[12];
int ssn[9];
Courses studentCourses;
struct StudentList *next;
};
StudentList *ssnhead;
int tempStoreSSN[9];
void displayArrayChar(char [], int);
void displayArrayInt(int []);
bool testIntArray(int [], int []);
public:
StudentInfo(void)
{ssnhead=NULL;}
~StudentInfo(void);
void insertStudent(char [], char [], int [], Courses &);
void insertStudent(char fn[], char ln[], int s[]);
void deleteStudent(int []);
bool searchBylast(char []);
bool searchByssn(int []);
void displayAllStudents(void);
void editStudentInfo(int []);
void editStudentInfo(char [],int);
int getTempssn(int);
void storessnTemp(char [], int);
};
#endif
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//courses.cpp
#include <iostream>
#include <ctype.h>
#include <string.h>
#include "courses.h"
#include "studentinfo.h"
using namespace std;
Courses::~Courses(void)
{
CourseList *nodePtr, *nextNode;
nodePtr=head;
while (nodePtr !=NULL)
{
nextNode=nodePtr->next;
delete nodePtr;
nodePtr=nextNode;
}
head=NULL;
}
void Courses::appendCourse(CourseList *tempHead) //should only pass the head pointer of the node
{
CourseList *nodePtr, *nodeTempPtr, *newNode;
nodePtr=head;
nodeTempPtr=nodePtr;
while(nodeTempPtr->next !=NULL)
{nodePtr=nodePtr->next;
}
nodeTempPtr = tempHead;
while(nodeTempPtr->next !=NULL)
{
newNode=new CourseList;
strcpy(newNode->courseNum, nodeTempPtr->courseNum);
strcpy(newNode->courseName, nodeTempPtr->courseName);
strcpy(newNode->courseSch, nodeTempPtr->courseSch);
newNode->next=NULL;
nodePtr->next=newNode;
nodePtr=nodePtr->next;
nodeTempPtr=nodeTempPtr->next;
}
}
void Courses::appendCourse(char cNum[], char cName[], char cSch[])
{
CourseList *newNode, *nodePtr;
newNode=new CourseList;
strcpy(newNode->courseNum, cNum);
strcpy(newNode->courseName, cName);
strcpy(newNode->courseSch, cSch);
newNode->next=NULL;
if(!head)
head=newNode;
else
{
nodePtr=head;
while(nodePtr->next)
{
nodePtr=nodePtr->next;
}
nodePtr->next=newNode;
}
}
void Courses::emptyCourses(void)
{
CourseList *nodePtr, *nextNode;
nodePtr=head;
while (nodePtr !=NULL)
{
nextNode=nodePtr->next;
delete nodePtr;
nodePtr=nextNode;
}
head=NULL;
}
void Courses::displayAllCourses(void)
{
CourseList *nodePtr;
nodePtr=head;
if(!head)
cout<< " This Student isn't registered for any classes ";
while(nodePtr)
{
displayArrayChar(nodePtr->courseNum, 10);
cout<< " ";
displayArrayChar(nodePtr->courseName, strlen(nodePtr->courseName));
cout<< " ";
displayArrayChar(nodePtr->courseSch, strlen(nodePtr->courseSch));
cout<<" ";
nodePtr=nodePtr->next;
}
}
void Courses::displayArrayChar(char array[], int elms)
{
for(int counter=0; counter < elms; counter++)
{
cout<< array[counter];
}
}
void Courses::deleteCourse(char array[])
{
CourseList *nodePtr, *previousNode;
head->courseNum[10]=NULL; //THE FUNCTION WON'T WORK W/O THIS
if(!head)
return;
if(strcmp(head->courseNum, array) == 0)
{
nodePtr=head->next;
delete head;
head=nodePtr;
}
else
{
nodePtr=head;
while(nodePtr->next !=NULL && strcmp(array, nodePtr->courseNum) !=0)
{
previousNode=nodePtr;
nodePtr=nodePtr->next;
}
previousNode->next=nodePtr->next;
delete nodePtr;
}
}
bool Courses::searchforCourse(char array[])
{
CourseList *nodePtr;
if(!head)
return false;
if(strcmp(head->courseNum, array) == 0)
return true;
else
{
nodePtr=head;
while(nodePtr !=NULL && strcmp(nodePtr->courseNum, array) !=0)
{
if(strcmp(nodePtr->courseNum, array) ==0)
return true;
nodePtr=nodePtr->next;
}
return false;
}
}
void Courses::editCourses(char course[], char change[], int choice)
{
CourseList *nodePtr;
nodePtr=head;
head->courseNum[1]=NULL; //THE FUNCTION WON'T WORK WITHOUT THIS
if(strcmp(head->courseNum, course) == 0);
else
{
while(nodePtr->next !=NULL && strcmp(course, nodePtr->courseNum) !=0)
{
nodePtr=nodePtr->next;
}
}
switch(choice)
{
case 1://Changes the Course Number
strcpy(nodePtr->courseNum, change);
break;
case 2://Changes the Course Name
strcpy(nodePtr->courseName, change);
break;
case 3://Changes the Course Schedule
strcpy(nodePtr->courseSch, change);
break;
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Studentinfo.cpp
#include <iostream>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "studentinfo.h"
#include "courses.h"
using namespace std;
StudentInfo::~StudentInfo(void)
{
StudentList *nodePtr, *nextNode;
nodePtr=ssnhead;
while(nodePtr !=NULL)
{
nextNode=nodePtr->next;
ssnhead->next->studentCourses.emptyCourses();
delete nodePtr;
nodePtr=nextNode;
}
ssnhead->next=NULL;
}
void StudentInfo::insertStudent(char fn[], char ln[], int s[], Courses &stdcourses)
{
StudentList *newNode, *nodePtr, *previousNode;
newNode=new StudentList;
strcpy(newNode->firstName, fn);
strcpy(newNode->lastName, ln);
for(int count=0; count<9; count++)
newNode->ssn[count]=s[count];
newNode->studentCourses.appendCourse(stdcourses.getHead());
newNode->next=NULL;
if(ssnhead==NULL) //There should be no information stored in the head
{
ssnhead=newNode;
}
else
{
nodePtr= ssnhead;
while(nodePtr !=NULL)
{
previousNode=nodePtr;
nodePtr=nodePtr->next;
}
if(previousNode==NULL)
{
ssnhead->next=newNode; //There should be no information stored in the head
newNode->next=nodePtr;
}
else
{
previousNode->next=newNode;
newNode->next=nodePtr;
}
}
}
void StudentInfo::insertStudent(char fn[], char ln[], int s[])
{
StudentList *newNode, *nodePtr, *previousNode;
newNode=new StudentList;
strcpy(newNode->firstName, fn);
strcpy(newNode->lastName, ln);
for(int count=0; count<9; count++)
newNode->ssn[count]=s[count];
if(ssnhead==NULL)
{
ssnhead->next=newNode;
newNode->next=NULL;
}
else
{
nodePtr=ssnhead;
while(nodePtr !=NULL)
{
previousNode=nodePtr;
nodePtr=nodePtr->next;
}
if(previousNode==NULL)
{
ssnhead=newNode;
newNode->next=nodePtr;
}
else
{
previousNode->next=newNode;
newNode->next=nodePtr;
}
}
}
void StudentInfo::deleteStudent(int s[])
{
StudentList *nodePtr, *previousNode;
if(s[0] ==-1)
{
for(int c=0; c<10; c++)
s[c]=tempStoreSSN[c];
tempStoreSSN[0]=NULL;
}
if(!ssnhead->next)
return;
if(testIntArray(ssnhead->next->ssn, s) == true)
{
nodePtr = ssnhead->next->next;
ssnhead->next->studentCourses.emptyCourses();
delete ssnhead->next;
ssnhead->next=nodePtr;
}
else
{
nodePtr=ssnhead->next;
while(nodePtr !=NULL && testIntArray(ssnhead->next->ssn, s) != true)
{
previousNode=nodePtr;
nodePtr=nodePtr->next;
}
previousNode->next=nodePtr->next;
ssnhead->next->studentCourses.emptyCourses();
delete nodePtr;
}
}
void StudentInfo::displayArrayChar(char array[], int elms)
{
for(int counter=0; counter< elms; counter++)
{
cout<< array[counter];
}
}
void StudentInfo::displayArrayInt(int array[])
{
for(int counter = 0; counter<9; counter++)
{
cout<< array[counter];
}
}
void StudentInfo::displayAllStudents()
{
StudentList *nodePtr;
nodePtr = ssnhead;
if(ssnhead==NULL)
{
cout<< " There aren't any students in the database. ";
return;
}
while(nodePtr)
{
cout << " made it in" << endl;
cout<< " ";
displayArrayChar(nodePtr->firstName, strlen(nodePtr->firstName));
cout<< " ";
displayArrayChar(nodePtr->lastName, strlen(nodePtr->lastName));
cout<< " ";
displayArrayInt(nodePtr->ssn);
cout<< " ";
nodePtr->studentCourses.displayAllCourses();
cout<< endl;
}
}
bool StudentInfo::searchBylast(char name[])
{
StudentList *nodePtr;
nodePtr=ssnhead->next;
int temp=0;
if(nodePtr==NULL)
return false;
while(nodePtr !=NULL)
{
if(strcmp(name, nodePtr->lastName) == 0)
{
cout<< endl<< (temp + 1)<< "-";
displayArrayChar(nodePtr->lastName, strlen(nodePtr->lastName)); cout<< ", ";
displayArrayChar(nodePtr->firstName, strlen(nodePtr->firstName)); cout<< endl;
temp++;
}
if(nodePtr==NULL && temp !=0)
{
return true;
}
nodePtr=nodePtr->next;
}
return false;
}
bool StudentInfo::searchByssn(int social[])
{
StudentList *nodePtr;
nodePtr=ssnhead->next;
if(nodePtr==NULL)
return false;
while(nodePtr !=NULL)
{
if(testIntArray(social, nodePtr->ssn) == true)
{
cout<< " ";
displayArrayChar(nodePtr->lastName, strlen(nodePtr->lastName)); cout << ", ";
displayArrayChar(nodePtr->firstName, strlen(nodePtr->firstName)); cout<< endl;
return true;
}
nodePtr=nodePtr->next;
}
return false;
}
void StudentInfo::storessnTemp(char name[], int count)
{
StudentList *nodePtr;
nodePtr=ssnhead->next;
int counter=1;
while(nodePtr !=NULL)
{
if(strcmp(name, nodePtr->lastName) == 0)
{
if(counter == count)
{
for(int c=0; c<9; c++)
tempStoreSSN[c] = nodePtr->ssn[c];
}
else
counter++;
}
nodePtr= nodePtr->next;
}
}
int StudentInfo::getTempssn(int e)
{
return tempStoreSSN[e];
}
void StudentInfo::editStudentInfo(char futurechange[], int choice)
{
StudentList *nodePtr;
nodePtr=ssnhead->next;
while(nodePtr !=NULL && testIntArray(tempStoreSSN, nodePtr->ssn) == true)
{
nodePtr=nodePtr->next;
}
switch(choice)
{
case 1://Changes first name
strcpy(nodePtr->firstName, futurechange);
break;
case 2://Changes last name
strcpy(nodePtr->lastName, futurechange);
break;
}
}
void StudentInfo::editStudentInfo(int futurechange[])
{
StudentList *nodePtr;
nodePtr=ssnhead->next;
while(testIntArray(tempStoreSSN, nodePtr->ssn) ==true && nodePtr !=NULL)
{
nodePtr=nodePtr->next;
}
for(int count = 0; count<9; count++)
nodePtr->ssn[count]=futurechange[count];
}
bool StudentInfo::testIntArray(int a[], int b[])
{
for(int count=0; count<9; count++)
{
if(a[count] != b[count])
return false;
}
return true;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//mainprogram.cpp
#include <iostream>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "studentinfo.h"
#include "courses.h"
#define ERROR " You've Entered An Invalid Character! "
void displayname(void);
void getStudentInfo(StudentInfo &);
bool changeCase(char [], int);
void getCourseInfo(Courses &);
bool yesorno(void);
int mainMenu(void);
void directions(void);
void search(StudentInfo &);
void insertStudent(StudentInfo &);
void addStudent(StudentInfo &);
void deleteStudent(StudentInfo &);
void editStudent(StudentInfo &);
void main (void)
{
StudentInfo spartans;
int choice;
displayname();
do
{
choice = mainMenu();
switch(choice)
{
case 0: spartans.displayAllStudents();
break;
case 1: insertStudent(spartans);
break;
case 2: //Edit
break;
case 3: search(spartans);
break;
case 4: deleteStudent(spartans);
break;
case 5: cout << " GOODBYE!! ";
break;
}
}
while(choice != 5);
}
void getCourseInfo(Courses &l)
{
char cname[10];
char cd[25];
char sc[20];
bool execution = true;
cout << " Enter The Course Number & Session Number: ";
cin.getline(cname, 11);
execution = changeCase(cname, 3);
if(execution == false)
{
cout << " The Course Has Not Been Entered Into The System ";
cout << "Because Of Input Problems. "; directions();
return;
}
cout << "Enter The Course Description: ";
cin.getline(cd, 25);
execution = changeCase(cd,4);
if(execution == false)
{
cout << " The Course Has Not Been Entered Into The System ";
cout << "Because Of Input Problems. "; directions();
return;
}
cout << "Enter the Course Schedule: ";
cin.getline(sc, 20);
execution = changeCase(sc, 5);
if(execution == false)
{
cout << " The Course has Not Been Entered Into The System ";
cout << "Because Of Input Problems. "; directions();
return;
}
if(execution == true)
l.appendCourse(cname,cd,sc);
}
bool changeCase(char array[], int choice)
{
int elm = strlen(array);
int count = 0;
switch(choice)
{
case 1:
for(count = 0; count < elm; count++)
{
if(count== 0 && isalpha(array[count]))
{
array[count] = toupper(array[count]);
}
else if(isalpha(array[count]))
{
array[count] = tolower(array[count]);
}
else
{
cout << ERROR; return false;
}
}
break;
case 2:
for(count = 0; count < 10; count++)
{
if(isdigit(array[count]));
else
{
cout << ERROR; return false;
}
}
break;
case 3:
for( count = 0; count < elm; count++)
{
if(count <=2)
{
if(isalpha(array[count]))
{
array[count] = toupper(array[count]);
}
else
{
cout << ERROR; return false;
}
}
else if(count == 3)
{
if(isspace(array[count]));
else
{
cout << ERROR; return false;
}
}
else if(count >4 && count <=6)
{
if(isdigit(array[count]));
else
{
cout << ERROR; return false;
}
}
else if(count == 7)
{
if(array[count] == '-');
else
{
cout << ERROR; return false;
}
}
else
{
if(isdigit(array[count]));
else
{
cout << ERROR; return false;
}
}
}
break;
case 4:
for(count = 0; count < elm; count++)
{
if(isalpha(array[count]))
{
if(count == 0)
{
array[count] = toupper(array[count]);
}
else
{
array[count] = tolower(array[count]);
}
}
else if(isspace(array[count]))
{
if(isalpha(array[count+1]))
{
array[count] = toupper(array[count]);
count++;
}
else
{
cout << ERROR; return false;
}
}
else
{
cout << ERROR; return false;
}
}
break;
case 5:
for(int count = 0; count < elm; count++)
{
if(isalpha(array[count]))
{
array[count] = toupper(array[count]);
}
}
break;
}
return true;
}
void directions(void)
{
cout << " When entering data follow the instructions below. ";
cout << " *Enter all names beginning with a capital letter. Ex: Tommy White ";
cout << " *All social security numbers must not have blank spaces or dashes. Ex: 277892345 ";
cout << " *Enter 'y' or 'n' for all yes or no questions. ";
cout << " *Below is an example of how to input all course information. ";
cout << " -Course Number & Session Number: CSC 351-01 ";
cout << " -Course Description: Linear Algebra ";
cout << " -Course Schedule: MWF 0900AM 1000AM ";
}
bool yesorno(void)
{
char ans;
do
{
cout << " Enter Yes or No(Y or N) For The Above Question: ";
cin >> ans;
cin.ignore();
if(tolower(ans) != 'y' && tolower(ans) != 'n')
{
cout << ERROR;
directions();
cout << " Please Try Again!!";
}
}
while(tolower(ans) != 'y' && tolower(ans) != 'n');
if(tolower(ans) == 'y')
return true;
else
mainMenu();
return false;
}
int mainMenu(void)
{
int ans;
do
{
cout << " Main Menu ---------- ";
cout << " 0-Display All Students In The Database ";
cout << " 1-Add a Student ";
cout << " -Add a Non-Existing Student ";
cout << " -Register a Non-Existing Student ";
cout << " -Edit a Student's Information ";
cout << " -2-Edit a Student's Information ";
cout << " -Edit a 'Student's Courses ";
cout << " -Edit a 'Student's Personal Information ";
cout << " -Register An Existing Student ";
cout << " 3-Search For A Student ";
cout << " 4-Delete a Student ";
cout << " -Delete a Student from The Database ";
cout << " 5-Quit ";
cout << " Enter the corresponding number next to the option of your choice: ";
cin >> ans;
cin.ignore();
if(ans != 0 && ans != 1 && ans != 2 && ans != 3 && ans != 4 && ans != 5)
{
cout << ERROR; cout << " Please Try Again!! ";
}
}
while(ans != 0 && ans != 1 && ans != 2 && ans != 3 && ans != 4 && ans != 5);
return ans;
}
void getStudentInfo(StudentInfo &l)
{
char fname[12];
char lname[12];
//char tempsocial[9];
int social[9];
bool execution = true;
cout << " Enter The Student's First name: ";
cin.getline(fname, 13);
execution = changeCase(fname, 1);
if(execution == false)
{
cout << " The Student's Name Has Not Been Entered Into The System ";
cout << "Because Of Input Problems. "; directions();
return;
}
cout << "Enter The Student's Last Name: ";
cin.getline(lname, 13);
execution = changeCase(lname,1);
if(execution == false)
{
cout << " The Student's Name Has Not Been Entered Into The System ";
cout << "Because Of Input Problems. "; directions();
return;
}
cout << "Enter the Student's Social Security Number: ";
cin >> social[9];
if(execution == false)
{
cout << " The Student's Social Security Number Has Not Been Entered Into The System ";
cout << "Because Of Input Problems. "; directions();
return;
}
bool ans;
Courses temp;
cout << " Would You Like To Register This Student For A Course? ";
ans = yesorno();
if(ans == true)
{
while(ans == true)
{
getCourseInfo(temp);
cout << " Would You Like To Register This Student For Another course? ";
ans = yesorno();
}
l.insertStudent(lname, fname, social);
}
else
{
l.insertStudent(lname, fname, social);
}
}
void addStudent(StudentInfo &n)
{
bool ans;
do
{
getStudentInfo(n);
cout << " Would You Like to Add Another Student? ";
ans = yesorno();
}
while (ans == true);
}
void search(StudentInfo &l)
{
bool a, searcher;
int choice, count;
do
{
do
{
cout << " Enter 1 to search by last name, or 2 to search ";
cout << "by social security number. " << " Enter Here: ";
cin >> choice;
switch(choice)
{
case 1:
char lname[12];
cout << " Enter The Student's Last Name: ";
cin.getline(lname, 13);
searcher = changeCase(lname, 1);
if(searcher == true)
{
searcher = l.searchBylast(lname);
if(searcher == false)
{
cout << " There is no student by that last name";
cout << " in the database. ";
}
a = false;
}
else
{
cout << ERROR << "Please Try Again!! ";
a = true;
}
break;
case 2:
int social[9];
for(count = 0; count < 10; count++)
{
cin >> social[count];
}
searcher = l.searchByssn(social);
if(searcher == false)
{
cout << " There is no student that has that social ";
cout << "security number in the database. ";
}
a = false;
break;
default:
cout << ERROR; a = true;
}
}
while(a = true);
cout << " Would You Like To Try Another Search? ";
a = yesorno();
}
while(a == true);
}
void deleteStudent(StudentInfo &sa)
{
int s[9];
bool a;
cout << " Enter the student's social security number: ";
&nbs
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.