0% found this document useful (0 votes)
36 views22 pages

C++ Lect 3

The document discusses programming as problem solving and describes the process as having 4 main steps: 1) analyzing the problem, 2) designing the program, 3) coding the program, and 4) testing the program. It then provides examples of each step for the problem of Brewster wanting to invest money and calculate investment returns. The document also covers object-oriented programming languages and the typical process for creating, editing, compiling, linking, and executing a C++ program.

Uploaded by

Ashar Azeem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views22 pages

C++ Lect 3

The document discusses programming as problem solving and describes the process as having 4 main steps: 1) analyzing the problem, 2) designing the program, 3) coding the program, and 4) testing the program. It then provides examples of each step for the problem of Brewster wanting to invest money and calculate investment returns. The document also covers object-oriented programming languages and the typical process for creating, editing, compiling, linking, and executing a C++ program.

Uploaded by

Ashar Azeem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

Programming as Problem Solving

 Problem solving  Developing a Program:


principles: 1. Analyze the problem
1. Completely understand the 2. Design the program
problem 3. Code the program
2. Devise a plan to solve it 4. Test the program
3. Carry out the plan
4. Review the results

An example of programming as problem solving,


Brewster’s Thousands follows …

Ms Qurat-ul-Ann
1) Analyze the Problem
Brewster’s Thousands
The problem: Brewster wants to invest money at a local
bank. There are many options such as interest rates,
terms of deposit, compounding frequencies. He needs a
program to compute, for any given initial investment,
the final maturity (value) of the deposit.
 What are the inputs? (given data)
 What are the outputs? (required data)
 How will we calculate the required outputs from the given

inputs?

Ms Qurat-ul-Ann
2) Design the Program
Create an outline of the program
An algorithm – a step by step procedure that will
provide the required results from the given inputs.
Algorithm Examples: Instructions on how to make a
cake, use the bank’s ATM, etc.

Ms Qurat-ul-Ann
3) Code the Program
Once the design is completed, write the program
code.
Code is written in some programming language such
as BASIC, Pascal, C++, Java, etc.
In this course we write code in pseudo-code,
developing the skills to be used when studying the
specific languages.

Ms Qurat-ul-Ann
4) Testing the program
Locate any errors (bugs)
Testing is done throughout the development cycle
Desk-checking, or code walkthrough is
performed to locate errors in the code.
 Pretend you are the computer and execute your own code.

Ultimate test is to run the program to see if the


outputs are correct for the given inputs.

Ms Qurat-ul-Ann
Testing
Most of the work should be done before the phase
begins – creating of a testing document.
Two types of testing:
 Testing for errors
 Quality/Usability testing

Two phases of testing:


 Alpha testing (Internal testing)
 Beta testing (Testing at the customer site w/ live data)

Ms Qurat-ul-Ann
Documentation
Internal Documentation
Comments explain to the reader the logic and decision
processes of the programmer. Comments are ignored by
an interpreter or compiler.
Types of comments include code comments,
documentation comments & module comments.
External Documentation
External documentation includes a user’s guide and,
typically, a more technical system administrator’s guide.

Ms Qurat-ul-Ann
Object-Oriented Languages
Most object-oriented languages are high-level
languages.
The focus of OOP languages is not on structure, but
on modeling data.
Programmers code using “blueprints” of data models
called classes.
Examples of OOP languages include C++, Visual
Basic.NET and Java.

Ms Qurat-ul-Ann
Basics of a Typical C++ Environment Editor Disk
Program is created in
the editor and stored
on disk.

Phases of C++ Programs: Preprocessor Disk Preprocessor program


processes the code.

1. Edit Compiler
Compiler creates
object code and stores
Disk
2. Preprocess it on disk.
Linker links the object
3. Compile Linker Disk code with the libraries,
creates a.out and
4. Link Primary
Memory
stores it on disk
Loader
5. Load Loader puts program
6. Execute Disk ..
in memory.
..
..

Primary
Memory
CPU
  CPU takes each
instruction and
executes it, possibly
storing new data
..
.. values as the program
..
executes.
Ms Qurat-ul-Ann
Creating and Editing a C++ Program
 The Process of writing C++ program is known as editing. The process

includes writing, modifying and deleting program statements.


 The part of Turbo C++ IDE that is used to write
C++ programs is called Edit Window. A new edit window can be opened by
selecting File>New option from menu bar.
 The edit window appears as follows:

Ms Qurat-ul-Ann
Creating and Editing a C++ Program
 The edit window appears as follows:

Ms Qurat-ul-Ann
Creating and Editing a C++ Program
 The edit window has a doubled lined border. The courser blinks in the

window.
 The position of the cursor indicates the starting point to write a program.

The user can expand the window by clicking the arrow in the upper right
corner.
 The user can also select Window>Zoom to expand the window. The vertical

and horizontal scrollbars are used to navigate through the program.

Ms Qurat-ul-Ann
Saving a C++ Program
 The process of storing the program on disk is known as Saving. A program

should be saved on a desktop be used repeat.


 C++ programs are saved with .cpp extension.

 For example, a progarm can be saved like program.cpp

Ms Qurat-ul-Ann
Saving a C++ Program
 The following procedure is used to save a C++ program:

1. Select File >Save OR Press F2 Key. The Save File As dialog box will appear.

2. Enter the file name. the default name NONAME.CPP appears in the dialog
box.

3. Enter the Path to save file. The default location to save program is BIN
directory.

4. Click on ok. The program will be saved at special location with specified
name.

Ms Qurat-ul-Ann
Saving a C++ Program

Ms Qurat-ul-Ann
Compiling a C++ Program
 The Process of converting a Source Program into an object program

is known as compiling.
 The program save with .cpp extension contains the statement of C++

languages. It is known as source program.


 A source program cannot be executed directly. A compiler converts

the source program into object program and saves it in a separate file.
The object program is saved with .obj extension.
 The source code cannot be compiled if contains any syntax errors.

The complier generates error message to describe the cause of error.


 All errors must be removed to successfully compile a source
program.
Ms Qurat-ul-Ann
Compiling a C++ Program
 The following procedure is used to compile a C++ program.

1. Select Compile>Compile Or press ALT+F9 key.

2. The program will be translated into object code if it contains no errors. The
compiler will generate error message if the program contains any errors.

Ms Qurat-ul-Ann
Linking a C++ Program
 The process of linking library files with the object program is known as linking.

 These files are used to accomplish different tasks such as input/output etc..

 A library files must be linked with the object file before execution of program.

 A program that combines the object program with the additional library files is known as linker. It

is part of C++ compiler.


 The linker generates error message if the library file dose not exist.

 A new file is created with .exe extension if the process of linking is successful. This files is known

as executable file and can be executed by the computer directly.


 The linker can be invoked in Turbo C++ by selecting Compiler>Link from the menu bar.

Ms Qurat-ul-Ann
Executing a C++ Program
 The process of running an executable file is known as executing.

 The C++ program can be executed after compiling and linking. The program

must be loaded into the memory to execute it.


 A program that places an executable file in memory is know as loader.

 The program can be loaded in memory by selecting Run>RUN from menu

bar pressing Ctrl+F9.


 The screen flickers for some time when a program is executed. The output

screen displays the output of the program and disappears.


 The user can display the output screen by selecting windows>User Screen

or press ALT+F5

Ms Qurat-ul-Ann
Running Programs
• Steps that the computer goes through to run a
program:
Memory

Machine language
program
(executable file)
Input Data Data entered CPU
during execution

Computed results
Program Output

Ms Qurat-ul-Ann
The user enters program and save it as source file

Revised
Source File Source File

The compiler attempts to translates a program


The user correct syntax errors

Success Failure
Errors List

Other Object
Linker links new object file with other object files
Files

Executable File
Different Steps from writing to
executing C++ program
Loader place executable file in memory

Executable file in memory


Ms Qurat-ul-Ann
Program Execution
 Steps taken by the CPU to run a program
(instructions are in machine language):
1. Fetch an instruction
2. Decode (interpret) the instruction
3. Retrieve data, if needed
4. Execute (perform) actual processing
5. Store the results, if needed

Ms Qurat-ul-Ann

You might also like