C++ Programming Using Microsoft Visual C++ 2019 on Windows

 

 

**************************************************************

Note: What you need to do if you have a Mac but not a PC:

(i) You can simply use the PC computer labs on campus for your programming assignments.

(ii) Alternatively you may use the Xcode environment on the Mac platform for C++ programming for convenience. See a brief introduction to how to use Xcode for C++ programming. However, in the end you should still run Visual C++ 2019 to check your program before submitting your work. This is because sometimes Xcode allows a C++ program to go under some faults, but the program may fail when the TAs test your program under Visual C++ onWindows.

(ii) Either way you do need to know how to compile your C++ program using Microsoft Visual C++ 2019 on Windows. So please read the descriptions below.

**************************************************************

 

 

C++ Programming Using Microsoft Visual C++ 2019 on Windows

 

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. 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 Visual C++ compiler provided under Microsoft Visual Studio Community 2019 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. Get Microsoft Visual C++ 2019 on your own Windows platform: We use Visual C++ in Microsoft Visual Studio Community C++ 2019 Edition as the standard C++ compiler to compile your programs and determine your grades based on the results under such settings.  For Windows, click here to automatically download Microsoft Visual Studio Community 2019 Edition for free. After the download, click the downloaded executable to proceed with the installation. Make sure you do select "Desktop development for C++" (instead of the "Universal Development …"). You do want to register your Visual Studio with Microsoft so that you can continue to use it in the long run.

 

4. Explore a sample Visual C++ 2019 project of Microsoft Visual Studio: For each new program we write, we need to create a separate Visual C++ programming project, and have all the related files (source code files and header files …) of the program stored within the project folder. For example, consider this very simple C++ program composed of a single main.cpp file only. For this program, we have already created a sample Visual C++ 2019 project and compress it as a zip file for you. Please first click here and download the sampleProject zip file to a selected location you want. Find and right click the sampleProject zip file and then select Extract all to extract the project folder (the sampleProject folder) from the zip file. Open the the sampleProject folder and double click the myProgram.sln solution file. This will automatically invokes Microsoft Visual Studio to open the entire project for you. Try to compile the program in the project to get some hands-on experiences according to the descriptions in #5 below.

 

5. Reuse the sample Visual C++ project for C++ Programming: For our programming assignments this semester, you can simply make a copy of the sample project folder you got from #4 above, rename the folder as you want (such as program0 for example), and then go into the project folder and open up the project by clicking the myProgram.sln solution file in the folder. You can then edit and replace the contents of main.cpp with your own new C++ code. To finish your programming assignment, you may then repeatedly do the following things with the project under Microsoft Visual Studio:

 

6. Optional alternative: If you would like to create a new project for a new C++ program from scratch on your own, you can also create a new project from scratch each time for a new C++ program assignment according to the description below.

To create a new C++ project from scratch, do the following:

·         Go to File menu, point to New on the menu, and then click on Project to start the process of creating a new project from scratch.

·         Under the new project setting, check Console App.

·         Proceed to configure your new project by setting (i) the name of your project and (ii) the location of your project, and then click Create to create your project in the new project folder at the selected location.