// File: tbonelaforge[P]gradebook/Main.cpp
// Function: handleChangeGrade(Gradebook&)
void handleChangeGrade(Gradebook &gradebook) {
    int studentId, gradeNumber, newGrade;
    char gradeType;
    Student * student;
    cout << "Enter the student number: " << endl;
    cin >> studentId;
    student = gradebook.findStudentById(studentId);
    if (student == NULL) {
        cout << "Student number " << studentId << " not found\n";
        return;
    }
    if (gradebook.getNumFinals() > 0) {
        cout << "Enter the type of grade: ('P' for program, 'T' for test, 'F' for final exam)" << endl;
    } else {
        cout << "Enter the type of grade: ('P' for program, 'T' for test)" << endl;
    }
    cin >> gradeType;
    gradeType = toupper(gradeType);
    switch (gradeType) {
    case 'P':
        cout << "Enter the program number (1 - " << gradebook.getNumPrograms() << ")\n";
        cin >> gradeNumber;
        if (gradeNumber < 1 || gradeNumber > gradebook.getNumPrograms()) {
            cout << "Invalid program number.\n";
            return;
        }
        break;
    case 'T':
        cout << "Enter the test number (1 - " << gradebook.getNumTests() << ")\n";
        cin >> gradeNumber;
        if (gradeNumber < 1 || gradeNumber > gradebook.getNumTests()) {
            cout << "Invalid test number.\n";
            return;
        }
        break;
    case 'F':
        if (gradebook.getNumFinals() > 0) {
            break;
        }
    default:
        cout << "Unrecognized Grade Type\n";
        return;
    }
    cout << "Enter the new grade: " << endl;
    cin >> newGrade;
	while (newGrade < 0 || newGrade>100) {
		cout << "Error, please enter a value between 0-100: " << endl;
		cin >> newGrade;
	}

    transLog << "Changed student " << student->getId();

    if (gradeType == 'P') {
        cout << "Changing the grade for program " << gradeNumber << " to " << newGrade << endl;
        student->setProgramGrade(gradeNumber - 1, newGrade);
        
        transLog << " program " << gradeNumber << " to " << newGrade << endl;
    } else if (gradeType == 'T') {
        cout << "Changing the grade for test " << gradeNumber << " to " << newGrade << endl;
        student->setTestGrade(gradeNumber - 1, newGrade);
        
        transLog << " test " << gradeNumber << " to " << newGrade << endl;
    } else {
        cout << "Changing the final exam grade to " << newGrade << endl;
        transLog << " Final grade from " << student->getFinalExamGrade() << " to " << newGrade << endl;
        student->setFinalExamGrade(newGrade);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq 0x9525(%rip), %rdi      # 0xdfc8
leaq 0x5947(%rip), %rsi      # 0xa3f1
callq 0x3220
movq %rax, %rdi
movq 0x94ef(%rip), %rsi      # 0xdfa8
callq 0x3250
movq 0x951b(%rip), %rdi      # 0xdfe0
leaq -0xc(%rbp), %rsi
callq 0x3150
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x6590
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x4b17
movq 0x94dc(%rip), %rdi      # 0xdfc8
leaq 0x5919(%rip), %rsi      # 0xa40c
callq 0x3220
movq %rax, %rdi
movl -0xc(%rbp), %esi
callq 0x33e0
movq %rax, %rdi
leaq 0x590f(%rip), %rsi      # 0xa41c
callq 0x3220
jmp 0x4f87
movq -0x8(%rbp), %rdi
callq 0x6130
cmpl $0x0, %eax
jle 0x4b49
movq 0x949c(%rip), %rdi      # 0xdfc8
leaq 0x58f5(%rip), %rsi      # 0xa428
callq 0x3220
movq %rax, %rdi
movq 0x9466(%rip), %rsi      # 0xdfa8
callq 0x3250
jmp 0x4b6b
movq 0x9478(%rip), %rdi      # 0xdfc8
leaq 0x591e(%rip), %rsi      # 0xa475
callq 0x3220
movq %rax, %rdi
movq 0x9442(%rip), %rsi      # 0xdfa8
callq 0x3250
movq 0x946e(%rip), %rdi      # 0xdfe0
leaq -0x15(%rbp), %rsi
callq 0x3330
movsbl -0x15(%rbp), %edi
callq 0x3430
movb %al, -0x15(%rbp)
movsbl -0x15(%rbp), %eax
movl %eax, -0x24(%rbp)
subl $0x46, %eax
je 0x4cbb
jmp 0x4b99
movl -0x24(%rbp), %eax
subl $0x50, %eax
je 0x4bb4
jmp 0x4ba3
movl -0x24(%rbp), %eax
subl $0x54, %eax
je 0x4c39
jmp 0x4ccd
movq 0x940d(%rip), %rdi      # 0xdfc8
leaq 0x58ec(%rip), %rsi      # 0xa4ae
callq 0x3220
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
callq 0x6100
movq -0x30(%rbp), %rdi
movl %eax, %esi
callq 0x33e0
movq %rax, %rdi
leaq 0x58e4(%rip), %rsi      # 0xa4cd
callq 0x3220
movq 0x93eb(%rip), %rdi      # 0xdfe0
leaq -0x10(%rbp), %rsi
callq 0x3150
cmpl $0x1, -0x10(%rbp)
jl 0x4c1c
movl -0x10(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rdi
callq 0x6100
movl %eax, %ecx
movl -0x34(%rbp), %eax
cmpl %ecx, %eax
jle 0x4c34
movq 0x93a5(%rip), %rdi      # 0xdfc8
leaq 0x58a6(%rip), %rsi      # 0xa4d0
callq 0x3220
jmp 0x4f87
jmp 0x4ce5
movq 0x9388(%rip), %rdi      # 0xdfc8
leaq 0x58a2(%rip), %rsi      # 0xa4e9
callq 0x3220
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
callq 0x6110
movq -0x40(%rbp), %rdi
movl %eax, %esi
callq 0x33e0
movq %rax, %rdi
leaq 0x585f(%rip), %rsi      # 0xa4cd
callq 0x3220
movq 0x9366(%rip), %rdi      # 0xdfe0
leaq -0x10(%rbp), %rsi
callq 0x3150
cmpl $0x1, -0x10(%rbp)
jl 0x4ca1
movl -0x10(%rbp), %eax
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rdi
callq 0x6110
movl %eax, %ecx
movl -0x44(%rbp), %eax
cmpl %ecx, %eax
jle 0x4cb9
movq 0x9320(%rip), %rdi      # 0xdfc8
leaq 0x5856(%rip), %rsi      # 0xa505
callq 0x3220
jmp 0x4f87
jmp 0x4ce5
movq -0x8(%rbp), %rdi
callq 0x6130
cmpl $0x0, %eax
jle 0x4ccb
jmp 0x4ce5
jmp 0x4ccd
movq 0x92f4(%rip), %rdi      # 0xdfc8
leaq 0x5840(%rip), %rsi      # 0xa51b
callq 0x3220
jmp 0x4f87
movq 0x92dc(%rip), %rdi      # 0xdfc8
leaq 0x5841(%rip), %rsi      # 0xa534
callq 0x3220
movq %rax, %rdi
movq 0x92a6(%rip), %rsi      # 0xdfa8
callq 0x3250
movq 0x92d2(%rip), %rdi      # 0xdfe0
leaq -0x14(%rbp), %rsi
callq 0x3150
movb $0x1, %al
cmpl $0x0, -0x14(%rbp)
movb %al, -0x45(%rbp)
jl 0x4d2c
cmpl $0x64, -0x14(%rbp)
setg %al
movb %al, -0x45(%rbp)
movb -0x45(%rbp), %al
testb $0x1, %al
jne 0x4d35
jmp 0x4d69
movq 0x928c(%rip), %rdi      # 0xdfc8
leaq 0x5807(%rip), %rsi      # 0xa54a
callq 0x3220
movq %rax, %rdi
movq 0x9256(%rip), %rsi      # 0xdfa8
callq 0x3250
movq 0x9282(%rip), %rdi      # 0xdfe0
leaq -0x14(%rbp), %rsi
callq 0x3150
jmp 0x4d17
leaq 0x9508(%rip), %rdi      # 0xe278
leaq 0x57ff(%rip), %rsi      # 0xa576
callq 0x3220
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rdi
callq 0x7540
movq -0x50(%rbp), %rdi
movl %eax, %esi
callq 0x33e0
movsbl -0x15(%rbp), %eax
cmpl $0x50, %eax
jne 0x4e46
movq 0x9220(%rip), %rdi      # 0xdfc8
leaq 0x57d8(%rip), %rsi      # 0xa587
callq 0x3220
movq %rax, %rdi
movl -0x10(%rbp), %esi
callq 0x33e0
movq %rax, %rdi
leaq 0x5818(%rip), %rsi      # 0xa5e1
callq 0x3220
movq %rax, %rdi
movl -0x14(%rbp), %esi
callq 0x33e0
movq %rax, %rdi
movq 0x91c5(%rip), %rsi      # 0xdfa8
callq 0x3250
movq -0x20(%rbp), %rdi
movl -0x10(%rbp), %esi
subl $0x1, %esi
movl -0x14(%rbp), %edx
callq 0x7640
leaq 0x9477(%rip), %rdi      # 0xe278
leaq 0x5795(%rip), %rsi      # 0xa59d
callq 0x3220
movq %rax, %rdi
movl -0x10(%rbp), %esi
callq 0x33e0
movq %rax, %rdi
leaq 0x57bf(%rip), %rsi      # 0xa5e1
callq 0x3220
movq %rax, %rdi
movl -0x14(%rbp), %esi
callq 0x33e0
movq %rax, %rdi
movq 0x916c(%rip), %rsi      # 0xdfa8
callq 0x3250
jmp 0x4f87
movsbl -0x15(%rbp), %eax
cmpl $0x54, %eax
jne 0x4ef8
movq 0x916e(%rip), %rdi      # 0xdfc8
leaq 0x5746(%rip), %rsi      # 0xa5a7
callq 0x3220
movq %rax, %rdi
movl -0x10(%rbp), %esi
callq 0x33e0
movq %rax, %rdi
leaq 0x5766(%rip), %rsi      # 0xa5e1
callq 0x3220
movq %rax, %rdi
movl -0x14(%rbp), %esi
callq 0x33e0
movq %rax, %rdi
movq 0x9113(%rip), %rsi      # 0xdfa8
callq 0x3250
movq -0x20(%rbp), %rdi
movl -0x10(%rbp), %esi
subl $0x1, %esi
movl -0x14(%rbp), %edx
callq 0x7690
leaq 0x93c5(%rip), %rdi      # 0xe278
leaq 0x5703(%rip), %rsi      # 0xa5bd
callq 0x3220
movq %rax, %rdi
movl -0x10(%rbp), %esi
callq 0x33e0
movq %rax, %rdi
leaq 0x570d(%rip), %rsi      # 0xa5e1
callq 0x3220
movq %rax, %rdi
movl -0x14(%rbp), %esi
callq 0x33e0
movq %rax, %rdi
movq 0x90ba(%rip), %rsi      # 0xdfa8
callq 0x3250
jmp 0x4f85
movq 0x90c9(%rip), %rdi      # 0xdfc8
leaq 0x56be(%rip), %rsi      # 0xa5c4
callq 0x3220
movq %rax, %rdi
movl -0x14(%rbp), %esi
callq 0x33e0
movq %rax, %rdi
movq 0x9088(%rip), %rsi      # 0xdfa8
callq 0x3250
leaq 0x934c(%rip), %rdi      # 0xe278
leaq 0x56b3(%rip), %rsi      # 0xa5e6
callq 0x3220
movq %rax, -0x58(%rbp)
movq -0x20(%rbp), %rdi
callq 0x76c0
movq -0x58(%rbp), %rdi
movl %eax, %esi
callq 0x33e0
movq %rax, %rdi
leaq 0x5687(%rip), %rsi      # 0xa5e1
callq 0x3220
movq %rax, %rdi
movl -0x14(%rbp), %esi
callq 0x33e0
movq %rax, %rdi
movq 0x9034(%rip), %rsi      # 0xdfa8
callq 0x3250
movq -0x20(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x76e0
jmp 0x4f87
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)