By The End of This Section, The Students Should Be Able To
By The End of This Section, The Students Should Be Able To
1 Introduction
The first lab of C++ will describe how to use Microsoft Visual Studio C++ .NET (MVSC). Lab
1 begins with an explanation of C++ typical environment where it covers from the beginning of
constructing a program until the program’s output. Then student will be introduced to the form
and structure of a C++ simple program. Before trying the first program using MVSC, basic
output command will be described.
1.1 Theoretical Background
A C++ system generally consists of three parts which are; a program development environment,
the language, and the C++ Standard Library. Figure 1 shows a typical C++ program development
environment.
1. Text Editor
2. Compiler
Program is created in
the editor and stored
on a disk 2.1 Preprocessor 2.2 Translator
Converting the
Preprocessor program
program to machine
process the code
language (object code)
3. Linker
Links the object code
with C++ libraries to
form an executable 4. Loader
program
On OS command (run),
Loader will locate the
executable program and
reads it into memory to
begins execution.
ce code. A preprocessor is a program that removes all comments and modifies source code according to preprocessor directive
1.1.2 A simple C++ program
Comments 1 program*/
Preprocessor 2
#include <iostream> 2
Directive
using namespace std; 3
Namespace 3
void fun(); 4
4
Global declaration void main()
{
cout<<”Welcome to C++ Lab”; 5
All C++ statements except preprocessor directive end with a semicolon (;).
C++ functions must have an opening and matching closing bracket. ( {…<statement>…} )
2. On the main menu of Microsoft Development Environment, click File -> New -> Project...
3. On the New Project dialog box, in the Location box (at the bottom of the dialog box),
specify the path of the project, e.g. C:\LAB1
4. In the Templates list view, click Win32 Console Application
6. Click OK.
7. In the Win32 Application Wizard - Exercise1 dialog box, click Next >
8. In the Additional Options section, click the Empty Project check box
9. Click Finish.
10. To create a new C++ file, right click Source File Folder on the Solution Explorer
11. On the main menu, click Project -> Add -> New Item...
12. In the Installed Template list, make sure Visual C++ or C++ is selected.
13. On the right pane list view, click C++ File (.cpp).
14. In the Name box, give the file a name, e.g: Exercise.
#include <iostream>
using namespace std;
int main()
{
cout << "Welcome to Lab 1!!!\n";
return 0;
}
17. To compile the program, on the main menu, click Build -> Build Exercise1.exe
18. If there is no error(s), the Output windows will show the build process was succeeded
19. To see the output (execute), on the main menu, click Debug-> Start without
Debugging.
20. After viewing the result, press Enter to close the DOS window and return to MSVC.
x error: Syntax is the set of rules for forming valid instructions. Syntax error violates the syntax of a language.
ing message: Message from a compiler advises the programmer that a statement is technically acceptable but might have a po
1.3 Exercises
(b) Programmer
(e) Compiler
(f) Linker
Output:
Output: