Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Hugo Cedano
- finalProject
- part 0
- */
- #include <iostream>
- #include <string>
- #include <sstream>
- using namespace std;
- struct student{
- string name;
- char sex;
- float gpa;
- char finalGrade;
- };
- const int MAX_IN_CLASS = 20;
- student COP1334[MAX_IN_CLASS];
- bool empty = true;
- string searched_Name;
- void studentReg (student COP1334[], int& enrolled);
- void displayStudents (student COP1334[], int& enrolled);
- void checkRegistered (student COP1334[], int& enrolled);
- void dropStudent (student COP1334[], int& enrolled, int i);
- void assignFinalGrade(student COP1334[], int& enrolled);
- //void checkArray (student COP1334[], int& enrolled, int i);
- void sortName(student COP1334[], int& enrolled);
- void sortGPA(student COP1334[], int& enrolled);
- void swap(student COP1334[], int i, int j);
- int main() {
- char user_Input,
- sortInput;
- int enrolled = 0,
- assignCount=0;
- string temp,
- tempSort;
- do{
- cout << "****************************************************" << endl;
- cout << "*" << "Welcome to the COP1334 Student Registration System!" << endl;
- cout << "*" << "To register a student enter A." << endl;
- cout << "*" << "To print all registered students enter P." << endl;
- cout << "*" << "To drop a student enter D." << endl;
- cout << "*" << "To sort students enter S." << endl;
- cout << "*" << "To assign final grades for students enter F." << endl;
- cout << "*" << "To quit this program enter Q." << endl;
- cout << "****************************************************" << endl;
- getline(cin, temp);
- if(cin.fail()){
- cin.clear();
- cin.ignore(1337, '\n');
- }
- user_Input = temp[0];
- switch(user_Input){
- case 'A':
- case 'a':
- if (enrolled==MAX_IN_CLASS){
- cout << "----------------------------------------------------" << endl;
- cout << "The class is full! Sorry" << endl;
- cout << "----------------------------------------------------" << endl;
- }
- else
- studentReg (COP1334, enrolled);
- break;
- case 'P':
- case 'p':
- if (empty){
- cout << "----------------------------------------------------" << endl;
- cout << "There are no registered students" << endl;
- cout << "----------------------------------------------------" << endl;
- }
- else{
- displayStudents (COP1334, enrolled);
- }
- break;
- case 'D':
- case 'd':
- if (empty){
- cout << "----------------------------------------------------" << endl;
- cout << "There are no students to drop!" << endl;
- cout << "----------------------------------------------------" << endl;
- }
- else
- checkRegistered (COP1334, enrolled);
- break;
- case 'F':
- case 'f':
- if (empty){
- cout << "----------------------------------------------------" << endl;
- cout << "There are no students to assign grades to!" << endl;
- cout << "----------------------------------------------------" << endl;
- }
- else if (enrolled == assignCount){
- cout << "All grades have been assigned" << endl;
- }
- else{
- //assignFinalGrade(COP1334,enrolled);
- for(int i=0; i<enrolled; i++){
- if(COP1334[i].finalGrade == 'N'){
- assignFinalGrade(COP1334, enrolled);
- }
- }
- break;
- }
- break;
- case 'S':
- case 's':
- if (empty){
- cout << "----------------------------------------------------" << endl;
- cout << "There are no students to sort!" << endl;
- cout << "----------------------------------------------------" << endl;
- }
- else{
- cout << "----------------------------------------------------" << endl;
- cout << "To sort students by their Name enter N." << endl;
- cout << "To sort students by their GPA enter G." << endl;
- cout << "----------------------------------------------------" << endl;
- getline(cin, tempSort);
- if(cin.fail()){
- cin.clear();
- cin.ignore(1337, '\n');
- }
- sortInput = tempSort[0];
- switch (sortInput){
- case 'N':
- case 'n':
- sortName(COP1334, enrolled);
- break;
- case 'G':
- case 'g':
- sortGPA(COP1334, enrolled);
- break;
- default:
- cout << "Invalid input" << endl;
- }
- }
- break;
- case 'Q':
- case 'q':
- break;
- default:
- cout << "Invalid input" << endl;
- }
- }
- while (user_Input != 'Q');
- return 0;
- }
- void studentReg (student COP1334[], int& enrolled){
- student s;
- string temp;
- cout << "Enter Name: ";
- getline(cin, s.name);
- cout << "GPA: ";
- cin >> s.gpa;
- cout << "Sex: ";
- cin.ignore(1, '\n');
- getline(cin,temp);
- s.sex = temp.substr(0,1)[0];
- s.finalGrade = 'N';
- COP1334[enrolled] = s;
- enrolled++;
- empty = false;
- cout << "Student successfully registered" << endl;
- }
- void displayStudents (student COP1334[], int& enrolled){
- cout << "----------------------------------------------------" << endl;
- cout << "Class Capacity: " << enrolled << '/' << MAX_IN_CLASS << " N- \"Not Entered\"\n";
- for(int i=0; i<enrolled; i++){
- cout << "----------------------------------------------------" << endl;
- cout << "Name\tGPA\tGender\tFinal Grade" << endl;
- cout << COP1334[i].name << "\t" << COP1334[i].gpa << "\t" << COP1334[i].sex << "\t" << COP1334[i].finalGrade << endl;
- cout << "----------------------------------------------------" << endl;
- }
- }
- void checkRegistered (student COP1334[], int& enrolled){
- bool studentFound=false;
- cout << "----------------------------------------------------" << endl;
- cout << "Enter name of student to drop: " << endl;
- cout << "----------------------------------------------------" << endl;
- getline(cin, searched_Name);
- if(searched_Name.compare(COP1334[enrolled-1].name) == 0){
- enrolled--;
- cout << "----------------------------------------------------" << endl;
- cout << "Student was dropped successfully" << endl;
- cout << "----------------------------------------------------" << endl;
- if(enrolled==0){
- empty=true;
- }
- return;
- }
- //check if student is registered and calls the actual drop student function
- for(int i=0; i<enrolled-1; i++){
- if(searched_Name==(COP1334[i].name)){
- studentFound = true;
- dropStudent (COP1334, enrolled, i);
- cout << "----------------------------------------------------" << endl;
- cout << "Student was dropped successfully!" << endl;
- cout << "----------------------------------------------------" << endl;
- }
- }
- if(!(studentFound)){
- cout << "----------------------------------------------------" << endl;
- cout << "Student isn't registered at this time" << endl;
- cout << "----------------------------------------------------" << endl;
- }
- if(enrolled==0){
- empty=true;
- }
- }
- void assignFinalGrade(student COP1334[], int& enrolled, int& assignCount){
- char user_Input, user_Input2, user_Input3;
- string temp, temp2, temp3;
- for (int i=0; i<enrolled; i++){
- cout << "----------------------------------------------------" << endl;
- cout << "To assign a final grade for " << COP1334[i].name << ", press A" << endl;
- cout << "To proceed to the next student, press P" << endl;
- cout << "----------------------------------------------------" << endl;
- getline(cin, temp);
- if(cin.fail()){
- cin.clear();
- cin.ignore(1337, '\n');
- }
- user_Input = temp[0];
- switch (user_Input){
- case 'A':
- case 'a':
- do{
- cout << "----------------------------------------------------" << endl;
- cout << "Enter a grade to assign to " << COP1334[i].name << ": " << endl;
- cout << "----------------------------------------------------" << endl;
- getline(cin, temp2);
- if(cin.fail()){
- cin.clear();
- cin.ignore(1337, '\n');
- }
- user_Input2 = temp2[0];
- cout << "----------------------------------------------------" << endl;
- cout << "You are about to assign " << user_Input2 << " to " << COP1334[i].name << endl;
- cout << "Enter P to proceed or C to cancel: " << endl;
- cout << "----------------------------------------------------" << endl;
- getline(cin, temp3);
- user_Input3 = temp3[0];
- switch (user_Input3){
- case 'p':
- case 'P':
- COP1334[i].finalGrade = user_Input2;
- assignCount++;
- break;
- case 'c':
- case 'C':
- break;
- default:
- cout << "Invalid input!" << endl;
- }
- break;
- case'p':
- case'P':
- //implement if...else code
- if (enrolled=1){
- break;
- }
- else
- if(assignCount = enrolled){
- cout << "All final grades are already assigned" << endl;
- break;
- }
- else{
- assignFinalGrade;
- }
- break;
- default:
- cout << "Invalid input!" << endl;
- }
- while(user_Input2 != 'C');
- }
- }
- }
- void dropStudent (student COP1334[], int& enrolled, int i){
- for(int i=0; i<enrolled; i++){
- if(searched_Name.compare(COP1334[i].name) == 0){
- for(int j=i; j<enrolled-1; j++){
- COP1334[j] = COP1334[j+1];
- }
- enrolled--;
- }
- }
- if(enrolled == 0){
- empty = true;
- }
- }
- int binarySearch(int COP1334[], int& enrolled, int value)
- {
- int first = 0,
- last = enrolled - 1,
- middle,
- position = -1;
- bool found = false;
- while (!found && first <= last)
- {
- middle = (first + last)/2;
- if (COP1334[middle] == value)
- {
- found = true;
- position = middle;
- }
- else if (COP1334[middle] > value)
- last = middle - 1;
- else
- first = middle + 1;
- }
- return position;
- }
- void sortName(student COP1334[], int& enrolled){
- for(int i=0; i<enrolled-1; i++){
- bool sorted = false;
- for(int j=1; j<=enrolled-1; j++){
- if(COP1334[j-1].name > COP1334[j].name){
- cout << "a at "<< j << " is: " << COP1334[j].name <<endl;
- cout << "a at "<< j-1 <<" is: " << COP1334[j-1].name <<endl;
- swap(COP1334, j, j-1);
- sorted = true;
- }
- }
- if(!sorted){
- break;
- }
- }
- }
- void sortGPA(student COP1334[], int& enrolled){
- for(int i=0; i<enrolled-1; i++){
- bool sorted = false;
- for(int j=1; j<=enrolled-1; j++){
- if(COP1334[j-1].gpa > COP1334[j].gpa){
- cout << "a at "<< j << " is: " << COP1334[j].gpa <<endl;
- cout << "a at "<< j-1 <<" is: " << COP1334[j-1].gpa <<endl;
- swap(COP1334, j, j-1);
- sorted = true;
- }
- }
- if(!sorted){
- break;
- }
- }
- }
- void swap(student COP1334[], int x, int y){
- student temp;
- temp = COP1334[x];
- COP1334[x] = COP1334[y];
- COP1334[y] = temp;
- }
- /*void checkArray (student COP1334[], int& enrolled, int i, int& assignCount){
- for(int i=0; i<enrolled; i++){
- if(COP1334[i].finalGrade == 'N'){
- assignFinalGrade(COP1334, enrolled, assignCount);
- }
- else
- break;
- }
- }*/
Add Comment
Please, Sign In to add comment