KEAN UNIVERSITY

46
KEAN UNIVERSITY Visual C++ Dr. K. Shahrabi

description

Visual C++ Dr. K. Shahrabi. KEAN UNIVERSITY. Developer studio. Is a self-contain environment for creating, compiling, linking and testing windows program. Developer studio incorporate a range of fully integrated tools designed to make the whole process of writing windows programs easy. - PowerPoint PPT Presentation

Transcript of KEAN UNIVERSITY

Page 1: KEAN UNIVERSITY

KEAN UNIVERSITY

Visual C++

Dr. K. Shahrabi

Page 2: KEAN UNIVERSITY

Developer studio

• Is a self-contain environment for creating, compiling, linking and testing windows program.

• Developer studio incorporate a range of fully integrated tools designed to make the whole process of writing windows programs easy.

Page 3: KEAN UNIVERSITY

System Components

• Editor

• Compiler

• Linker

• Libraries

• AppWizard

• ClassWizard

Page 4: KEAN UNIVERSITY

Editor

• Provides an interactive environment for creating and editing C++ source code.– Cut– Paste– Color cues to differentiate between various

language elements

• The editor automatically recognize fundamental words in the C++ and assigns a color to them according to what they are.

Page 5: KEAN UNIVERSITY

Compiler

• Converts the source code into machine language.

• Detects and reports error in the compilation process.– Invalid program code.– Unrecognized program code.– Structural errors

• part of program can never be executed

Page 6: KEAN UNIVERSITY

Compiler Output

• Output from the compiler is known as object code.

• Output is stored in a file called object file, which usually have name with extension .obj

Page 7: KEAN UNIVERSITY

Linker

• Linker combines the various modules generated by the compiler from source code file.

• Adds required code modules from program libraries supplied as part of C++, and welds everything into an executable whole.

• It can detect and report errors.– Missing part of program– Non-existent libraries

Page 8: KEAN UNIVERSITY

Libraries

• Support and extends the C++ language by providing routines to carry out operations which are not part of the language.– Calculating square root– Calculating sine

Page 9: KEAN UNIVERSITY

Types of Libraries

• Standard library

• Microsoft Foundation Class (MFC) library

Page 10: KEAN UNIVERSITY

Standard library

• Contains routines that are not platform specific.

• Common to all C++ compilers.

• The extension to standard set are not universal.

Page 11: KEAN UNIVERSITY

MFC Library

• A set of structured components that provides the basis for all the windows program.

• MFC is referred to as an application framework

Page 12: KEAN UNIVERSITY

AppWizard

• AppWizard automatically generates a basic framework for windows program.

Page 13: KEAN UNIVERSITY

ClassWizard

• Provides an easy mean of extending the classes generated by AppWizard as part of your basic windows program.

• It help to add new classes, based on classes in the MFC, to support the functionality you want to include in your program.

Page 14: KEAN UNIVERSITY

Project

• A program of some kind.

• A console program.– A program that have none of the baggage

required for windows program (character-based DOS).

Page 15: KEAN UNIVERSITY

Project Workspace

• A folder in which all the information relating to a project is stored.

• When you create a project, a project workspace is generated automatically .

• Developer Studio will maintain all of the source code and other files in the project workspace.

Page 16: KEAN UNIVERSITY

Project Workspace

• Contain other folders to store the output from compiling and linking the project.

• Further project can be added to the same project workspace (subprojects).

• Any project can be a subproject of another (not recommended)

Page 17: KEAN UNIVERSITY

Defining a Project

• Project name.

• List of all the source files.

• Definition of what sort of program is to be built from the source files.– .exe program– console program

Page 18: KEAN UNIVERSITY

Defining a Project

• Option set for the editor, the compiler, the linker and other components of Visual C++.

• Windows to be displayed in Developer Studio when the project is opened.

Page 19: KEAN UNIVERSITY

Defining a Project

• Project are stored in a file with the extension .dsp or .mak.

Page 20: KEAN UNIVERSITY

Files Type

• .dsp or .mak• .opt• .dsw• .exe• .obj• .ilk• .pch• .pdb

Page 21: KEAN UNIVERSITY

Files Type

• .dsp or .mak– Contains information about how your program

is to be created from the files in the project workspace and is produced when you create project workspace.

• .opt– Contains setting for the project workspace.

Page 22: KEAN UNIVERSITY

Files Type

• .dsw– Is used to store further information about the

workspace, such as what project it contains.

• .exe– Is the executable file for program. This file can

be obtained if both compile and link steps are successful.

Page 23: KEAN UNIVERSITY

Files Type

• .obj– Object file and it is created by compiler. This

file containing machine code from your program source files.

– These are used by linker, along with files from the libraries, to produce your .exe file

Page 24: KEAN UNIVERSITY

Files Type

• .ilk– It enable the linker to incrementally link the

object files produced from modified source code into the existing .exe file

• .pch– pre-compiled header

Page 25: KEAN UNIVERSITY

Files Type

• .pdb– This file contains debugging information that is

used when you execute a program in debug mode

Page 26: KEAN UNIVERSITY

Step one

• First step in writing a Visual C++ program is to create a project.– Select File from the main menu option– Select New from the File menu option– Select project– Define project type– File name

Page 27: KEAN UNIVERSITY

Step two

• Select File from main menu option

• Select New from File menu option

• Select C++ source code

• Start typing your program

Page 28: KEAN UNIVERSITY

Step Three

• Select File from main menu option

• Select save from File menu option

• Type a file name

Page 29: KEAN UNIVERSITY

Step Four

• Click right mouse key

• Select Add to Project

Page 30: KEAN UNIVERSITY

Step Five

• Click Build Button from main menu

• Run your program

Page 31: KEAN UNIVERSITY

Program

• Type the following program

# include <iostream.h>

int main(void)

{

cout <<“any text”

<<endl

<<“any text”

<<endl<<endl;

return 0;

}

Page 32: KEAN UNIVERSITY

Project Folder

• Look in project folder for subfolder called Debug.

• This folder must contains the output of the build that you did.

Page 33: KEAN UNIVERSITY

Project Folder

• Click Start

• Click Programs

• Click Windows Explorer

• Select Program Files

• Select DevStudio

• Select MyProjects

• Select Project Name

• Select Debug

Page 34: KEAN UNIVERSITY

Project Folder

• This folder must contain the following:

*.exe

*.ilk

*.obj

*.pch

*.pdb

vc50.idb

vc50.pdb

Page 35: KEAN UNIVERSITY

Executing Program

• There are different ways for executing a program.

1. From Explorer

2. From C++ development environment

a. From main menu

b. From toolbar

Page 36: KEAN UNIVERSITY

Executing Program

• Double-click the .exe file from Explorer.

OR

• Select Build from main menu

• Select Execute ‘file name’.exe from Build menu.

OR

• Click on toolbar button for this menu item (!).

Page 37: KEAN UNIVERSITY

Structure of a C++ Program

• One or more functions. A function is a self-contained block of code with a unique name.

main( )

Page 38: KEAN UNIVERSITY

Structure of a C++ Program

Execution start with

main ( )

int main ( )

{

input_name ( );

sort_name ( );

output_name ( );

return 0;

}

void input_name ( ){

//…return ;

}

void sort_name ( ){

//…return ;

}

void output_name ( ){

//…return ;

} Goes back to operating system

Page 39: KEAN UNIVERSITY

Structure of a C++ Program

• // comment

• # compiler look for first

• include compiler will add to main

• iostream.h header file

• int integer

• endl end line & start on new line

• cout send to display

Page 40: KEAN UNIVERSITY

Example1

• Add to integer variables and display the result.//example1

#include <iostream.h>

int main()

{

int A, B, C; //Declare integer variables

A=10; B=20; //Set initial values

C=A+B; //Add A and B

cout <<endl; //Start a new line

cout <<"A+B=" <<C; //Display

cout <<endl<<endl;

return 0;

}

Page 41: KEAN UNIVERSITY

Example 2

//example2

#include <iostream.h>

int Add (int x, int y)

{

return (x+y);

}

main()

{

int a, b, c; //Declare integer variables

cout << "Enter two numbers:"<<endl;

cout <<"a=";

cin >> a; //Enter a value for a

cout<<"b=";

cin >> b; //Enter a value for b

c=Add(a,b); //Call Add ( )

cout <<endl; //Start a new line

cout <<"a+b=" <<c; //Display

cout <<endl<<endl;

return 0;

}

Page 42: KEAN UNIVERSITY

Example3

//example3

#include <iostream.h>

int Add (int x, int y)

{

return (x+y);

}

int Sub (int x, int y)

{

return (x-y);

}

main()

{

int a, b, c, d; //Declare integer variables

cout << "Enter two numbers:"<<endl;

cout <<"a=";

cin >> a; //Enter a value for a

cout<<"b=";

cin >> b; //Enter a value for b

c=Sub(a,b); //Call Sub ( )

d=Add(a,b); //Call Add ( )

cout <<endl; //Start a new line

cout <<"a-b=" <<c; //Display

cout <<endl;

cout <<"a+b=" <<d; //Display

cout <<endl<<endl;

return 0;

}

Page 43: KEAN UNIVERSITY

Variable Type

• unsigned short int 2 bytes 0 to 65535• short int 2 bytes -32768 to 32768• unsigned long int 4 bytes 0 to 4294967295• long int 4 bytes -2147483648 to

2147483647• int 2 bytes -32768 to 32768• unsigned int 2 bytes 0 to 65535

Page 44: KEAN UNIVERSITY

Variable Type

• Char 1 byte 256 character

• float 4 bytes 1.2 e-38 to 3.4 e38

• double 8 bytes 2.2 e-308 to 1.8 e308

Page 45: KEAN UNIVERSITY

Keywords

• C++ reserved words (keywords). Keywords can not be used as name in program.

asm, auto, bool, break, case, catch, char, class, const, const_cast, continue, default, delete, do, double, dynamic_cast, else, enum, explicit, export, extern, false, float, for, friend, goto, if, inline, int, long, mutable, namespace, new, operator, private, protected, public, register, reinterpret_cast, return, short, signed, sizeof

Page 46: KEAN UNIVERSITY

Keywords

static, static_cast, struct, switch, template, this, throw, true, try, typedef, typeid, union, unsigned, using, virtual, void, volatile, wchar_t, while,