Using the Microsoft Visual C++ Compiler
Here's a video tutorial (or linked here at my "misterminich" YouTube channel) that may help you follow these instructions.
- If you download the free version, start the Visual C++ software by clicking the Start/Programs/Visual C++ 2010 Express Edition command. On campus, you click Start/All Programs/Microsoft Visual Studio 2010/Microsoft Visual Studio 2010.
- Choose File/New/Project... from the menu. Click "Visual C++" on the left under Project types. Select "emptyproj" on the right under Templates. If you are on a campus computer, you click the "Empty Project" icon on the right.
- Type the name of the project under Name. You can use a name such as "a1" (i.e. assignment #1). This entry will end up being the name of a folder that is automatically created to store all of the files related to your new computer program.
- Click the Browse button to specify a location on your hard drive or USB flash drive for this folder (i.e. directory) or allow Visual C++ to store the folder in the default location of "My Documents\Visual Studio 2010\Projects". Make sure there is a checkmark next to "Create directory for solution". The Solution Name should be the same as the name that you specified above. Click the OK button. On a campus computer, you should specify the Desktop as your location for saving the project.
- Click the Project/Add New Item... menu command. If you do not see this menu command, see the additional steps below.
- Select "Visual C++" under Categories on the left. Select "C++ File (.cpp)" under Templates on the right.
- Type the name of the source file (e.g. a1) for Name. It is simple and easy to remember if you type the same name for this C++ source file that you used for the project in step #1 above. It is optional to type the .cpp file extension. The location should be the folder that was specified and automatically created by step #1 above. Click the Add button.
- Type the source code for your program.
- Click the Build/Build Solution menu command. This compiles your program which checks it for errors. You must compile the program before executing it.
- Any errors in your program will now be indicated in a window at the bottom of the screen. On a campus computer, you can double-click anywhere within the line that describes the first error. The compiler will probably highlight a line of your program where it believes an error is located. On a campus computer, errors may be indicated by squiggly underlines. Note that an error sometimes is on the line just before the highlighted line of code. Anyway, you should find and fix that error and try compiling your program again. Do not worry yet about fixing any other errors that you might see listed since they may be errors that resulted from the first one that you fixed. Also, you can generally disregard warnings since they do not prevent your program from executing and are sometimes incidental. The process of fixing errors in a program is called debugging.
- To run (i.e. execute) your program, click the Debug/Start Without Debugging menu command.
- When your program executes, it's output will be displayed in a black DOS console window. After you have studied the program's output, press any key to continue.
- To print your program's source code, click the File/Print... menu command.
- When you are finished writing, modifying, & recompiling your program, click the File/Exit menu command to completely exit the Visual C++ compiler. Your program (the .cpp source file) is now saved in the folder that was created in step #1 above. If you are planning to immediately write another C++ program, you should click the File/Close Solution menu command or completely exit the Visual C++ compiler software and follow these instructions from the very beginning.
- To copy your source and executable files to a USB flash drive or your PSU PASS X: drive, copy (or drag and drop) the whole project folder to that new location.
- For CMPSC 101 "Assignments", you must upload the source file (which has a file extension of .cpp) and the executable file (which has a file extension of .exe) to the appropriate drop box in Angel. These two files are located in your project's folder. If you named your project "a1" then there is an inner folder named a1. Inside that inner a1 folder, there is a file named a1.cpp however some computes do not show file name extensions so the file may be named simply a1. It will have an icon with the letters C++ on it. This file must uploaded to the Angel drop box. The other important file, a1.exe, is found inside of a folder named "Debug". Actually, there are two folders named Debug. The a1.exe file is found in the outer Debug folder. The .exe filename extension may not show up so this file may also appear with the filename "a1". However, it's icon is a greenish rectangle and it may say that it is an "Application". Double-clicking the exe file will run your program even on Windows computers that does not have the Visual C++ compiler installed. This file must also be uploaded to the Angel drop box. I highly recommend that you use the Internet Explorer browser rather than Firefox, Chrome, or another browser. After you upload a1.exe to Angel, you should click on the entry and you will be given the chance to execute the file just as I will be doing to grade your program. If the program doesn't work correctly, when you do this, you should resubmit it. If the black output window immediately goes away without giving you the chance to read the output and press any key to continue then you probably forget to add the critical system("pause"); line of code. You will lose many points if you do not add that line of code.
Modifying a program that you already have saved.
- If your project folder is not saved to your home computer's Documents folder, copy your project folder from your USB flash drive or your PSU PASS X: drive to your computer's desktop.
- Double-click the file with the .sln file extension. Or, click the File/Open/Project/Solution menu command and find and click the file with the sln file extension or the file with the vcproj file extension.
- If necessary, click the plus symbol next to the name of your project on the right. Then click the plus symbol next to "Source Files" on the left. Finally, double-click your .cpp source file in order to open it in the main editing window.
If you don't get a list of errors at the bottom of the screen, follow these steps:
- Click on the Tools/Options menu command.
- Click the plus symbol next to the Projects and Solutions entry on the left.
- Click on the General entry.
- Place a checkmark next to the "Always show Error List if build finishes with errors" option
- Click the OK button to close the window.
If the Project/Add New Item menu command doesn't appear in Step #5, follow these steps:
- Click the Tools/Import Settings menu command
- Click "Reset all settings"
- Click "Next"
- Click "No, just reset settings, overwriting my current settings"
- Select "General Development Settings".
- Click the "Finish" button