(E) Total gradeΒΆ

Goal: I will learn to create a simple dialog using Qt Designer, and to understand the signals & slots mechanism of Qt. I will also practice modularity by implementing a graphical user interface for an existing program.

Instructions: The given template code forms a working program, and you can try to run it. However, be careful to not cause any changes in the templates directory.

The template code can be found from the directory templates/11/grading, but you only need the files gradecalculator.hh and gradecalculator.cpp. There is also the file main.cpp, but in GUI programs Qt generates us the corresponding file with same name but with a different content.

Create a new Qt project: student/11/grading_gui/ (note the name different from the template code). Now, Qt generates the class MainWindow (files mainwindow.hh, mainwindow.cpp, and mainwindow.ui). Add a new class (moduuli) GradeCalculator to it, but replace the file gradecalculator.hh generated by Qt with the file of the same name given in the template code. Accomplish the same action with the file gradecalculator.cpp. Do not modify the given module GradeCalculator, but only the class MainWindow.

Your task is to use Qt Designer to implement a dialog that looks like the figure below.

User interface before giving input values

After the user has given desired points and exam grade and clicked the Calculate button, the program prints into the textBrowser widget the following information: score from weekly exercises (W-Score), score from projects (P-Score), and total grade. Therefore the dialog will look, for example, like below.

User interface with inputs and outputs

You can print texts in different lines by using the character '\n' in a string. For example, the string "ab\ncd" will be printed as:

ab
cd

The file main.cpp given in the template code checks if the numbers given by the user can be accepted. Note that you can achieve corresponding checks by setting ranges for the spin boxes (with the method setRange).

Instruction to pass automated tests

Use the following object names for spinBox widgets: spinBoxN, spinBoxG, spinBoxP, and spinBoxE. For these widgets, use the signal valueChanged(int). For the button, use the object name calculatePushButton. For the textBrowser widget, in which you print the total grade, use the object name textBrowser.

In the same way as in the BMI (body mass index) exercise, use the signal & slot mechanism to connect suitable actions for the widgets.

Tips for completing the assignment:

  • First, follow the instructions given above. After that a good place to continue is to construct the user interface.

  • Anyway, you can use similar steps to those described in the BMI exercise.

  • Before printing an integer value, you most probably need to convert it to a QString. This can be done as follows:

    int x = 0;
    QString s = QString::number(x);
    

A+ presents the exercise submission form here.