Title: Engineering 2420 Structured Programming
1Engineering 2420 Structured Programming
Cheng Li licheng_at_engr.mun.ca http//www.engr.mun.c
a/licheng/2420 EN-4012, 737-8972
Winter 2007
Lecture 4
2Build Process
- An editor is a specialized word processor used to
prepare source modules in the language of choice
(e.g. C, Java, Fortran, Basic) - The pre-compiler adds in standard pre-written
code (boilerplate) from include files you specify
to produce a complete source module. - The compiler produces object code for the target
computer/operating system. - The linker ties multiple modules together into a
complete program - An executable file is a program that will run on
the computer. The editor, pre-compiler, compiler
and linker are all executables. So is your
program!
3Integrated Development Environment (IDE)
- An IDE integrates all the tools you need to
prepare, debug, test and run a program. - Preparation of a program requires the following
basic steps - Edit your module to produce a source file
- Compile your module to produce an object file
- Link the object file with other object modules to
produce an executable file (a program). - Run the executable (your program).
- Debugger A program which allow you to run your
code interactively
4Getting Closer to Visual .Net (1)
- Step 1 Create a directory for the course (if you
are in the lab do it on your M drive). Call it
programming or 2420 or any other convenient name. - Step 2 Create a directory for your assignments,
something like Assigns. - Step 3 Now start up the Visual C program. (How
you do this will vary with your computer setup.
On most machines, go to the start menu, select
programs, then Microsoft Visual Studio .NET which
will give you another menu. Select Microsoft
Visual Studio .NET 2003 from that one as well.)
5Getting Closer to Visual .Net (2)
6Getting Closer to Visual .Net (3)
- Step 4 The Visual C design environment should
open. If the My Profile tab is not already
selected, click on it and set your profile as
shown next slide.
7Getting Closer to Visual .Net (4)
8Getting Closer to Visual .Net (5)
- Step 5 Now, to create your first project
- select the Projects tab.
- hit the New Project button (the New Project
Dialog Box will come up as shown below). - select the Visual C Projects under Project
Types. - select Empty Project (.NET) under Templates
- replace ltEnter Namegt with a name for your
project, say Assign0. - browse to the Assigns directory you created in
Step 2 (which should be on your M drive if you
are in our lab). - hit the OK button. You've just created your first
programming project!
9Getting Closer to Visual .Net (6)
10Getting Closer to Visual .Net (7)
- Step 6 So far, your project is empty. Typical
programming projects contain hundreds of files
but right now we'll just add one. - select the File Menu and when it drops down click
on Add New Item... (which will bring up the
dialog box shown in the picture below). - Categories should be Visual C
- replace ltEnter Namegt with a name for your file,
say assign0. - the directory should be set up correctly to the
project directory you created in Step 5. - hit the Open button.
11Getting Closer to Visual .Net (8)
12Getting Closer to Visual .Net (9)
- Step 7 Now you should have an empty file, all
ready to type your first program
1 include ltiostreamgt 2 using
namespace std 3 4 int main () 5
cout ltlt Hello World ! \n 6
return 0 7
13Getting Closer to Visual .Net (10)
14Getting Closer to Visual .Net (11)
- Type the program into the blank area provided.
- These box-bracket widgets are like paragraph
markers. They divide the code into logical blocks
and let you collapse the block if you want to
make your file more compact. - You can turn on the line number feature by
selecting - Tools -gt Options -gt C/C -gt General
- Tick Line Numbers box
- As shown next slide
15Getting Closer to Visual .Net (12)
1
2
3
16Getting Closer to Visual .Net (13)
- When done, now to build your program.
- Click on the Build menu and select Build Solution
(or making sure your cursor is in the code
window, just hit the F7 key). If all goes well
you should get the message - Build 1 succeeded, 0 failed, 0 skipped
- in the Output window below the code window.
- Run the program by clicking on the Debug menu and
select Start without Debugging (the shortcut key
is Ctrl-F5).
17Getting Closer to Visual .Net (14)
18Review What Have Been Done
- The Assigns directory is the directory in which
all the assignments will appear (and is a
subfolder of the Programming folder). Try to keep
things logically organized. - Visual C created the Assign0 directory. It was
done when we created our project name, Assign0. - We created the assign0.cpp file when we added it
to the project (step 6). - Everything else was created by Visual C. Notice
how big the Assign0.ncb file is. - Check the Debug directory. The Assign0.exe file
is the executable, the end result of your
programming.
19View Resulting Files
20Clean up
- Step 8 When you are done with an assignment, all
files except your source file(s) should be
erased. - Make sure you close the Visual C IDE first or
it may not let you erase some files.
21View Resulting Files
22Recreate a Project
- First, make sure you have your (in our example
Assign0.cpp) file and it is still in the Assign0
directory. - Then follow Steps 3 4 above except that in
Dialog Box for creating a new project (Step 4)
select the directory which contains your project
directory as the location (in this example the
Assigns directory) then enter the name of your
existing assignment directory as the project name
(e.g. Assign0). - Instead of Step 5 (creating a new file) click on
the File menu, select Open, and open your
existing file. Then right click on your opened
file and select Add to Project and voila! you're
back in business.