Академический Документы
Профессиональный Документы
Культура Документы
1 Introduction
The first lab of C++ will describe how to use the Integrated Development Environment
(IDE) of the Microsoft Visual C++ 2010 (MVSC). Lab 1 begins with a brief explanation
of the IDE where it covers from the beginning of constructing a program until the
programs output. Then student will be introduced to the structure of a simple C++
program. Before writing the first C++ program using MVSC, basic command of output
will be described.
ed the source code. A preprocessor is a program that removes all comments and modifies source code according to preprocessor directive (statement
No.
1
Description
Comments: Internal programming documentation. Comments will be ignored
by compiler, and comments do not affect the way the program runs.
Preprocessor Directive: Tells the compiler to include input/output stream
4
5
statement will tell the compiler where to look for names in the libraries.
Global declaration: Declaration that are visible to all parts of the program.
Main function: The starting point of a program. A group of statements/program
All C++ statements except preprocessor directive end with a semicolon (;).
C++ functions must have an opening and matching closing bracket. ( {<statement>} )
cout<< : an output object that sends data given to it to the standard output
Escape sequence: The backslash character (\). This character tells the compiler
that the sequence following does not have the same meaning as the character
appearing by itself. Table 2 below lists some commonly used escape sequences.
Escape
Name
Description
Sequence
\a
\t
\n or endl
\"
\'
\?
\\
Audible alert
Horizontal Tab
New line
Double Quote
Apostrophe
Question mark
Backslash
Bell sound
Takes the cursor to the next tab stop
Takes the cursor to the beginning of the next
line
Displays a quotation mark (")
Displays an apostrophe (')
Displays a question mark
Displays a backslash (\)
2. The first step in writing a Visual C++ program is to create a project for it. In the
menu bar, click File -> New -> Project...
3. In the New Project dialog box shown below, select by clicking Visual C++ in the
Installed Template pane and Win32 Console Application in the middle pane.
4. In the Name text box, give the project a name, e.g., Exercise1
5. In the Location text box (at the bottom of the dialog box), specify the path of the
project,(e.g.; C:\LAB1) or select the location or folder in which youd like to store
project files by clicking the Browse
6.
Click OK. Note that there is no need to enter a name in the Solution name text
box; the system fills the project name in it by default.
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++ program file, right click the Source Files Folder on the
Solution Explorer. In the popup menu, click Add then New Item or in the menu
bar, click Project -> Add -> New Item...
11.In the Installed Templates list of the Add New Item dialog box, make sure Visual
C++ is selected.
12.
13.
In the Name text box, give the C++ program file a name, e.g: Exercise.
14.
Click Add.
15.
Using the text editor in the IDE, fill the contents of file Exercise with the
following C++ program:
/*Program 1: This program demonstrate a simple C++
program*/
#include <iostream>
using namespace std;
int main()
{
cout << "Welcome to Lab 1!!!\n";
return 0;
}
16. To compile the program, on the main menu, click Build -> Build Exercise1.exe
10
18. To see the output (execute), on the main menu, click Debug-> Start without
Debugging.
11
20. After viewing the result, press any key on the keyboard to close the program
output and return to MSVC.
12
1.3
Syntax error: Syntax is the set of rules for forming valid instructions. Syntax error violates the syntax of a language.
Warning message: Message from a compiler advises the programmer that a statement is technically acceptable but might have a potential error.
Exercises
1. Write a program that can print as the following:
University :
Faculty :
FKEKK
Programme :
BENG
b)
13
The background / foreground colour for the output screen, its font,
size etc can be set in the output windows property.
14
3. a)
15
4.
Output:
Output:
16