< Back

Lecture 10- C++ Design and Test Cases


As usual, create a directory to hold today's activities:

$ mkdir ~/cs170/labs/lab10 
$ cd ~/cs170/labs/lab10

QT

QT is a graphical environment that allows us to write "professional" looking applications. It's the first time we've directly worked with things suck as text boxes and buttons. QT allows us to use even more powerful graphical components: lists, progress bars, menu bars, image buttons, etc. We will work with basic syntax and components today, so we can explore more advanced components next week!



Lab Activity 1
Temperature Converter

One of the most common things we will do in a QT application is take some information the users gives us, and do some sort of processing on it. We will either be storing the information, or performing a computation and outputting some relevant data associated. Performing the computation should be straight forward. It's practice with QT that we need today.

Details

Using QTCreator, create a C++ program that displays a form that asks the user to enter in a numeric value that represents the current temperature. There should be two buttons. Pressing one of the buttons should convert the given temperature into Celsius, while the other should convert into Fahrenheit. The result of the computation should output to a label placed else where on the window.

Example

 

Challenge

Add an additional button that will convert to Kelvin.


Lab Activity 2

One of the great, but unfortunate things about QT is that there are so many built in components. We just don't have time to explicity cover every single one of them in a lecture. So it will sometimes fall onto you to learn how some of these components work. For this activity, you will play around with a Spinner Box.

Details

Using QTCreator, create a C++ program that displays a form that allows the user to select 4 integer values. Your program should generate 4 random numbers as the combination. When the user presses the submit button on the form, your program should check whether all 4 spin boxes match the randomly generated combination. It should display "valid" or "invalid" depending on if the combination is correct.

To generate a random number in C++, you need to use the rand() function. This function will return a random number in a very large, system defined range. These numbers will be the same every time you run the program, unless you change the seed using the srand() function. Read these pages to get see examples of how they work.

Example

 

Challenge

Modify your program so that it displays the number of correct entries the user has chosen.