示例#1
0
int main(void){
  Student st[20];
  int nrOfStudents;
  int option = 0;
  while (option != 5) {
    option = menu();
    switch (option){
      case 1:
        cin.ignore();
        addStudent(st, nrOfStudents);
        break;
      case 2:
        showAllStudents(st, nrOfStudents);
        break;
      case 3:
        cin.ignore();
        if(removeStudent(st, nrOfStudents) != -1)
          cout << "Succesful!\n";
        break;
      case 4:
          int position;
          position = findStudent(st, nrOfStudents);
          if(position != -1){
            st[position].show();
          }
          else
            cout << "Not found\n";
        break;
      }
  }
  return 0;
}
//"Remove student" main screen for users
//Display lines:
//1. Search.
//2. Remove student by Id.
//0. Back.
//Enter a number:
////////////////////
//When user input, do the respective functions:
//'1': mainSearch()
//'2': removeStudent()
//'0': return;
//Otherwise: print "Invalid command", ask for other input.
void mainRemoveStudent() {
	for(;;) {
		cout << endl << endl;
		cout << "Remove a student: " << endl;
		cout << "1. Search." << endl;
		cout << "2. Remove student by ID." << endl;		
	  cout << "0. Back." << endl;
	  
	  cout << "Enter a number: ";
	  
	  // Verify a command if it is integer and belong to {0..2}
	  int command;  
		while (true) {
			cin >> command;
			if (cin && (command < 3) && (command > -1)) break;
			cout << "Invalid command!" << endl;
			cin.clear();
			cin.ignore(256,'\n');
		} 
		//////////////////////////////////////////////////////////
		
	  switch (command) {
	  	case 1: mainSearch();
	  					break;
	  					//mainScreen();
	  	case 2: removeStudent(usth_student_list, stu_list_size);
	  					//mainScreen();
	  					break;	  	
	  	case 0: return;
	  	default: 
	  		cout << "Invalid command!" << endl;
	  		break;
	  		
	  }		
	}
}
示例#3
0
bool Repository::updateStudent(Student s) {
    removeStudent(s);
    addStudent(s);
}