42
CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which is quite similar to 2010)

CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Embed Size (px)

Citation preview

Page 1: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

CS2311 - Tutorial 1

Getting Started with Visual Studio 2012(Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which is quite similar to 2010)

Page 2: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Outline• Introduction and installation of Visual studio (VS)• Writing, compiling, and executing C++ programs using VS

Page 3: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Working Environment

• In this course, you will be working with PC under Windows 7 or 8, and all the programs will be written with Visual Studio 2012.

• In this tutorial, you will explore and get familiar with the MS Visual Studio 2012 compiler working environment.

• Visual Studio 2012 is an integrated developing environment (IDE). Inside the Visual Studio 2012 compiler, you can edit, compile, link, run, debug and manage your programming projects.

Page 4: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Setting up Visual Studio Environment (In CSC Labs)• Locate Microsoft Visual Studio 2012 from the WorkDesk icon

on Desktop.• Visual Studio 2012 professional and Visual Studio 2012

professional ultimate are similar IDE and both of them can be used in this course

Page 5: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Outline • Introduction and installation of Visual studio (VS)• Writing, compiling, and executing C programs using VS

Page 6: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Steps for writing, compiling and running c programs 1. Create a project and project folder2. Create a folder for storing programs (source code)3. Add the source code to project4. Compile and run the program

Page 7: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Create the project

1. Select File2. Mouse over New3. Click Project…

Page 8: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Create a C++ Console Project

2: Select Win32 Console Application1: Select Visual C++

4: type a folder name, e.g. tut1

4: uncheck “Create directory for solution”

6: click OK

3: Select the folder where you want the project saved e.g. c:\user\<your login ame>\documents\Visual Studio 2010\Projects

Page 9: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Customize the project setting

click Application Setting

Page 10: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Customize the project setting

1: check Empty project

2: click Finish

Page 11: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Add a C++ program file into the project1. Right click Source Files2. Mouse over Add3. Click New Item…

Page 12: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Add a C++ program file into the project

1: select C++ File(.cpp)

3: click Add

2: enter a file name, e.g. tut1

Page 13: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Writing code

The cpp file just created

The area for typing project

code

Page 14: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Writing code

Type the Hello World program

Page 15: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Build (Compile) your program [F7]

click Build Solution

Page 16: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Build your program

If the program can be built successfully, you will see 1 succeeded here

Page 17: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Execute your program [Ctrl+F5]

click Start without Debugging…

Page 18: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Result of Execution

Page 19: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Try it out!

Comment this line

Page 20: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Rebuild the project [Ctrl+Alt+F7]

This time, click Rebuild Solution because the project has been built before

Page 21: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Got an error message

0 succeeded, 1 failed means the program has problem! No executable is made

Page 22: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

If you try to execute it anyway..

Page 23: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

You will get an error message

Page 24: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

And will not have an expected result

Page 25: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

A better way: Locate the error

Double click the error message

A maker will be placed beside the line that makes program failed to build

Page 26: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Fixed the error

Add std:: before cout, it tells the compiler the cout object is defined in std namespace

Page 27: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Rebuild the project: Fixed!

It is success this time!

Page 28: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Copy your project out

Locate your project (the path may be different if you choice different path in project creation

Copy the whole folder into your USB or elsewhere

Page 29: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Reload your project

Close it first!

Page 30: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

VS without project loaded

Click File >> Open

Page 31: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Locate and select your project

1. Select tut1.sln from the project folder you copy before

Click Open

Page 32: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Your project is loaded

Page 33: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Work on other program with the same project• Within the same project, we can only have one “main”

function. If you want to add another program file with function main, exclude the existing one first!

Page 34: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Schedule• Introduction and installation of Visual studio (VS)• Writing, compiling, and executing C programs using VS

Page 35: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

What you have done in this Tutorial

• Create a Visual Studio 2012 Project• Create and add a C program into the

project•Write a simple Hello World Program• Build and Execute the program• Locate the syntax error of a program

Page 36: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Downloading a Visual C++ 2012 compilers (try it yourself at home)

• Visual Studio 2012 can be found at: http://msdnaa.cs.cityu.edu.hk/

• Login using your student ID as login name and password.

• Click "MSDNAA Software Center"• Select Visual Studio 2012 Professional Edition• Add the following items to the shopping cart• Visual Studio 2010 Professional Edition DVD

• Download and run the executable files. • Burn the iso files to DVDs (or using software to

mount the DVD image). • Click setup to install.

Page 37: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

You have to ….Trust us

Click this

Page 38: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Enter your CS lab account (Check the email sent by CS Lab first)

Page 39: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Enter the MSDNAA Software Center

Click this

Page 40: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Select Visual Studio 2012

Select Visual Studio 2012

1. Select Developer Tools

Page 41: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Download the Ultimate Version

Select Visual Studio 2012 Ultimate

Page 42: CS2311 - Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which

Add VS2012 to shopping cart

Click Add to Cart and then check-out