Overview
This laboratory will have you using while loops and if statements, among other control structures. You will also create a new class, instantiate an instance of that class, and call a function within that class. First you will create a console application that has you enter passing or failing grades - it will calculate the number of each and provide responses based on the total number of each pass or failure. Second you will use visual programming to create a "Memory" game where you select two cards at a time, if they match, you remove those cards. You continue this process until all of the cards are matched.
Procedures
- Grade analysis console application
- View a finished release candidate
- Open a new instance of VS08
- New Project... > Console Application > Name it: Analysis (pay attention to where you save it)
- Right click on the project name in Solution Explorer (in bold), select Add > New Item...
- Choose Class
- Name it: doAnalysis.cs
- Click Add
- Inside class doAnalysis
- Create a function: public void ProcessExamResults()
- Inside Main
- Instantiate a new instance of doAnalysis
- Use that instance to call ProcessExamResults()
- Inside ProcessExamResults()
- Declare and initialize 4 integers: passes, failures, studentCounter, results
- Use a while loop to prompt the user 10 times (use studentCounter)
- Prompt the user to: Enter result (1 = pass, 2 = fail):
- Store the user input into the variable result
- Use an if...else to determine whether the result is a 1 or a 2
- if the result is a 1, increment the variable passes by 1
- else if the result is a 2, increment the variable failures by 1
- increment the studentCounter
- Note: if you forget to increment the counter, you'll get an infinite loop and your program will "hang" and eventually use up so much memory that it crashes.
- After the while loop, write out the number of passes and failures using the format item {0}
- Then use the ternary operator to test if passes is greater than failures, if so write "Great Job", if not write "Get some tutors"
- The use an if statement to see if passes is greater than 8. If so, write "Raise tuition"
- Finally, write out a message to press the Enter key to continue and wait so the user can see the result
- Test your project
- Memory Matching game
- View a finished release candidate
- Open a new instance of VS08
- New Project... > Windows Forms Application > Name it: Memory (pay attention to where you save it)
- Layout
- Use these images | cardPair_sm.png:
- background, cardback, icon, kitten, puppy, monkey, bear, road runner, wile e coyote
- Layout the controls in the application similar to what you see in the release candidate
- form should be 900 x 650 pixels
- add background image
- add icon
- add 12 pictureBox instances to the form (100 x 100 pixels)
- add a title label (approx 40pt, centered at top)
- add a congratulations label (approx 40pt, centered in middle)
- add a play again button (centered in middle below congrats)
- add a label containing your name in the lower right corner (10pt)
- Coding
- Declare private variables:
- need 12 int's: card1 through card12
- need int's: randomNum, numMatches, counter, numSelectedCards, firstSelectedCard, totalNumMatchesRemoved
- Inside Form1() constructor
- Set the congrats label and play again button visibility to false
- Initialize the pictureBox image location to cardBack.jpg for all 12 pb's
- Randomly create 6 matches - use a switch
- Add 12 Event Handlers, one for each pictureBox on the form
- increment numSelectedCards
- Check to see which picture to display (see if cardx is equal to 1-6)
- Set the image location based on whether the value is 1,2,3,4,5,6
- if there are two cards selected
- Pause the application
- if the firstSelectedCard is cardx
- find the two cards and remove them from the screen
- use an if...else if
- Increment the total number of matches removed
- Check to see if the total number of matches removed is 6
- if so, display the congrats label and play again button
- else - when the firstSelectedCard is not cardx
- Set the image location of all 12 pb's to cardBack.jpg
- Set the number of selected cards and the first selected card back to zero 0
- else if the first selected card is 0
- Set the value of the first selected card to be equal to cardx
- Add an Event Handler for the play again button
- Re-initialize all variables
- Set the congrats label and play again button visibility to false
- Set the visibility of all 12 pb's to true
- Initialize the pictureBox image location to cardBack.jpg for all 12 pb's
- Randomly create 6 matches - use a switch
- Test your project
- Finalization
(do this for both applications)
- Build > Configuration Manager
- Change "Active solution configuration" to Release.
- Make sure "Configuration" changes to Release.
- Close
- Rebuild
- Look in <project folder> / bin / Release
- Double click <projectName>.exe
- On your own
- Write the pseudocode for each application in a large comment block at top of the .cs files. Be thorough with your pseudocode. It should be easily readable by anybody (regular english terminology). Essentially, if there's a line of code, there should be a line of pseudocode. You do not have to write pseudocode for the "layout" code.
- Turn in both entire projects.
Grading
Console App |
5 pts |
Memory App |
10 pts |
Commenting of Code |
5 pts |
|
|
Total |
20 pts |
|