C++ Programming Using Microsoft Visual Studio

1. Files of a C++ program. In its simplest form, a C++ program is simply a source code file with the file extension .cpp, in which you have C++ source code defining the main function and maybe other functions. The main function is the starting point of execution when you successfully compile and run the program. In general, a C++ program, in addition to such a single source code file, may have other source code files (with the file extension .cpp), plus some header files (with the file extension .h), and others.  


2. Compiling C++ program under Microsoft Visual Studio.NET. In order to run a C++ program, we need a compiler to translate C++ source code in the program into executable computer hardware instructions so that the computer can do what you want to do. In this course, we use the C++ compiler provided in Microsoft Visual Studio available in the computer labs to do this job. Microsoft Visual Studio also provides a convenient environment for editing and managing your C++ programs.  The following is an introduction to the use of Microsoft Visual Studio to meet the needs of our programming assignments.  


3. A sample project under Microsoft Visual Studio. For each new program we write, we need to create a project for it in Microsoft Visual Studio, and have all the related files (source code files and header files ) of the program added into the project. Usually we have the C++ source code file(s) and header file(s) of the program together with some project information files stored in a single project folder. For example, consider a very simple C++ program composed of this single main.cpp file only. For this program, here is a Microsoft Visual Studio project folder (compressed as a zipped file). Please download it and use WINZIP to unzip it to get the project folder. Open the folder and double click the sample.sln solution file. This will automatically invokes Microsoft Visual Studio to open the entire project for you. Play with it to get some hands-on experiences.


4. Free Microsoft Visual C++ 2010 Express Edition



5. Other free C++ compiler GNU: There are many other free C++ available on different hardware platforms. Among them, Gnu gcc is a top quality widely used open-source C++ compiler for free.

6. Steps of programming using Microsoft Visual Studio. For the first programming assignment, you can simply make a copy of this entire sample project folder, rename the folder, and then replace the contents of main.cpp with your own code. (See the description at #5 below, if you would like to create a new project for a new program that has multiple source code files and header files in it from scratch by yourself, instead of using and modifying the sample project given in #3.) To finish your programming assignment, you may repeatedly do the following things with the project under Microsoft Visual Studio:


7. Create a new project for a new C++ program from scratch. You can always make a copy a solution project folder and change its contents for a new programming assignment. Instead of reusing the sample project I gave you, you can also create from scratch a new project for a new C++ program, which may have multiple source code files and header files in it, in the following way

  1. Start Microsoft Visual Studio.
  2. On the File menu, point to New, and then click Project.
  3. Under Project Types, click Visual C++ Projects.
  4. Under Templates, click Win32 Console Project.
  5. In the Name text box, type any name you give to the project.
  6. In the Location text box, type any location you choose, and then click OK.
    The Win32 Application Wizard dialog box appears.
  7. In the Win32 Application Wizard dialog box, click Application Settings in the left pane.
  8. Under Application Type, click to select Console application.
  9. Under Additional options, click to select the Empty project check box.
  10. Click Finish to create an empty new project (with a corresponding project folder under Windows).
  11. To create a whole new .cpp file (or an .h file) and add it into the project, under Project click Add New Item to proceed.
  12. To add a .cpp file that already exists (or an .h file) into the project, first (under Windows) copy the file into your project folder and then under Project click Add Existing Item to proceed.