C++ Using Visual C++ 2008
A. Lab #
B. Lab 6 of 7: Menu Driven Applications (GUI)
C. Lab Overview – Scenario / Summary:
You will code, build, and execute two programs requiring GUI. The first program will ask
the user to input a password then reenter it for verification. The second program is a
number guessing games that generates a random number and asks the user to input their
guess.
Learning outcomes:
1.
2.
3.
4.
To be able to explain the need for menus in a program.
To be able to determine ways to implement menus in a Windows application.
To be able to understand the classes and objects used in a Windows application.
To be able to write a Windows application.
D. Deliverables:
Section
Part A
Part B
Deliverable
Step 5. Program Listing and Output
Step 5. Program Listing and Output
Points
20
25
E. Lab Steps:
Preparation:
If you are using the Citrix remote lab, follow the login instructions located in the iLab tab in
Course Home.
Locate the Visual Studio 2008 Icon and Launch the application.
Lab:
Part A: Password Program
Step 1: Requirements
Write a Windows application that simulates entering a password. The user enters a
password and clicks Next. Then the user types the password again and presses Continue.
The program will display a MessageBox that displays either the passwords are equal or not
Page 1 of 12
equal.
Sample Output:
I type in Bob in the password field and press Next
I type in Bob in the second password field and click Continue
Page 2 of 12
Message displayed if the passwords match.
Message displayed if the passwords are different.
Step 2: Processing Logic
Using the pseudo code below, write the code that will meet the requirements:
Next Button Event Handler Method
Make visible the second password textbox, the Done button, and the labels
Let the second password textbox gain focus
Done Button Event Handler Method
If the first password text box equals the second password textbox
Display the message "Passwords are the same"
Else
Display the message "Passwords are different"
Page 3 of 12
Step 3: Create a new project
Create a new project and name it LAB6A.
Write your code using the Processing Logic in Part A Step 2. Make sure you save your
program.
Step 4: Compile and Execute
a) Compile your program. Eliminate all syntax errors.
b) Build your program and verify the results of the program. Make corrections to the
program logic if necessary until the results of the program execution are what you
expect.
Step 5: Print Screen Shots and Program
1. Capture a screen print of your output [Do a PRINT SCREEN and paste into an MS Word
document.]
2. Copy your code and Paste it into the same MS Word document that contains the screen print
of your output.
3. Save the Word Document as Lab06A_LastName_FirstInitial
Step 6: How to get started with your first Windows application
1. Go to Visual Studio 2008. Go to File -> New ->Project to open a new C++ project.
2. Pick Windows Forms Application as the template and name your project to CIS170CLab6A.
3. You will see the empty form displayed. We now need to use the Toolbox to add components to
our program.
Page 4 of 12
4. Based on the specification of the program, we need to add the following components to our
form:
Three Label – lblFirstPassword, lblSecondPassword, lblConfirm
Two TextBox – txtFirstPassword, txtSecondPassword
Two Button – btnNext, btnContinue
From the Toolbox, drag a label and drop it to the form:
Page 5 of 12
Right click the component label1 and click on properties.
Change the Text to Password.
Page 6 of 12
Change the name to lblFirstPassword.
You will now have the first component – a password label.
Apply the same drag and drop operation to add the rest components into your form and your
final interface will look like this:
Since we only want the first password label, the first password textbox and the Next button to
show initially, we need to set behavior Visible to False for the rest of the components.
5. We now are ready to add application logic to the Next button. Double click the Next button will
bring us to the function btnNext_Click().
6. Based on the supplied pseudo code:
Next Button Event Handler Method
Make visible the second password textbox, the Done button, and the labels
Let the second password textbox gain focus
We can add the following application logic to the function:
7. We now go back to the design page and double click the Continue button.
8. Based on the supplied pseudo code:
Page 7 of 12
Done Button Event Handler Method
If the first password text box equals the second password textbox
Display the message "Passwords are the same"
Else
Display the message "Passwords are different"
We can add the following application logic to the function:
9. The program is now finished and we can start testing it. If you successfully build your project
with no errors, you will see the following interface displayed.
Enter a password and click on Next:
ReType your password and click on Continue.
You will get a message stating that Passwords are the same.
Congratulations, you successfully finished your first windows application in C++.
END OF PART A
Page 8 of 12
Part B: Number Guessing Game
Step 1: Requirements
Write a Windows application that randomly generates a number from 0 through 100. Prompt
the user to guess the number. Let the user know if the guess is too low, too high, or is the
correct number. Give the user another chance to guess the number. The user keeps
guessing until he gets it correctly.
Sample Output:
I entered a number and pressed the button.
Page 9 of 12
I pressed the button and the box and message are cleared.
I entered a number and pressed the button
Page 10 of 12
After entering several numbers, I got the following.
Message displayed when the guess is right.
Step 2: Processing Logic
Using the pseudo code below, write the code that will meet the requirements.
Form constructor method
Randomly pick a target number between 0 and 100
Evaluate Button Click Event Handler Method
Add 1 to the number of guesses
If the guess is equal to the target
Display a message indicating the user guess correctly and display the number of
guesses
it took.
Else if the guess is less than the target
Change the label message to "Too Low!!"
Else
Page 11 of 12
Change the label message to "Too High!!"
Make the label message visible
Make the Try Again button visible and let it gain the focus
Make the Evaluate button invisible
Try Again Button Click Event handler
Make the label message and Try Again buttons invisible
Make the Evaluate button visible and gain the focus
Clear the guess text box
Step 3: Create a new project
Create a new project and name it LAB6B.
Write your code using the Processing Logic in Part B Step 2. Make sure you save your
program.
Step 4: Compile and Execute
a) Compile your program. Eliminate all syntax errors.
b) Build your program and verify the results of the program. Make corrections to the
program logic if necessary until the results of the program execution are what you
expect.
Step 5: Print Screen Shots and Program
1. Capture a screen print of your output [Do a PRINT SCREEN and paste into an MS Word
document.]
2. Copy your code and Paste it into the same MS Word document that contains the screen print
of your output.
3. Save the Word Document as Lab06B_LastName_FirstInitial
END OF LAB
Page 12 of 12
12 years ago
Purchase the answer to view it
- computer_scienceilab.rar
- computer_scienceilab.zip