geng106-lab01

7
1 Qatar University College of Engineering Dept. of Computer Science & Eng’g Computer Programming - GENG106 - Lab Handbook Fall 2012 Semester Introduction to Visual C++ 2010 Express The main purpose of this tutorial is to introduce you to the computing environment you will be using in this course. The ideas in this lab will be used again and again throughout this course, so you should make every effort to understand not only what but why you are doing what you are doing at each step. An integrated development environment (IDE) is a software application that provides comprehensive facilities to programmers to ease software development. There are many IDE that can be used to write C++ programs. In this course, we are going to use Visual C++ 2010 Express to write C++ programs. This software can be downloaded for free from: http://www.microsoft.com/visualstudio/eng/downloads Creating C++ program in Visual C++ 2010 Express 1. After installing the software and to start the Visual C++ 2010 Express, from start >> all program >>Microsoft Visual C++ 2010 Express. A screen similar to the one in Figure 1 will be opened.

Upload: naeem-nasser

Post on 03-Dec-2015

214 views

Category:

Documents


1 download

DESCRIPTION

C++ lab

TRANSCRIPT

Page 1: GENG106-Lab01

1

Qatar University

College of Engineering

Dept. of Computer Science & Eng’g

Computer Programming -

GENG106 - Lab Handbook

Fall 2012 Semester

Introduction to Visual C++ 2010 Express

The main purpose of this tutorial is to introduce you to the computing environment you will be using in

this course. The ideas in this lab will be used again and again throughout this course, so you should

make every effort to understand not only what but why you are doing what you are doing at each step. An integrated development environment (IDE) is a software application that provides

comprehensive facilities to programmers to ease software development. There are many IDE that

can be used to write C++ programs.

In this course, we are going to use Visual C++ 2010 Express to write C++ programs. This software

can be downloaded for free from: http://www.microsoft.com/visualstudio/eng/downloads

Creating C++ program in Visual C++ 2010 Express

1. After installing the software and to start the Visual C++ 2010 Express, from start >> all program

>>Microsoft Visual C++ 2010 Express. A screen similar to the one in Figure 1 will be opened.

Figure 1

Page 2: GENG106-Lab01

2

2. To create a new program, you should first create a new project as following: From File menu select

New Project , a new window will be opened like Figure 2

On the left pane, select Win32

On the middle pane select Win32

Console Application

You need to give this project a

name. Let’s name it

“FirstProject”

Also remember where you save

this project

You can choose to create or not

to create a folder for your

solution

3. Press OK button, a new window will be displayed as shown in Figure 3.

Figure 2

Figure 3

Page 3: GENG106-Lab01

3

4. Press Next button, a new window will be opened as showin Figure 4

Just make sure that “Empty

project” is checked

5. Press Finish button. Go to the "Solution Explorer" on the left side and right-click on "FirstProject"

but be sure not to right click on "Solution FirstProject(1 project)." Once you have right clicked on

FirstProject select "Add New Item"

6. In the Box that appears, on the

left pane select "Visual C++"

7. On the middle pane choose

"C++ file (.cpp)"

8. Change the name to

FirstProgram (as shown). Press

"OK".

Figure 4

Figure 5

Page 4: GENG106-Lab01

4

A blank screen will appear showing the contents of "FirstProgram.cpp" (as shown in Figure 6)

9. Now inside the blank screen write the following

#include <iostream>

using namespace std;

void main()

{

cout<<"Welcome to C++";

}

10. Compile your program:

On the Debug menu (refer to Figure 7 below), click Build Solution or press F7.

Remember that the compiler is your helping friend because it tells you what and where you made

mistakes. Always start correcting the very first error listed by the compiler. Why?

Figure 6

Page 5: GENG106-Lab01

5

Figure 7

11. The Output window (at the bottom of your program in Figure 7), displays information about the

compilation progress, such as the errors, location of the build log and a message that indicates the

build status.

To fix compilation errors refer to the next section in this Lab. When all errors are fixed proceed to

the next step to execute/run your program.

12. To run the program, press CTRL+F5. The output screen, in Figure 8 below, will be displayed.

Figure 8

Note: In each project, you should only have one program that has the main function. Therefore, to

write a new program you have to create a new project or just update the previous one.

Debug

Build

Solution

Output Window

Page 6: GENG106-Lab01

6

13. Modify the program by adding << endl to the 5th

line as shown below:

cout<<"Welcome to C++"<< endl;

Compile (press F7) and run the program again (press CTRL+F5).

What is the change in the output? ___________________________________________________

How to Fix Compilation Errors

1. If you didn’t get any compilation errors, you need to simulate an error by deleting the semicolon in

line 5 of your program above so that it reads (refer to Figure 9):

cout<<"Welcome to C++" << endl

Note: To display line numbers in your editor click Tools Options Text Editor C/C++

General tick Line Numbers in the Display section.

2. On the Debug menu, click Build Solution or Press F7

3. A message in the Output window (refer to Figure 9) states that building the project failed.

Click on the Error List button in the status bar area to see the error(s) in your program, as indicated

in Figure 9.

Note: If the Error List tab is not visible, click View Other Windows Error List.

Figure 9

Go To Next

Message

Error List

Page 7: GENG106-Lab01

7

4. An alternative way to see the errors, click on the Go To Next Message button (the green, right-

pointing arrow) in the Output window in Figure 9.

5. To view more help information about an error, highlight the error and press the F1 key.

6. Correct the error by adding the semicolon back to the end of the line:

cout<<"Welcome to C++"<< endl;

7. Compile again: on the Debug menu, click Build Solution or press F7

8. A message in the Output window indicates that the project compiled correctly.

Write your first C++ program:

Write myself.cpp - a program that produces output describing yourself, such as:

Name: Ali Mousa

Gender: Male

Year: Year 1

Phone: 5751 566

Hobbies: Swimming and programming

Quote: "We learn to swim by swimming and we learn to program by programming!"