// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r14
movq 0x7cc6(%rip), %rdi      # 0xafc8
leaq 0x40e8(%rip), %rsi      # 0x73f1
callq 0x2170
movq %rax, %rdi
callq 0x20b0
movq 0x7cc3(%rip), %rdi      # 0xafe0
leaq -0x38(%rbp), %rbx
movq %rbx, %rsi
callq 0x20e0
movl (%rbx), %esi
movq %r14, %rdi
callq 0x447c
testq %rax, %rax
je 0x3421
movq %rax, %rbx
movq %r14, %rdi
callq 0x41e8
testl %eax, %eax
leaq 0x40d8(%rip), %rax      # 0x7428
leaq 0x411e(%rip), %rsi      # 0x7475
cmovgq %rax, %rsi
movq 0x7c66(%rip), %rdi      # 0xafc8
callq 0x2170
movq %rax, %rdi
callq 0x20b0
movq 0x7c6a(%rip), %rdi      # 0xafe0
leaq -0x31(%rbp), %r15
movq %r15, %rsi
callq 0x2230
movsbl (%r15), %edi
callq 0x22f0
movb %al, (%r15)
cmpb $0x46, %al
je 0x34c0
movsbl %al, %eax
cmpl $0x54, %eax
je 0x344e
cmpl $0x50, %eax
jne 0x35b5
movq 0x7c16(%rip), %rdi      # 0xafc8
leaq 0x40f5(%rip), %rsi      # 0x74ae
callq 0x2170
movq %rax, %r15
movq %r14, %rdi
callq 0x41d6
movq %r15, %rdi
movl %eax, %esi
callq 0x22c0
leaq 0x40f3(%rip), %rsi      # 0x74cd
movq %rax, %rdi
callq 0x2170
movq 0x7bf7(%rip), %rdi      # 0xafe0
leaq -0x30(%rbp), %r15
movq %r15, %rsi
callq 0x20e0
movl (%r15), %r15d
testl %r15d, %r15d
jle 0x340e
movq %r14, %rdi
callq 0x41d6
cmpl %eax, %r15d
jle 0x34d0
movq 0x7bb3(%rip), %rdi      # 0xafc8
leaq 0x40b4(%rip), %rsi      # 0x74d0
jmp 0x35c3
movq 0x7ba0(%rip), %rdi      # 0xafc8
leaq 0x3fdd(%rip), %rsi      # 0x740c
callq 0x2170
movl -0x38(%rbp), %esi
movq %rax, %rdi
callq 0x22c0
leaq 0x3fd6(%rip), %rsi      # 0x741c
movq %rax, %rdi
jmp 0x35c3
movq 0x7b73(%rip), %rdi      # 0xafc8
leaq 0x408d(%rip), %rsi      # 0x74e9
callq 0x2170
movq %rax, %r15
movq %r14, %rdi
callq 0x41de
movq %r15, %rdi
movl %eax, %esi
callq 0x22c0
leaq 0x4050(%rip), %rsi      # 0x74cd
movq %rax, %rdi
callq 0x2170
movq 0x7b54(%rip), %rdi      # 0xafe0
leaq -0x30(%rbp), %r15
movq %r15, %rsi
callq 0x20e0
movl (%r15), %r15d
testl %r15d, %r15d
jle 0x34ad
movq %r14, %rdi
callq 0x41de
cmpl %eax, %r15d
jle 0x34d0
movq 0x7b14(%rip), %rdi      # 0xafc8
leaq 0x404a(%rip), %rsi      # 0x7505
jmp 0x35c3
movq %r14, %rdi
callq 0x41e8
testl %eax, %eax
jle 0x35b5
leaq 0x405d(%rip), %rsi      # 0x7534
movq 0x7aea(%rip), %r14      # 0xafc8
movq 0x7afb(%rip), %r15      # 0xafe0
leaq -0x2c(%rbp), %r12
leaq 0x405a(%rip), %r13      # 0x754a
movq %r14, %rdi
callq 0x2170
movq %rax, %rdi
callq 0x20b0
movq %r15, %rdi
movq %r12, %rsi
callq 0x20e0
cmpl $0x64, -0x2c(%rbp)
movq %r13, %rsi
ja 0x34f0
leaq 0x7cbd(%rip), %rdi      # 0xb1d8
leaq 0x4054(%rip), %rsi      # 0x7576
callq 0x2170
movq %rax, %r14
movq %rbx, %rdi
callq 0x4d38
movq %r14, %rdi
movl %eax, %esi
callq 0x22c0
movzbl -0x31(%rbp), %eax
movq 0x7a81(%rip), %rdi      # 0xafc8
cmpl $0x54, %eax
je 0x35d7
cmpl $0x50, %eax
jne 0x3664
leaq 0x4027(%rip), %rsi      # 0x7587
callq 0x2170
movl -0x30(%rbp), %esi
movq %rax, %rdi
callq 0x22c0
leaq 0x406a(%rip), %r14      # 0x75e1
movq %rax, %rdi
movq %r14, %rsi
callq 0x2170
movl -0x2c(%rbp), %esi
movq %rax, %rdi
callq 0x22c0
movq %rax, %rdi
callq 0x20b0
movl -0x30(%rbp), %esi
decl %esi
movl -0x2c(%rbp), %edx
movq %rbx, %rdi
callq 0x4da8
leaq 0x7c2c(%rip), %rdi      # 0xb1d8
leaq 0x3fea(%rip), %rsi      # 0x759d
jmp 0x3631
movq 0x7a0c(%rip), %rdi      # 0xafc8
leaq 0x3f58(%rip), %rsi      # 0x751b
callq 0x2170
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3fc9(%rip), %rsi      # 0x75a7
callq 0x2170
movl -0x30(%rbp), %esi
movq %rax, %rdi
callq 0x22c0
leaq 0x3fec(%rip), %r14      # 0x75e1
movq %rax, %rdi
movq %r14, %rsi
callq 0x2170
movl -0x2c(%rbp), %esi
movq %rax, %rdi
callq 0x22c0
movq %rax, %rdi
callq 0x20b0
movl -0x30(%rbp), %esi
decl %esi
movl -0x2c(%rbp), %edx
movq %rbx, %rdi
callq 0x4dc8
leaq 0x7bae(%rip), %rdi      # 0xb1d8
leaq 0x3f8c(%rip), %rsi      # 0x75bd
callq 0x2170
movl -0x30(%rbp), %esi
movq %rax, %rdi
callq 0x22c0
movq %rax, %rdi
movq %r14, %rsi
callq 0x2170
movl -0x2c(%rbp), %esi
movq %rax, %rdi
callq 0x22c0
movq %rax, %rdi
callq 0x20b0
jmp 0x35c8
leaq 0x3f59(%rip), %rsi      # 0x75c4
callq 0x2170
movl -0x2c(%rbp), %esi
movq %rax, %rdi
callq 0x22c0
movq %rax, %rdi
callq 0x20b0
leaq 0x7b4e(%rip), %rdi      # 0xb1d8
leaq 0x3f55(%rip), %rsi      # 0x75e6
callq 0x2170
movq %rax, %r14
movq %rbx, %rdi
callq 0x4dd8
movq %r14, %rdi
movl %eax, %esi
callq 0x22c0
leaq 0x3f2f(%rip), %rsi      # 0x75e1
movq %rax, %rdi
callq 0x2170
movl -0x2c(%rbp), %esi
movq %rax, %rdi
callq 0x22c0
movq %rax, %rdi
callq 0x20b0
movl -0x2c(%rbp), %esi
movq %rbx, %rdi
callq 0x4de2
jmp 0x35c8