Home

Visual C++ 6.0 Tutorial

image

Contents

1. 12 hour 12 lt lt 3 lt lt minute lt 10 0 lt lt minute lt lt lt lt second lt 10 O lt lt second lt lt hour lt 12 AM PM File 3 Example2 cpp main function the driver Driver for Time class include lt iostream gt using std cout using std endl include time h Driver to test class Time int main Time t instantiate object t of class time cout lt lt The initial military time is t printMilitary cout lt lt nThe initial standard time is t printStandard t setTime 13 27 6 cout lt lt n nMilitary time after setTime is t printMilitary cout lt lt nStandard time after setTime is t printStandard t setTime 99 99 99 attempt invalid settings cout lt lt n nAfter attempting invalid settings n lt lt Military time printMilitary ut lt lt nStandard time t printStandard u t lt lt endl urn 0 26
2. File name Examplet cppl 4 m ClassView FileView Files oftype C Files c cpp coc tli h tlh ink rc Cancel x Files will be inserted into folder titled Source Files in project Hello World 4 Lae Build Ready Find in Files 1 Find in Files2 10 11 Step 6c Right click the button on the left of the Source Files folder to show the inserted examplel cpp file Double click the presently empty Example cpp file a Microsoft Visual C dialog box is displayed asking if you want to create a new file Examplel cpp Click on Yes to display the editing window Ges Workspace Hello World 1 project s Hello World files Source Files Examplet Header Files Resource Files Microsoft Visual C Project file D Hello World Example1 does not exist Do you want to create a new file Je Ready Astr AIAMO DD BS BW Removable Disk 0 fH Progam Developme op Hello World Mi Bm BL BajO B 11 28PM 11 12 Step 6d An empty editing window appears to the right waiting for you to enter the source code for the Example1 cpp file Hello World Microsoft Visual C Example1 fey Workspace Hello World 1 project s a Hello World files B Ma i gt 12 13 Step 7 Enter the C C source code for Example cpp file in the editing window as shown After the code is entered you are ready to compile
3. Edit View Insert Project Build Tools Window Help Gigs Workspace Time 1 project s EF Time files 3 Source Files A Example2 cpp Header Files ElTimet h Resource Files Time h Declaration of the Time class Member functions are defined in timel cpp Tine cpp Member function definitions for Time class include lt iostream gt using std cout t printMilitary cout lt lt NnThe initial standard time is t printStandard t setTime 13 27 6 cout lt lt Nn nMilitary time after setTime is t printMilitary cout lt lt nStandard time after setTime is t printStandard t setTime 99 99 99 77 attempt invalid settings cout lt lt NnNndfter attempting invalid settings n lt lt Military time t printMilitary cout lt lt NnStandard time t printStandard cout lt lt endl return 0 Ready ln 22 Col22 REC COL OVA READ Astrt A 3 Am O J9 m EB laMa Tm foo Time E Progam BB omy SOR 1 20PM 23 24 Step 8 We are now ready to compile link and execute the project You may do each of these phases separately as we did in Example 1 or you can consolidate all three phases into one step by clicking on the Execute Program icon an exclamation mark in the tool bar The system displays a dialog box The file does not exist Time exe Do you want to build it click Yes If there is no error as is
4. Time Program File 1 Time h Time class header file Member functions are defined in time cpp prevent multiple inclusions of header file ifndef TIME1_H define TIME1 H Time abstract data type definition class Time public Time constructor void setTime int int int set hour minute second void printMilitary print military time format void printStandard print standard time format private int hour Pi OS 23 int minute 0 59 int second 0 59 ke endif File 2 Time cpp Implementation file for Time h Member function definitions for Time class include lt iostream gt using std cout include time h Time constructor initializes each data member to zero Time Time hour minute second 0 Set a new Time value using military time Perform validity checks on the data values Set invalid values to zero void Time setTime int h int m int s hour h gt 0 amp amp h lt 24 h 0 minute m gt 0 amp amp m lt 60 m 0 second s gt 0 amp amp s lt 60 s 0 25 25 Print Time in military format void Time printMilitary Cout lt lt hour LLOP FOT e MNE eee Hour lt lt Mee lt lt minute lt 10 0 lt lt minute Print time in standard format void Time printStandard cout lt lt hour hour 12
5. and or execute your program Hello World Microsoft Visual C Example1 cpp le ja sae welo c mmg Ll es ee ooo o AE include lt iostream h gt E Workspace Hello World 1 project s int main B E Hello World files cout lt lt Hello World return 0 E Resource Files a Ha la lx 13 14 Step 8a In order to execute your program it is necessary to go through three steps compile link load and execute Normally these steps performed separately especially when you have a large project that involves multiple files and you want to compile and debug each file separately For simple projects such as most assignments in CS230 you may want to use the one click operation that consolidates all four steps together automatically by simply clicking the Execute Program icon a red exclamation symbol in the tool bar as shown below Click on it and then click on Yes in the dialog box If there is no warning or error in your project the system displays the output window shown in step 8d the output window has a black background which displays the result of the execution If there are warnings and errors the system displays the diagnostic messages in the message window at the bottom of the screen Note that you may choose to skip steps 8b and 8c which show how compile link load and execute steps are performed separately Hello W
6. cpp Time cpp and Time h are already in the Time folder the system does not recognize them as files that should be included in the project as reflected by the fact that both the Source Files and the Header Files folders are empty We must add these files to appropriate folder to associate them with the Time project Go through Steps 3 4 and 5 as you did in the previous example Time Microsoft Visual C File Edit View Insert Project Build Tools Window Help j ict xmeio c lomeia dl Globals All global members I No members Create New Class Gigs Workspace Time 1 project s Time fi s Resource Files all Ready Asun AIAMO J9 mE BY laMa Grime foo Time Proatam Smal GOapR 1 09PM 21 22 Step 6 Right click on the Source Files folder and add Time cpp and Example2 cpp source files to the folder Add Time h to the Header Files folder Expand the Source Files and Header Files folders to display their contents as shown below Microsoft Visual C Globals Gigs Workspace Time 1 project s a g Time files Source Files Example2 cpp e c E Timet h Resource Files 22 23 Step 7 Double clicking on the file name of each of these files opens the file in the edit windows Note that three files are arranged in cascade You may want to tile them vertically or horizontally with the Window menu in the menu bar Time Microsoft Visual C File
7. s TENN suits Debug Find in Files 1 Find in Files2 Results 7 Nel of Ready Ln6 Col2 REC COL OVR READ FE Start JLab Coach House JRemovable Disk Hello World Mi Microsoft Visual Gi E Hello Worl PEX Qo aR 1 29 AM 18 19 Step 9b The selected part of the screen contains the entire output as shown below with white background which can be pasted to any text editor such as MS notepad or Word for printing Note that you may also select part of the output for printing by selecting Mark then select the part of the output by dragging the pointer across it we p 18 x E File Edit View Insert Project Build Tools Window Help 6 x alsa mel 2 e mee wf d aii include lt iostream h gt int main i Workspace Hello Worle 5 E8 Hello World files 4 Source Files L Example1 cpp G Header Files G Resource Files cout lt lt Hello World lt lt endl return 0 Select E Hello World Debug Hello World exe Hello World 4 ma ClassView E FileView Examplel cpp Linking Hello World exe 0 error s 0 warning s CTE Build Debug Find in Files 1 Find in Files2 Results 7 at of Ready Ln 6 Col 2 RE OL OVR REA FE Start JLab Coach House Removable Disk Hello World Mi 2 Microsoft visual E Select E Hell Sd Qo SBS 1 35AM 19 20 Some Observations of the Hello World Example The project name you h
8. the case here the system displays the output result in a Time name of the project window as shown below Ele Time Microsoft Visual C Eile Edit View Insert Project Build Tools Window Help jals ag ae 2 lt Basa Fa fiGiobatsy zjjn global members z main JA 7 SAS ao easels Time files iol x 2 8 Source Files Auto z 4 Example re military time i 2 Time cp pte e OCC rm et aa Meade Files Military time Z Time h Qa ee Resource Fi cout lt lt nThe initial standard time is t printStandard t setTime 13 27 6 cout lt lt NnN nMilitary time after setTime is oem r t tMi litare ma ClassView FileView nrintMi litary Epee Configuration Time Win32 Debug W Compiling Tine cpp Example2 cpp Linking Time exe 0 error s 0 warning s Build Debug FindinFiles 1 FindinFiles Rezus Tal 4 Ba in19 Colt REC COL OVA READ Ason A 3 A m O ID m EZ Slam Pro time che o Time Tm OOA 1 50PM Step 9 To print the source code and the output by following the same procedure as described in Step 11 of the previous example 24 Appendix The Source Code Single file Demo The Hello World Program File name Hello World cpp include lt iostream h gt int main cout lt lt Hello World lt lt endl return 0 Multiple file Demo the
9. WPUNJ Department of Computer Science MS Visual C 6 0 Student User Manual Table of Contents Page No Introduction 00 20 2 22000000222200000 2 How to Launch Visual C 6 0 3 How Start a New Project 4 How to Enter or Add Source Files to a Project 7 How to Execute a Project or Program 14 How to Print the Source Code and Output 18 Some Observations 00 2 20 Multiple File Demo 21 Program Development with Microsoft Visual C C 6 0 Introduction This short manual is created mainly for the beginning students in CS230 Computer Science I It introduces the Integrated Development Environment IDE of Microsoft Visual C 6 0 and shows how a C program is developed in such an environment Two simple programs are chosen to allow students to focus on the detailed steps of how to enter compile and execute a C C program rather than on the programs themselves The first is the well known Hello World single file program single file in the sense that the source code entered by the user is contained in a single file with a cpp file extension The program prints literally the Hello W
10. ave entered in Step 2 causes the system to create a folder of the same name Although it is possible to store your files in different drives and folders it is strongly advisable that you centrally store all your files in this folder for ease of access If such a folder is already there the system will use the existing one for the project An empty single source file named Examplel cpp was first added to the Source Files folder and its code subsequently entered In a multiple file project the above process may be repeated to add any number of additional source files to the Source Files folder Similarly any number of user defined header files h file extension may be added to the Header Files folder Note that both the Source Files and Header files folders are sub directories or sub folders in the project folder Also note that it is not necessary to use the editor provided by Visual C to enter code into files any ASCII editors will do It is possible to store physically all the cpp and h files in different folders and drives for multiple file example These files may have been created earlier and are reused in other project However all the files that are to be used by a project or program must be added or associated to the project In our second example we assume all files two source files Example2 cpp and Time cpp and a Time h header file have already been created and stored in a folder named Time on the D drive After you hav
11. dy to add our empty Examplel cpp filename is arbitrarily chosen source file to the Source Files folder and then enter C code into this file Hello World Microsoft Visual C File Edit View Insert Project Build Tools Window Help jals nai eal Hla Globals Ejj All global members No members Create New Class Hes Workspace Hello World 1 project s Hello World files E E Header Files E Resource Files eady Ast A 3 A m O DD BS BW Removable Disk 0 E Program Developme op Hello Word Mi BD LAESA 11 14PM Step 6a Right click on the Source File folder and select Add Files to Folder in the popup menu Example1 Microsoft Visual C je x i All global members A No members Create New Class 10 Step 6b In the File name box of the Insert Files into Project dialog box enter the filename of your choice Examplel cpp in this case Note that it is essential to enter the file extension cpp Click on the OK button to add the Example1 cpp file to the Source Files folder of the project Hello World Microsoft Visual C Ble Edit view Insert Project Build Tools window Help cO smelo c ame el a Cias fgos members JelfNo members Create New Class je gt ae Workspace Hello Worle 3 Ef Hello World files Header Files Resource Files Insert Files into Project Look in S Helo World gt cf Ev Debug
12. e successfully executed the program the project folder contains more than 10 files including many intermediate files created by the system to build your project These files occupy more than 1 MB of the storage space even for the simply Hello World program with a few line of source code For larger projects a single floppy disk may not capacity to store the entire project 20 21 A Multiple File Project The Time Program In this demonstration the project or program that prints a given time of the day in both military as well as standard time formats the project contains three files created by the programmer two source files Example2 cpp and Time cpp and a header file Time h We assume that these files have already been created you may use any ASCII editor and stored in a project folder named Time on the D drive Based on Observation 2 above we will name our multiple file project Time and use this same Time folder to store all the files Step 1 Same as previous example launch MS Visual C C 6 0 from task bar Step 2 Same as previous example click on File in the menu bar then click on New Click on the Projects tab then select Win32 Console Application In the Location box select the disk drive the D drive in this case and in the Project box enter project name Time in this case The Time folder is already there will be used by the system to store all the files for the Time project Although all three files Example2
13. hat is displayed below Microsoft Visual C BEE File Edit View Insert Project Build Tools Window Help jals a PEE omasa O da Ready Mstart A 3 A m O NO IO m E BW Lab Manual Froject 8 Program Developme op Microsoft Visual Am RAEO aosem Note Hereafter all system defined terms including menu items such as File will appear in bold and all entries made by programmers such as a file name are in italicized 4 Step 2 In the Menu bar click on File then click on New In the New dialog box shown below click on the Projects tab then select Win32 Console Application In the Location box select the disk drive e g the D drive in this demo that you will use to store your project In the Project name box enter project name of your choice e g Hello World is chosen for this demo A folder named Hello World will be created on the disk in the drive you have chosen the D drive in this example This folder will be used by the system to store all files that are associated with the Hello World project Click on the OK button eee Hello World D Hello World E Hea ISAPI Extension Wizard Makefile RE MFC ActiveX Controlwizard o MFC AppWizard dll O Adah sata MFC AppWizard exe Ti Utility Project LA Win32 Application Win32 Dynamic Link Library S Win32 Static Library LK Cancel OBL Bt GajOR 5 Step 3a The system displays the window shown below Click on the Fini
14. orld string The second is a multiple file program where the source code consists of two cpp files and a user defined header file with a h file extension The program displays a given time of the day in both standard hour ranges between 1 and 12 with AM and PM to distinguish morning and afternoon and military format hour ranges between 0 and 23 For your convenience we list the source code for both programs in the Appendix It is noted that in MS Visual C C 6 0 a program is referred to as a project and we use these terms interchangeably in this document As we will see in the following examples a project is actually a directory or folder that contains several sub directories or sub folders used to store various files belonging to the project including those entered by the programmer and intermediate files created by the system For example all the cpp files are stored in Source Files sub folder and all the user defined h files are stored in the Header Files sub folder The basic operations introduced in these manual will certainly make it easier for you to explore and learn more advanced features of the MS Visual C IDE Your feedback is important to us to continually improve this menu Please forward your comments and suggestions by email to Dr E Hu at hue wpunj edu Single file Project The Hello World Program Step 1 Launch the MS Visual C C 6 0 software from task bar The main window of MS Visual 6 0 should be similar to w
15. orld Microsoft Visual C Example _ SS l6 x le File Edit View Insert Project Build Tools Window Help 6 x jaleO s mee a2 c Ree a lls Gowa SS Alrgiobalmembers zomin z Ry ey alzi include lt iostream h gt i Workspace Hello Worle int main 5 68 Hello World files Source Files Example cpp Header Files G Resource Files cout lt lt Hello World lt lt endl return 0 Microsoft Visual C 7 xi P E Hello World Debug Hello World exe This file does not exist Do you want to build it Pe ma ClassView Z FileView zj E X Build Debug Find in Files 1 Find in Files2 Results m rf E Hello World Example1 cpp saved Ln6 Col2 REC COL OVR READ Astart JLab Coach House Removable Disk fo Hello World Micr Microsoft Visual C AR ETRA 1 22 AM 14 15 Step 8b In the menu bar click on Build and then click on Compile Examplel cpp Alternatively you may click on the Compile icon on the Build MiniBar tool bar these icons are next to the exclamation symbol move the cursor over them and use the tool tips to find out what each of these icons is supposed to do Hello World Microsoft Visual C Example1 cpp Compile Examplel cpp Ctrl F7 Ooo O E3 Hello World files Source Files Hello World Header Files Resource Files 15 16 Step 8c As a res
16. rror s 0 warning s 5 Build Findin Files 1 FindinFiles2 J gt fa ins Col 35 ToL o a 2 3 um oo naa OBES Helo word M Program Dev Hello World i Hetto World Bm Bd ajo B 12024M 17 18 Step 9a To print the source code in the editing window is straightforward click anywhere in the source code to activate the editing window Click on File and then select Print in the pull down menu Since there is no print menu associated with the output window to print the output requires some cut and paste Activate the output window by clicking anywhere in the output window Click on the icon at the upper left corner of the title bar of the output window a pull down menu is displayed as shown below Click on Edit then choose Select All 18 x E Fie Edit View Insert Project Build Tools Window Help la x I sdg pela e ora n EE include lt iostream h gt i Workspace Hello Worle int main Hello World files cout lt lt Hello World lt lt endl 34 Source Files return 0 Examplel cpp E Header Files E Resource Files E Hello World Debug Hello World exe y to continue Minimize o Maximize X Close Defaults Gop Ente Properties n t Al t 5 ClassView ileView 4 Find x j Configuration Hello World Win32 Debug il Compiling Examplel cpp Linking Hello World exe 0 error s 0 warning
17. sh button in the Win32 Console Application dialog box P jals ua rele F Win32 Console Application Step 1 of 1 BEES Bol wd Gal ae Step 3b The system displays the New Project Information dialog box Click on the OK button Hello World Microsoft Visual C j mi x Ble Edit view Insert Project Build Tools window Help jals ma eee c mmen a a i alx New Project Information x Win32 Console A Win32 Console Application will create a new skeleton project with the following Teme E Eemer specifications Empty console application No files will be created or added to the project lee Project Directory E Hello World coe _ X KT Co Ready Astart Lab Coach House M Microsoft Visual C Removable Disk E fo Hello World Micr 4S 0 He 8H 12 49 4M 7 Step 4 On the left pane the system displays the ClassView folder Select the FileView folder by clicking on the FileView tab Hello World Microsoft Visual C 8 Step 5 The system now displays the FileView of the Hello World project on the left pane Click on the button to display three sub folders the Source files Header Files and Resource Files folders for the Hello World project as shown below Note that all three folders are empty because we have not yet add any files to these folders We are now rea
18. ult of the compilation the system displays the total numbers of errors and warnings in the message window at the bottom of the main window If there are warnings and or errors none in this compilation diagnostic messages are also displayed in the same window Note that the Build tab of the message window has been selected 18 x alsa i eela e ineea a JA Globe ZNA giobal members main Eah S al i include lt iostream h gt Rey Workspace Hello World 1 project s int main 4 Hello World files 4 Source Files cout lt lt Hello World return 0 Se Configuration Hello World Win32 Debug W Ccompiling Examplel cpp Examplel obj 0 error s 0 warning s 16 17 Step 8d To execute the program from the menu bar click on Build and then click on Execute Hello World exe in the pull down menu The results are displayed in the Hello World output window as shown on the right Hello World Microsoft Visual C Example1 cpp _ 15 x He File Edit View Insert Project Build Tools Window Help a x ala SHG amp B Qc En 8 hl Workspace Hello World 1 project s Hello World files Source Files E Header Files Hello World E Resource Files Auto X amp Ell ajs A Hello World Press any key to continue int main cout lt lt Hello World lt lt endl 4 ClassView FileView Hello World exe 0 e

Download Pdf Manuals

image

Related Search

Related Contents

Swisher LS67528S User's Manual  PLA GUICIDAS  Renesas Starter Kit for M16C/6C USB Sample Code User`s Manual  HUB USB 4 PORTS GH 215 GÛnÛCtIGÛA GUIDE D  HP EliteBook Revolve 810 G2  ADVANTAGE GPX 130  Installation Manual for Air Distribution Systems  カタログ(PDFファイル:1MB  Dy-Mark 39023522 Spray Lacquer Fluro Colours Aerosol  T4 Diagnostic System User Manual  

Copyright © All rights reserved.
Failed to retrieve file