MCC - CIS 162AB - C++ Level I
P01 Hello - 10 points
   cpp.gif

Introduction to Using Microsoft Visual Studio .Net

All files related to a program are stored in a Project. This document will walk you through the process of creating a Project, and adding a Source file, and text file to it. You will need a separate Project for each assignment, so pay attention to the detailed steps as you go through this document, because you will be doing this throughout the semester.

  1. Put your name on your storage device (flash disk).

  2. Insert storage device into the appropriate connection on the computer.

  3. Start Microsoft Visual Studio 2008 or Visual C++ 2008 Express Edition.

    • In Mesa Community College's computer lab open Microsoft Visual Studio 2008.
    • The program to open on your home computer will depend on which version was installed,
      Microsoft Visual Studio 2008 or Visual C++ 2008 Express Edition.

    • The Microsoft Visual Studio program appears:

      Start VS.Net (p01_start.jpg)

    • If necessary, maximize the application window to fill the whole screen by clicking the maximize button in the upper right-hand corner of the window.
    • Do NOT be alarmed if your Start Page does not look like the picture above.
    • Start Pages will vary by version and will depend on who used it last and on the options selected.

  4. Each assignment must be stored in a separate project.
    • Click on File on the menu bar, scroll down and mouse over New, and then slide over and select Project....

      New Project Window (p01_newproject.jpg)
    • The list of Project Types and Templates will vary based on the software version being used (Professional or Express).
    • The Templates on the right side can be displayed either in large or small icons. Select small icons by clicking on the small icon button which is the button on the far right above the Templates.
    • From the list of Frameworks on the upper right side select .Net Framework 3.5 in the dropdown list.
    • From the list of Project Types on the left side click on Visual C++.
    • In the list of Templates scroll down and click on Win32 Console Application .
      Note: Selecting anything else will cause your program not to work as described in this document.
    • Enter Name: P01 (0 is the number zero and not the letter O)
    • To set the Location: use the Browse... button to navigate to the drive assigned to your storage device.
    • The Solution Name should be the same as the application Name (P01). It may already be grayed out if Create a directory for solution does not have a check mark as instructed on the next step.
    • Click on the box in front of Create a directory for solution to remove the check mark.
    • Click on OK.

  5. After clicking on OK, the Win32 Application Wizard will appear.
    • Click on Application Settings on the left size of the window.

      Win32 Application Wizard (p01_newwizard.jpg)
    • Verify that the radio button before Console application is selected.
    • Click on the box in front of Empty project to select it.

      Always select Console application and Empty project
      Selecting anything else will cause your programs not to work as described in this document.

    • Click on Finish to create the project.

  6. The new project should appear in the Solution Explorer window.
    • If your workspace window does not display the Solution Explorer,
      click on View on the menu bar and select Solution Explorer.

      Note: Visual C++ 2008 Express displays the Solution Explorer on the left.

      Solution Explorer (p01_solution.jpg)

  7. The next item that must be created is a Text File for the sample output.
    This process will vary based on the software version being used (Professional or Express).

    Microsoft Visual Studio 2008 (Professional):
    • Click on Project on the menu bar, and select Add New Item...

      New Text File for Output (p01_newoutput.jpg)

    • On the left side under Categories, Visual C++ should be selected.
    • On the right side under Templates, scroll down and click on Text File (.txt).
    • Enter file Name: output
      The extension .txt will automatically be added to the file name.
      Just about every project will require a text file for the sample output.

    • The value for Location: will be automatically set based on the values entered when the project was created.
    • Click on Add.
    • The output.txt file should now be listed in the Solution Explorer and opened in the workspace window. The sample output produced by the program will be copied and pasted into output.txt in a later step.

    Visual C++ 2008 Express Edition:

    • Click on Project on the menu bar, and select Add New Item...

      New Text File for Output (p01_newoutput2.jpg)

    • On the left side under Categories, Visual C++ should be selected.
    • On the right side under Templates, scroll down or down and click on C++ File (.cpp).
    • Enter file Name: output.txt
      Include the .txt extension to force the creation of a text file.
      Just about every project will require a text file for the sample output.

    • The value for Location: will be automatically set based on the values entered when the project was created.
    • Click on Add.
    • The output.txt file should now be listed in the Solution Explorer and opened in the workspace window. The sample output produced by the program will be copied and pasted into output.txt in a later step.

  8. The last item that must be created is a C++ Source File.
    • Click on Project on the menu bar, and then scroll down and select Add New Item....

      New C++ Source File for main() (p01_newsource.jpg)

    • On the left side under Categories, Visual C++ should be selected.
    • On the right side under Templates, scroll up or down and click on C++ File (.cpp).
    • Enter File name: P01
      The extension .cpp will automatically be added to the source file name.
      Every project will require a C++ source file.

    • The value for Location: will be automatically set based on the values entered when the project was created.
    • Click on Add.
    • The P01.cpp file should now be listed in the Solution Explorer under Source Files and opened in the workspace window.

  9. Enter the source code for the program into the newly created C++ source file.
    • The file P01.cpp should now be listed under the Solution Explorer with in Source Files. If P01.cpp is not visible, click on the plus sign (+) in front of the Source Files folder name to expand the folder and see the source file P01.cpp.
    • Double click on the file P01.cpp to make it the active file for the editor.
    • Enter the Hello World program in the editing window as shown below.
      The editor works more-or-less like a word processor.
      Key words are set to different colors, and it auto-indents on the open and close braces ({}).
      Press enter at the end of each line.
      Be sure to change both occurrence of the instructor's name to your name.

    • Source code for P01.cpp (p01_source.jpg)

    • Click the Save All button or select Save All from the File menu.
      You should save your work at various times during your work sessions to prevent the loss of data.

  10. When you have completed entering or editing a program, it must be compiled, linked, and executed. The first step of the three is compile.
    • Compile the program by selecting Compile from the Build menu.

      The status bar at the botton should first display Build started... and end with Build succeeded.

      Compile Log (p01_compilelog.jpg)

      The compiler will display a list of errors (if any) in the Error List window. If your program has syntax errors identified by the compiler, double click on a error to highlight the error message and to move to the line of code where the error occured. Correct all the errors in the editing window and recompile by selecting Compile from the Build menu again. Keep editing and recompiling until all errors have been corrected. The program must entered as displayed above. The only thing change is the instructor's name to your name.

      Note: Visual C++ 2008 Express displays messages and errors on the Output pane at the bottom of the screen.

  11. After the program compiles successfully, it must be linked. Linking is referred to as building within Visual C++.
    • Link the program by selecting Build P01 from the Build menu.

      The results from the linker, including error messages, will appear in the Error List window. If your program has linking errors, you may need some assistance in resolving the problem. Typical errors include using the wrong #include statements, incorrect function names and parameters, or selecting a project type other than "Win32 Console Application". If you suspect a different project type was selected, it may be best to start over and name the second project attempt as P01a.

  12. After the program links successfully, it can be executed.
    • Execute your program by selecting Start Without Debugging from the Debug menu.

      Your output will appear in a similar MS-DOS window like this one:

      MS DOS Window for output (p01_dos_output.jpg)

      If execution does not pause so that the output can be reviewed, be sure to select Start Without Debugging from the Debug menu.

      After a program actually produces output, you begin the logic testing. If it works as expected, you're done. Otherwise, you'll need to review the program's logic and revise the program as needed in the editor window. Then you'll need to save, compile, link and execute it again to test the new logic.

  13. If the programs works as required, capture the sample output as instructed below.

    Windows XP:
    • Right-click on output window's title bar.
      On the pop-up menu, scroll down to Edit, and then over to select Mark.
      This will allow you to select text in the window.
    • Click and drag over the text you need to copy. As you drag the background will turn white.

      DOS output selected (p01_dos_selected.jpg)
    • Press the enter key to copy the selection.
    • Press the enter key again to close the console window and return to Visual C++.
    • Double-click on output.txt to open the file in the editing pane.
    • Paste the sample output into the output.txt file.
    • Click the Save All button.
    • If a printed copy of the output is desired by your instructor:
      Click on File on the menu bar and scroll down and select Print.
      Click OK in the printer dialog box.

  14. If the program works and a printed copy of the source code is desired by you or your instructor, then print a copy of the source code.
  15. Practice working through syntax errors using the Error List.
  16. To save space on your storage device, clean the project:
  17. To close project:
  18. To open an existing project:
  19. To exit Microsoft Visual C++:
  20. Submit online the source code (P01.cpp) and sample output (output.txt) for P01 when completed,
    or follow the instructions provided to you by your instructor.
    See Submitting assignments online.
  21. Very important: Eject your storage device.

Revised: 08/08/2008 - www.mc.maricopa.edu/~marquez/cis162ab/p01_2008/p01_intro.html