/* editStudent edit an existing student, and display details as defaults for input in: pointer to a student to edit out: none */ void editStudent(struct STUDENT *s) { char firstName[32]; // store input first name char lastName[32]; // store input last name int completedCredits; // store input credits struct DATE enrollmentDate; // store input enrollment date // store an "empty date" to compare with entered date to indicate no change struct DATE noDate = {0}; do { // display what # student we're editing printf("\nEditing Student #%d\n", numStudents + 1); // input first name & update only if input not empty printf("First name: [%s] ", s->firstName); strcpy(firstName, inputString("", 32)); if (strcmp(firstName, "") == 0) strcpy(firstName, s->firstName); // input last name & update only if input not empty printf("Last name: [%s] ", s->lastName); strcpy(lastName, inputString("", 32)); if (strcmp(lastName, "") == 0) strcpy(lastName, s->lastName); // input completed credits & update only if input not empty printf("Completed credits: [%d] ", s->completedCredits); completedCredits = inputInteger(""); if (completedCredits == 0) completedCredits = s->completedCredits; // input enrollment date & update only if input not empty printf("Enrollment date (mm/dd/yyyy): [%s] ", formatDate(s->enrollmentDate)); enrollmentDate = inputDate(""); // since inputDate returns a struct DATE, we must check against an "empty" date if (compDates(enrollmentDate, noDate) == 0) enrollmentDate = s->enrollmentDate; // print details entered printf("\nFirst name: %s\n" "Last name: %s\n" "Completed credits: %d\n" "Enrollment date: %s\n", firstName, lastName, completedCredits, formatDate(enrollmentDate)); // confirm with user whether info correct, repeat input if not } while (!confirm("\nInfo correct (y/n) ?")); // store entered data back into the record pointed to by s strcpy(s->firstName, firstName); strcpy(s->lastName, lastName); s->completedCredits = completedCredits; s->enrollmentDate = enrollmentDate; }
void Box::SetProgramRecorded() { string name; int aux=-1; int i = 0; cout << "Insert a Program's name: "; cin.clear(); cin.ignore(); getline(cin, name); cout << endl << endl << endl; int existInRecord = false; for (int j = 0; j < recordList.size(); j++) { if (string_to_upper(name) == string_to_upper(recordList[j].getName())) { existInRecord = true; cout << "The program \"" << name << "\", is in the list of recorded programs." << endl << endl << endl << endl; break; } } if (!existInRecord) { for (i; i < channels.size(); i++) { aux = searchProgram(string_to_upper(name), channels[i]); if (aux >= 0) { break; } } if (aux >= 0) { if (compDates(GetCurrentDate(), channels[i].getPrograms()[aux].getDate())) { cout << "The program \"" << channels[i].getPrograms()[aux].getName(); cout << "\", from the channel \"" << channels[i].getName() << "\", was sucefully\n"; cout << "set to be recorded." << endl << endl << endl << endl; recordList.push_back(channels[i].getPrograms()[aux]); } else { cout << "The program \"" << channels[i].getPrograms()[aux].getName(); cout << "\", from the channel \"" << channels[i].getName() << "\", has been reproduced." << endl << endl << endl << endl; } } else cout << "The program \"" << name << "\" doesn't exist." << endl << endl << endl << endl; } }
void Box::updateProgramState(string &programn) { system("CLS"); cout << " _ _ _ " << endl; cout << " / \\ __| |_ ____ _ _ __ ___ ___ __| |" << endl; cout << " / _ \\ / _` \\ \\ / / _` | '_ \\ / __/ _ \\/ _` |" << endl; cout << " / ___ \\ (_| |\\ V / (_| | | | | (_| __/ (_| |" << endl; cout << " /_/ \\_\\__,_| \\_/ \\__,_|_| |_|\\___\\___|\\__,_|" << endl << endl; cout << "\t \t Update a program" << endl << endl << endl; int channel_position = 0; int program_position = 0; for (channel_position; channel_position < channels.size(); channel_position++) { program_position = searchProgram(programn, channels[channel_position]); if (program_position != -1) break; } if (compDates(GetCurrentDate(), channels[channel_position].getPrograms()[program_position].getDate())) { cout << "The program \"" << channels[channel_position].getPrograms()[program_position].getName() << "\""; cout << " wasn't reproduced yet"; Sleep(3000); } else { cout << endl << endl << "The record state of the program \"" << channels[channel_position].getPrograms()[program_position].getName() << "\""; cout << " was change to \""; if (channels[channel_position].getPrograms()[program_position].getState()) cout << "true"; else cout << "false"; cout << "\""; Sleep(3000); channels[channel_position].setProgramState(program_position); } }
/* sortStudents sort the array of students based on user preference (uses simple bubble sort algorithm) in: none out: none */ void sortStudents() { // declarations char sortField; // user entered field to sort char fieldName[20]; // name of the field to sort int i = 0; // loop counter for sorting int sorted = 0; // repeat loop for bubble sort int swap = 0; // whether to swap students[i] & students[i+1] int desc = 0; // if we're sorting in descending order struct STUDENT tempStudent; // temp struct to store student for swapping // no need to sort only one or 0 students! if (numStudents < 2) return; // print menu choices printf("Sort by:\t" "L) Last Name\n\t\t" "F) First Name\n\t\t" "E) Enrollment Date\n\t\t" "C) Completed Credits ? "); // get sort field from user sortField = toupper(inputString("", 2)[0]); // ask user whether to sort in descending order desc = confirm("\nDescending (just hit Enter for ascending) (y/n) ? "); // set the fieldName for display back to user switch (sortField) { case 'F': strcpy(fieldName, "First name"); break; case 'E': strcpy(fieldName, "Enrollment date"); break; case 'C': strcpy(fieldName, "Completed credits"); break; case 'L': default: strcpy(fieldName, "Last name"); break; } // print back to user how we are sorting printf("\nSorting by: %s, %s ...\n\n", fieldName, desc ? "Descending" : "Ascending"); while (!sorted) // repeat loop for bubble sort { sorted = 1; // "assume" sorted until we swap // loop through all students - 1 // (because we're swapping [i] with [i+1]) for (i = 0; i < numStudents - 1; i++) { swap = 0; // do not swap unless flagged switch (sortField) // check by field: { case 'F': // first name swap = ((strcmp(students[i+1].firstName, students[i].firstName) < 0) || (strcmp(students[i+1].firstName, students[i].firstName) == 0 && strcmp(students[i+1].lastName, students[i].lastName) < 0)); break; case 'E': // enrollment date swap = (compDates(students[i].enrollmentDate, students[i+1].enrollmentDate) > 0); break; case 'C': // completed credits swap = (students[i].completedCredits > students[i+1].completedCredits); break; case 'L': // last name default: swap = ((strcmp(students[i+1].lastName, students[i].lastName) < 0) || (strcmp(students[i+1].lastName, students[i].lastName) == 0 && strcmp(students[i+1].firstName, students[i].firstName) < 0)); break; } /* XOR desc ^ swap: if swap == 1, order must be swapped for ascending; if swap == 0, order must be swapped for descending */ if (desc ^ swap) { // swap students[i] and students[i+1] using temp variable tempStudent = students[i]; students[i] = students[i+1]; students[i+1] = tempStudent; sorted = 0; // we had to swap, so repeat the loop } } } // when done sorting, print the sorted student list listStudents(); }