

→ 
→ 

→ 
#include <cstdio>
void try_password(char* guess);
void main()
{
char* hack = "abcd";
try_password(hack)
}
void try_passwerd(char* guess)
{
char* username = getenv("USERNAME");
for (int i = 0; i < 4; ++i) {
char c = username[i]^2;
if (guess[i] != c)
printf("CHARACTER %d IS WRONG\n", j); // print index 0..3 of mismatch
}
}
}
The code doesn't compile because it was written by an engineer who totally forgot C++ over the summer.
There are precisely five "C++ mistakes" in the code (missing ; , stuff like that).
Get the program to compile by finding these tiny mistakes.
getenv is not included
(needs #include <something>).
Position the text cursor on getenv and hit F1 to get Microsoft's getenv documentation. If asked to choose "Online or Local Help", choose Online.
+ Hit F1 → 
Run your corrected program from Part B without debugging (Ctrl+F5).
It complains that some characters in the current password "abcd" are incorrect.
Close the window and go back to Visual Studio.
Your job in Part C is to hack try_password to figure out what 4-letter
password it expects. You must use the debugger, and should not modify the code except to change the default password from "abcd".
try_password.

try_password function, then hit F10 until
the CPU is about to test if guess[i] is correct.
i,guess[i], and c.
Either hover the mouse over the variable you want, or enter them into the Watch window, whichever you like best.
'g' and not 'a'.
guess[i] is correct. There are two ways:
either click the gray margin with the mouse, or hit F9 to create one wherever the cursor is.
i becomes
0,1,2, and finally 3, and you can inspect the value of c each time.
| Ctrl+F5 | → Run program; CPU runs until program quits |
| F5 | → Run program with debugging; CPU will freeze at any breakpoint |
| Shift+F5 | → Quit debugging; your program is forced to quit and debugging stops |
| F9 | → Toggle breakpoint on current line |
| F10 | → Step over; CPU runs all code on current line, including functions |
| F11 | → Step into; follow the CPU to the next line of code it actually executes |
| Shift+F11 | → Step out; let the CPU finish the current function and freeze after it returns |
| Shift+F9 | → Quickwatch; pop-up version of Watch window |
→ 
→
→ 
#include "cs1037lib-window.h"
#include "cs1037lib-image.h"
void main()
{
SetWindowTitle("Lab 1");
SetWindowVisible(true); // Show main window
int map = LoadImage("london.png"); // Load image from file
DrawImage(map,0,0); // Draw image at xy position (0,0)
while (!WasWindowClosed()) { // Loop until user closes window
// do nothing
}
DeleteImage(map); // Free memory used by image
}
If you run this program, it will complain that "london.png" is missing.
Download london.png and save it beside main.cpp.
GetMouseInput function in cs1037lib-window.h
and look at the example given there.
It should only take 6–9 extra lines of code to make your program act like lab01demo.exe.