Download
visual c dr k shahrabi n.
Skip this Video
Loading SlideShow in 5 Seconds..
KEAN UNIVERSITY PowerPoint Presentation
Download Presentation
KEAN UNIVERSITY

KEAN UNIVERSITY

86 Vues Download Presentation
Télécharger la présentation

KEAN UNIVERSITY

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

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

  2. 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.

  3. System Components • Editor • Compiler • Linker • Libraries • AppWizard • ClassWizard

  4. 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.

  5. 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

  6. 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

  7. 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

  8. 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

  9. Types of Libraries • Standard library • Microsoft Foundation Class (MFC) library

  10. Standard library • Contains routines that are not platform specific. • Common to all C++ compilers. • The extension to standard set are not universal.

  11. MFC Library • A set of structured components that provides the basis for all the windows program. • MFC is referred to as an application framework

  12. AppWizard • AppWizard automatically generates a basic framework for windows program.

  13. 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.

  14. Project • A program of some kind. • A console program. • A program that have none of the baggage required for windows program (character-based DOS).

  15. 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.

  16. 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)

  17. 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

  18. 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.

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

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

  21. 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.

  22. 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.

  23. 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

  24. 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

  25. Files Type • .pdb • This file contains debugging information that is used when you execute a program in debug mode

  26. 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

  27. Step two • Select File from main menu option • Select New from File menu option • Select C++ source code • Start typing your program

  28. Step Three • Select File from main menu option • Select save from File menu option • Type a file name

  29. Step Four • Click right mouse key • Select Add to Project

  30. Step Five • Click Build Button from main menu • Run your program

  31. Program • Type the following program # include <iostream.h> int main(void) { cout <<“any text” <<endl <<“any text” <<endl <<endl; return 0; }

  32. Project Folder • Look in project folder for subfolder called Debug. • This folder must contains the output of the build that you did.

  33. Project Folder • Click Start • Click Programs • Click Windows Explorer • Select Program Files • Select DevStudio • Select MyProjects • Select Project Name • Select Debug

  34. Project Folder • This folder must contain the following: *.exe *.ilk *.obj *.pch *.pdb vc50.idb vc50.pdb

  35. 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

  36. 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 (!).

  37. Structure of a C++ Program • One or more functions. A function is a self-contained block of code with a unique name. main( )

  38. Structure of a C++ Program void input_name ( ) { //… return ; } Execution start with main ( ) int main ( ) { input_name ( ); sort_name ( ); output_name ( ); return 0; } void sort_name ( ) { //… return ; } void output_name ( ) { //… return ; } Goes back to operating system

  39. 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

  40. 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; }

  41. 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; }

  42. 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; }

  43. 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

  44. 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

  45. 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

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