Exit Exam Tutorial #1-2

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 110

Computer programming (Introduction to

computing) Tutorial for Exit Exam


preparation based on blueprint sent by
MOE.

1
Outlines
1. Fundamental programming concepts, Algorithm,
flowchart and Software

2. Basics of C++

3. Examine various kinds of operators and program flow


control statement

4. Logical thinking to develop computer programs.

2
Fundamental programming concepts
• Computers have emerged as the most useful device in recent
times.
• They perform a variety of tasks
• However, being machines, computers cannot perform on their
own.
• They need to be instructed to perform, even something so
simple as addition of two numbers.
• Computers work on a set of instructions called computer
program, which clearly specify the ways to carry out a specific
task.

3
• An analogy of this may be thought of as the instructions given by
the manager or team leader to its team.
• The team members follow those instructions and accordingly
perform their duties.
• Similarly, a computer also takes instructions from its user, inform
of computer programs, and carried out the requested task.
• Therefore,
 A computer is an electronic device that executes the instructions in
a program.
 a program is a list of instructions, together with any fixed
information required to carry out those instructions.

4
• A computer specialist who is responsible for designing,
writing, and modifying computer program allowing end-users
to interface directly with computer operating systems and
hardware is known a computer programmer.
• Broadly, programmers can be classified into two categories,
namely, systems programmers and application programmers.

5
• System programmers are mainly concerned with those programs,
which provides interface and functionality to the hardware
components.
• These programs help the computer to boot or they facilitate
general functioning of the computer. For example MSDOS.SYS
and COMMAND.COM programs are used to boot the system
while FORMAT.COM and CHKDSK.COM programs help in
normal functioning of the computer.
• An application program writes programs to fulfil a specific task
such as inventory control and payroll system.
6
• Thus, in order to design a program for a computer, you must
determine three basic elements:

1. The instructions that must be performed.

2. The order in which those instructions are to be performed.

3. The fixed data required to perform the instructions.

7
Programming Languages
• We, as human beings, use natural languages such as English, Amharic,
AfanOromo or Afsomali to communicate.
• Similarly, a user communicates with the computer in a language
understood by it.
• We also know that a computer cannot think.

• It needs to be instructed to perform all the tasks.


• The instructions are provided in the form of computer programs, which
are developed by a programmer using a programming language.

8
Programming Languages
• The language, which the user employs to interact with
computer, is known as computer programming language.
The process of using such languages to instruct the
computer is knows programming or coding.
• Programming languages are software development
environments that consist of a set of language primitives
(keywords and specified syntax) and a translator
(assembler, compiler, or interpreter) that converts source
code (written in with programming language primitives)
9
into object code (binary machine language).
Programming Languages (contd…)
 Programming languages are classified in three
categories:

1. Low level languages (LLL), which are computer


oriented, are used to create programs that have a one-to-
one correspondence between their statements and the
machine language statements based on the instruction set
of the CPU.

10
• Low level language programs make efficient use of the CPU
and memory, but, because they are tedious and difficult to
write correctly, are inefficient from the standpoint of
developer time and effort.
 Machine language which are numeric (sequence of ones
and zeros) , and
 Assembly language which utilizes mnemonic keywords.
Assembly language programs are translated into object
code by assemblers.

Eg. ADD D1,D2


11
Programming Languages (contd…)
• Low level languages are not user friendly. Examples:
Intel Assembly, Sparc Assembly, MIPS.
• A LLL (assembly language) has the following
characteristics:
 It is machine dependent
 It is designed to reflect the architecture of the machine, not to make
programming easier for you.
 One instruction generally translates into one machine instruction.
 The instructions use mnemonics for the underlying machine
instruction. Some Intel instructions are add, mov, jmp.

12
Programming Languages (contd…)
2. High level languages (HLL), which are task oriented,
facilitate the coding of algorithms.
• These languages are the primary tools of computer
scientists and are therefore a key component of Computer
Science curricula.
• HLL exemples ,

C, C++, FORTRAN, Pascal, Java, etc.

13
 A HLL has the following characteristics:
 It is designed to make the programming process easier for humans.

 Instructions emphasize the logical structure being used, for example, with a
while loop or an if..then..else statement.
 The structure of the language aids in the design process. For example,
supporting function calls aids in modular design. Supporting objects aids in
implementing abstract data types.
 It is machine/platform independent.

 A single HLL instruction usually translates into several machine instructions.

14
3. Very high level languages (VHLL), which are human
oriented, are designed to allow non-programmers
develop customized software.
• They are very powerful within the limited domain of
their application.

15
• There is a wide range categories of VHLL but the two most
useful in Web development are:
A. Authoring languages like markup languages (HTML,
DHTML, XML) and modeling languages (VRML) are
used to create Web pages and other hypermedia
documents.
B. Scripting languages like JavaScript are used to write
miniature programs that can be included within Web pages
providing animation and interactivity.

16
• A language may be extremely useful for one type of application
but may not work that well for other applications. For example,
a language such as COBOL is useful for business applications
but not for embedded software.
• Therefore, on the basis of application, languages can be broadly
classified as:
 Business: COBOL
 Scientific: FORTRAN
 Internet: JAVA
 System:C,C++
 AI: LISP and PROLOG
17
Common terminologies used in
programming
• Machine independent: Capable of being used on any type of machine
(Intel, Apple, Sun, ...).
• Platform independent: Capable of being used on any type of machine,
running under any operating system (MS windows, unix, linux...)
• Machine/platform dependent: Applicable to only one specific type of
machine/platform.
• Source Code: The program that you write in some language (Java, C,
assembly language).

18
Terminologies , contd…
• Object Code: Machine code version of source code for a particular
machine.
• Byte Code: A machine independent but low level code. This is also
called push code.
• Exe File: Executable file, ready to be loaded and run

• Compiler: The traditional definition of a compiler is a program that


translates source code into machine code.

19
Terminologies
• Linker: Another programming tool, the linker puts together
several object modules and library routines into one executable
file.
• Interpreter: A traditional interpreter translates source code into
machine code one line at a time, then immediately executes the
statement. Early Basic used an interpreter. Operating system
shell programming languages are often interpreted. The Java
Virtual Machine acts as an interpreter of Java byte code.

20
Terminologies
Syntax Error:
• This is a compiler error, indicating that you disobeyed
one of the grammar rules of the language.
•You could misspell a keyword, forget a semicolon or
closing bracket, use an else without an if, and many others.

21
Compiler Warning:
• With some compilers, all syntax errors are fatal and must be
fixed.
•Other compilers have warning level messages.

• A warning indicates an ambiguous or unusual usage of a


language feature, but the compiler can generate code.
•You should look at warnings and decide whether or not the
compiler is interpreting your meaning correctly.
•If you understand the warning and it is okay, ignore it. If not, fix
the problem. 22
Terminologies
Linker Error:
•The most common linker error is an unresolved external
reference.
•This occurs when a function is called in one module but
coded in a different module.
• The linker tries to find the function's implementation code,
but it isn't there. What could cause this?.

23
Run-time Error:
•This is also called an execution error or an exception.

• It will cause your program to terminate, usually with a system-


generated message.
•Typical examples are divide by zero and memory violations. An
infinite loop may cause a time-out on shared systems.

Logic Error: Your program compiles correctly, links without


problems, but doesn't produce correct output

24
Compile, Link & Run Steps
Machine Independent Machine Dependent

Compiler Linker OS Loader


Source Object Exe File Your
Code Code Output

+ Library
+ Other + test data
Object
Modules
Syntax Linker Run Time
Errors Errors Errors

• Note that the compiler translates machine independent high level source
code into machine dependent object code. The object files are all linked
into one executable file, which is what you run. The compile and link steps
need not be repeated each time you run the program. 25
Example
1. Which of the following is the correct definition of
Computer?

A. Computer is a machine or device that can be


programmed to perform arithmetical or logic operation
sequences automatically
B. Computer understands only binary language which is
written in the form of 0s & 1s
C. Computer is a programmable electronic device that
stores, retrieves, and processes the data
D. All of the mentioned

26
2. Which of the following language does the computer
understand?
A. Computer understands only C Language

B. Computer understands only Assembly Language

C. Computer understands only Binary Language


D. Computer understands only BASIC

27
3. Which of the following computer language is written in
binary codes only?
A. Pascal
B. machine language
C. C language
D. C# language

28
4. The language used in the business application is
A. FORTRAN B. COBOL
C. Java D. All
5. Which of the following was the disadvantage of first
generation language?
A. Less efficient B. Need for more disk space
C. Machine dependency D. All.

29
6. Good programming language has the
following features.

A. Portable, Safe B. Reliable, good performance

C. both (a) & (b) D. High cost

30
7. The language translator that translates the programs written in
high-level language corresponding machine code is
A. Compiler
B.Assembler
C.Loader
D.Linker
8. The language used in making web page is
A.C++
B.PASCAL
C.PROLONG
D.Java

31
9. A program that links together several object module and libraries
to form a single, coherent program is _____
A. Compiler
B.Assembler
C.Loader
D.Linker
10. Compiler and interpreter are called as _____
A.Language translator
B.Language Syntax
C.Linker
D.All
32
Algorithm
 The computer scientist Niklaus Wirth stated that:

Programs = Algorithms + Data


 The algorithm is part of the blueprint or plan for the computer program, an
algorithm is:
• "An effective procedure for solving a problem in a finite number of steps."

• It is effective, which means that an answer is found and it finishes, that is it


has a finite number of steps.
• A well-designed algorithm will always provide an answer.

• A well-designed algorithm is also guaranteed to terminate.

33
• Therefore, an algorithm is defined as a finite sequence of
explicit instruction that, when provided with a set of input
values, produces an output and then terminates.
• To be an algorithm, the steps must be unambiguous and after a
finite number of steps the solution of the problem is achieved.
• However, algorithms can have steps that repeat (iterate) or
require decisions (logic and comparison) until the task is
completed.
34
• Different algorithms may accomplish the same task, with a
different set of instructions, in more or less the same time,
space, and efforts.
• For example, two different recipes for preparing tea, one 'add
the sugar" while "boiling the water' and the other after boiling
the water produce the same result.

35
• However, perforating an algorithm correctly does not
guarantee a solution, if the algorithm is flawed or not
appropriate to the context.
• For example, preparing the tea algorithm will fail if there are
no tealeaves present; even if all the motions of preparing the
tea are performed as if the tea leaves were there.

Note that: Algorithms are not computer programs, as they cannot


be executed by a computer.
36
Characteristics of an Algorithm
 An algorithm must have the following properties:
i. There must be no ambiguity in any instruction.
ii. There should not be any uncertainty about which instruction is
to be executed next.
iii.The description of the algorithm must be finite. An algorithm
cannot be open-ended.
iv.The execution of the algorithm should conclude after a finite
number of steps.
v. The algorithm must be general enough to deal with any
contingency.

37
Here is an example of an algorithm for making a pot of tea:

1. If the kettle does not contain water then fill the kettle

2. Plug the kettle into the power point and switch it on.

3. Place tea leaves in the cup of tea.

4. Switch the kettle off.

5. Pour water from the kettle into the cup of tea

38
Another example of an algorithm to determine the largest
number out of three numbers A, B, and C:
Step 1: Start

Step 2: Read 3 numbers say: A, B, C

Step 3: Find the larger number between A and B and store it in MAX_AB

Step 4: Find the larger number between MAX AB and C and store it in MAX
step 5: Display MAX
step 6: Stop

39
Different ways of stating algorithms
• There are different ways of stating algorithms:

1. Step-Form (the tea making example above)

2. Pseudocode

3. Flowchart
• The first two are written forms.

• The Step-Form (the tea-making example) is just like normal language.

• Pseudocode is also human language but tends toward more precision by


using a limited vocabulary.
• The last one is graphically-oriented, that is they use symbols and language
to represent sequence, decision and repetition.
40
Flowchart
• A flowchart is a pictorial representation of an algorithm in
which the steps are drawn in the form of different shapes of
boxes and the logical flow in indicated by interconnecting
arrows.
• The boxes represent operations and the arrows represent the
sequence in which the operations are implemented.
• The primary purpose of the flowchart is to help the
programmer in understanding the logic of the program.

41
• Therefore, it is always not necessary to include all the required
steps in detail.
• Flowcharts outline the general procedure.

• Since they provide an alternative, visual way of representing


the information flow in a program.

42
• Flowcharts can be compared with the blueprint of a building.

• Just as an architect draws a blueprint before starting


construction of a building, a programmer draws a flowchart
prior to writing a computer program.
• As in the case of the drawing of a blueprint, the flowchart is
drawn according to defined rules and using standard flowchart
symbols prescribed by the American National Standard
Institute (ANSI).
43
Flowchart Symbols
• A flowchart uses special shapes to represent different types of
actions or steps in a process.
• Some standard symbols, which are frequently required for
flowcharts, are shown in Table below.
• Note that each symbol has a different shape denoting a
different type of operation.

44
45
46
47
48
Guidelines for Preparing Flowcharts
The following guidelines should be used for creating a flowchart
1.The flowchart should be clear, neat, and easy to follow.
2.The flowchart must have a logical start and finish.
3. In drawing a proper flowchart, all necessary requirements
should be listed in logical order.
4.The direction of the flow of a procedure should always be from
left to right or top to bottom.
5.Only one flow line should come out from a process symbol

49
6. Only one flow line should enter a decision symbol. However,
two or three flow lines (one for each possible answer) may leave
the decision symbol.

50
7. Only one flow line is used with a terminal symbol.

8. Within standard symbols, write briefly. If necessary, use the


annotation symbol to describe data or process more clearly,

51
Flowchart Structures
• Flowcharts can be simple, where only few boxes and lines depict the entire
logic.
• There are mainly three key concepts which are used in drawing a
flowchart.

i. Sequence: Where information can flow in a straight line.

ii. Selection (branched): Where the decisions are made according to some
predefined condition.

iii. Repetition: Where the logic can repeat in a loop, that is, where a sequence
of steps is repeated until the desired output is obtained.

52
Sequence Flowchart
• As the name implies, in a sequence structure, the instructions
to be computed simply follow one another in a logical
progression.
• On a flowchart, the symbol representing each instruction has
only a single entering path and a single exiting path.
• Typical sequence operations consist of process and
input/output steps.

53
54
• In the above example, the first symbol is a Terminal symbol,
which is tagged as 'Start'. This symbol indicates the beginning
of the flowchart.
• The second symbol is an Input/output symbol, tagged as
'X=10, Y=20', which indicates the initialization of two
numbers (X and Y) to 10 and 20, respectively.
• The third symbol is a Processing symbol, labeled as 'Z =
X+Y'. In this step, the processing, that is, addition is executed
and the sum is stored in a memory variable, which has given
the name Z.

55
• The fourth symbol is again an Input/output symbol, which is
labeled as 'Print Z'.
• This step will print the output (value of Z) on an output
device such as monitor.
• The last symbol, tagged as 'Stop', indicates the conclusion of
the problem solving logic.

56
Selection Flowchart
• A selection structure allows the program to make a choice
between two alternate paths depending upon the condition,
that is, whether it is true or false.
• The first statement of a selection structure is a conditional
statement that obviously involves a decision symbol when
represented on a flowchart.
• The Decision constructs - If ... then, If ... then ... else .

57
58
Repetition Flowchart
• Repetition or loop pattern causes an interruption in the normal
sequence of processing and directs the system to loop back to
a previous statement in the program, repeating the same
sequence over and again, usually with new data.
• When a sequence of statements is repeated against a condition,
it is said to be in a loop.
• Using looping, the programmer avoids repeating the same set
of instructions.
• The looping process can be either one time or multiple times
until the desired output is obtained within a single program.

59
60
• It has the general form:
Repeat
Process1
Process2
Process N
Until proposition
• Here is an example:
Repeat
Put water in kettle
Until kettle is full
• The process is Put water in kettle, the proposition is kettle is
full.

61
Importance of Flowchart
• A flowchart helps to clarify how things are currently working
and how they could be improved.
• It also assists in finding the key elements of a process, while
drawing clear lines between where one process ends and the
next one starts.
• Developing a flowchart encourages communication among
participants and establishes a common understanding between
them about the process.
• Flowcharts also help in revealing redundant or misplaced
steps.

62
• In addition, flowcharts are used to identify appropriate team
members by identifying who provides inputs or to whom the
resources are to be allocated.
• It also helps in establishing important areas for monitoring or
data collection and to identify areas for improvement or
increase in efficiency.

63
 The reasons for using flowcharts as a problem solving tool are given
below:
1. Makes Logic Clear:
 The main advantage of using a flowchart to plan a task is that it
provides a pictorial representation of the task, which makes the logic
easier to follow.
 The symbols are connected in such a way that they show the
movement (flow) of information through the system visibly.
 The steps and how each step is connected to the next can be clearly
seen.
 Even less experienced personnel can trace the actions represented by
a flowchart, that is, flowcharts are ideal for visualizing fundamental
control structures employed in computer programming.

64
2. Communication:
Being a graphical representation of a problem solving logic, flowcharts are a
better way of communicating the logic of a system to all concerned.
That is, the diagrammatical representation of logic is easier to communicate
to all the interested parties as compared to actual program code as the users
may not be aware of all the programming techniques and jargons.
3. Effective Analysis:
 With the help of a flowchart, a problem can be analyzed in an effective way.
This is because the analyzing duties of the programmers can be delegated to other
persons, who may or may not know the programming techniques, as they have a head
idea about the logic.
Being outsiders, they often tend to test and analyze the logic in an unbiased manner.

65
4. Useful in Coding:
The flowcharts act as a guide or blueprint during the analysis and
programs development phase.
 Once the flowcharts are ready, the programmers can plan the coding
process effectively as they know where to begin and where to end, making
sure that no steps are omitted.
 As a result, error free programs are developed in high-level languages
and that too as a faster rate.
5. Proper Testing and Debugging:
 By nature, a flowchart helps in detecting the errors in a programs, as the
developers know exactly what the logic should do.
Developers can test various data for a process so that the program can
handle every contingency

66
6. Appropriate Documentation:
 Flowcharts serve as a good program documentation tool.
Since normally the programs are developed for novice users,
they can take the help of the programs documentation to know
what the program actually does and how to use the program.

67
Limitations of Flowcharts
I. Complex:
 The major disadvantage in using flowcharts is that when a
program is very large, the flowcharts may continue for many
pages, making them hard to follow.
 Flowchart tend to get large very quickly and it is difficult to
follow the represented process.
 It is also very laborious to draw a flowchart for a large
program.

68
II. Costly
 Drawing simple flowcharts may be a cost effective process.
However, if the flowchart is to be drawn for a huge program,
the time and cost factor of program development gets out of
proportion, making it a costly affair.
III.Difficult to Modify:
•Due to its symbolic nature, any changes or modification to a
flowchart usually requires redrawing the entire logic again, and
redrawing a complex flowchart is net a child's play.
• It is not easy to draw thousands of flow lines and symbols along
with proper spacing especially for a large complex program.
69
IV. No Update:

 Usually programs are updated regularly.


However, the corresponding update of flowcharts may not take
place, especially in case of large programs.
As a result, the logic used in the flowchart may not match with
the actual program's logic.

70
Pseudocode (P-CODE)
• Pseudocode (pronounced Soo-Doh Kohd) is made up of two
words: Pseudo and Code.
• Pseudo means imitation and Code refers to instructions, written
in a programming language.
• As the name suggests, pseudocode is not a real programming
code, but it models and may even look like programming code.
• It is a generic way of describing an algorithm without using any
specific programming language related notations.

71
• Simply put, pseudocode is an outline of a program, written in a
form that can be easily converted into real programming
statements.
• Pseudocode uses plain English statements rather than symbols,
to represent the processes of a computer program
• Pseudocode is also known as PDL (Program Design Language),
as it emphasizes more on the design aspect of a computer
program or structured English, because usually pseudocode
instructions are written in normal English, but in a structured
way.
72
• The benefit of pseudocode is that it enables the programmer to
concentrate on the algorithms without worrying about all the
syntactic details of a particular programming language.
• In fact, you can write pseudocode without even knowing what
programming language you will use for the final implementation.

Note: Pseudocode cannot be compiled nor executed, and there are


no real formatting or syntax rules. It is simply one step, an
important one, in producing the final code.

73
Example of Pseudocode keywords, which are often used to
indicate input, output and processing operations.
•Input: READ, OBTAIN, GET, and PROMPT
•Output: PRINT, DISPLAY, and SHOW
•Compute: COMPUTE, CALCULATE, and DETERMINE
•Initialize: SET and INITIALISE
•Add one: INCREMENT

74
For example, the pseudocode given below calculates the area of a
rectangle.
PROMPT the user to enter the height of the rectangle
PROMPT the user to enter the width of the rectangle
COMPUTE the area by multiplying the height with width
DISPLAY the area
STOP

75
Basics of C++
• The C++ language is an object-oriented programming
language.
• The programming language was created, designed &
developed in 1979 by a Danish Computer Scientist – Bjarne
Stroustrup at Bell Telephone Laboratories (now known as
Nokia Bell Labs).
• C++ was initially known as “C with classes, ” and was
renamed C++ in 1983.
• ++ is shorthand for adding one to variety in programming;
therefore C++ roughly means that “one higher than C.”

76
Syntax of a C++ Program
• Syntax refers to the rules and regulations for writing
statements in a programming language.
• They can also be viewed as the grammatical rules defining the
structure of a programming language.
• The C++ language also has its syntax for the functionalities it
provides.

77
• We can learn about basic C++ Syntax using the following
program.

78
Header File
• The header files contain the definition of the functions and
macros we are using in our program.
• They are defined on the top of the C++ program.

• In line #1, we used the #include <iostream> statement to tell


the compiler to include an iostream header file library which
stores the definition of the cin and cout methods that we have
used for input and output.

79
• #include is a preprocessor directive using which we import
header files.
• Therefore, sentences that begin with a pound sign (#) are
directives for the preprocessor.

80
Namespace
• A namespace in C++ is used to provide a scope or a region
where we define identifiers.
• It is used to avoid name conflicts between two identifiers as
only unique names can be used as identifiers.
• In line #2, we have used the using namespace std statement for
specifying that we will be the standard namespace where all
the standard library functions are defined.

Syntax:
using namespace std;

81
Main Function

• Functions are basic building blocks of a C++ program that


contains the instructions for performing some specific task.
• Apart from the instructions present in its body, a function
definition also contains information about its return type and
parameters.

82
• In line #3, we defined the main function as int main().

• The main function is the most important part of any C++


program.
• The program execution always starts from the main function.

• All the other functions are called from the main function.

• In C++, the main function is required to return some value


indicating the execution status.

83
Syntax:

84
Blocks
• Blocks are the group of statements that are enclosed within
{ } braces.
• They define the scope of the identifiers and are generally used
to enclose the body of functions and control statements.
• The body of the main function is from line #4 to line
#9 enclosed within { }.
Syntax:

85
Semicolons
• As you may have noticed by now, each statement in the above
code is followed by a ( ; ) semicolon symbol.
• It is used to terminate each line of the statement of the
program.
• When the compiler sees this semicolon, it terminates the
operation of that line and moves to the next line.
Syntax:

any_statement ;

86
C++ Identifiers
• In C++ programming language, identifiers are the unique
names assigned to variables, functions, classes, structs, or
other entities within the program.
• For example, in the below statement,

int num = 11;

num is an identifier.

87
Rules to Name of an Identifier in C++
• We can use any word as an identifier as long as it follows the
following rules:
1. An identifier can consist of letters (A-Z or a-z), digits (0-9),
and underscores (_). Special characters and spaces are not
allowed.
2. An identifier can only begin with a letter or an underscore
only.
3. C++ has reserved keywords that cannot be used as identifiers
since they have predefined meanings in the language.
For example, int cannot be used as an identifier as it has already
some predefined meaning in C++. Attempting to use these as
identifiers will result in a compilation error.

88
Basic Output cout
•In line #7, we have used the cout method which is the basic
output method in C++ to output the sum of two numbers in the
standard output stream (stdout).
Syntax:
cout << result << endl;

89
90
return 0;
• The return instruction makes the main() function to finish
and return the code that the instruction is followed by, in this
case 0.
• This is most usual way to terminate a program that has not
found any errors during its execution.

91
Example
1. Flowcharts and algorithms are used for
A. Better Programming
B. Easy testing and debugging
C. Efficient coding
D. All of these
2. Pseudocode is used for
A. Denoting the program Flow
B. Program code
C. For coding the program
D. To write program steps
92
3. Which of the following is not an advantage of a flowchart?
A.Better communication
B. Efficient coding
C. Systematic testing
D.Improper documentation
4. The operation represented by a parallelograms.
•Input/output
• Assignment
• Comparison
•Conditions
93
5. Which of the following is not a flowchart structure?
A.Process
B. Sequence
C. Repetition
D. Case
6. A _____ is a connector showing the relationship between the
representative shapes.
A.Line
B.Arrow
C. Process
D. box
94
7. A _____ is a directed graph that describes the flow of
execution control of the program.
A.Flowchart
B. Flow graph
C. Complexity curve
D.Algorithm
8. Which of the following is a loop statement?
A. IF
B. Else
A.While
B.Do
95
9. The _______ symbol is used at the beginning of a flow chart.
A.Oval
B.Rectangle
C. Diamond
D. None of these
10. The _____ symbol is used to represent process in flowchart.
A.Circle
B. Rectangle
C.Diamond
D. None of these
96
11. ______ symbol is used to represent input and output
operation in flowchart.
A.circle
B.Rectangle
C. Diamond
D. Parallelogram
12. Part of algorithm which is repeated for the fixed number of
times is classified as
•Iteration
• selection
•Sequence
•reverse action
97
13. In flowchart, parallelogram is used to show
A. General input symbol
B. Operation on data
C. Online use of keyboard
D. Output data screen
14. When an algorithm is presented in the form of a Programming language it becomes a
______
A.Program
B. flowchart
C. Pseudo code
D. Syntax
15. A box that can represent two different conditions.
•Rectangle
• Diamond
• Circle
• Parallelogram

98
16. Which of the following symbol in a flowchart are used to
indicate all arithmetic processes of adding, subtracting,
multiplying and dividing ?
A.Input/output
B.Terminal
C.Processing
D.Decision
17. Pseudo code is also known as
A.Program Design Language
B.Hardware Language
C.Software Language
D.Algorithm

99
18. In which of the following pseudo code instructions are written in the order
or sequence in which they are to be performed?
A.Selection Logic
B.Sequence Logic
C.Iteration Logic
D.Looping Logic
19. Which of the following logic is used to produce loops in program logic
when one or more instruction may be executed several times depending on
some conditions?
A.Iteration Logic
B.Selection Logic
C.Sequence Logic
D.Decision Logic

100
20. Selection logic also called as
A.Decision Logic
B.Iteration Logic
C.Sequence Logic
D.Looping Logic
21. Which of the following program planning tool allows the
programmers to plan program logic by writing program instruction in an
ordinary language?
•Flowchart
•Pseudo code
•Program
•Looping

101
22. Algorithm is
A.step by step execution of program
B.Object file
C.Executable file
D.Source file
23. Diagrammatic representation of an algorithm is
A.Flowchart
B.Data flow Diagram
C.Algorithm design
D.Pseudo code

102
24. After a programmer plans the logic of a program ,she /he will
next____
A.Understand the problem
B.Translate the program
C.Test the program
D.Code the program
25. The following pseudo code is an example of _______ structure:
Get number
While number is positive
Add to sum
A.Sequence
B.Decision
C.Loop
D.Nested 103
26. C++ language was developed by ___.
A.Dennis Rechard
B.Dennis M. Ritchie
C.Bjarne Stroustrup
D.Anders Hejlsberg
27. Which of the following is used for single-line comment in
C++?
•//
•\\
•/* */
•##

104
28. Which of the following is the correct extension of the C++
source code file?
A. .cpp
B. .c++
C. Both A&B
D. None
29. In which year, the name of the language was changed from "C with
Classes" to C++?
A.1979
B.1972
C.1983
D.1986

105
30. Which of the following is the correct syntax of header files in
C++?
A. #include “iostream”
B.#include <iostream.h>
C. #include <iostream>
D.All
31. C++ is a ___.
A.High-level language
B.Medium level language
C.Low-level language
D.None of the above

106
32. Which of the following statement is correct about identifiers in C++?
A.Identifiers are the combination of alphanumeric characters that can be used
for function and variable names.
B.Identifiers are a combination of alphanumeric characters that can be used
for looping statements.
C.Both of the above
D.None of the above
33. Which of the following is a correct identifier in C++?
A.7var_name
B. 7VARNAME
C.VAR_1234
D. $var_name

107
34. What will be the output of the following C++ code?
#include <iostream>
int main ()
{cout << "Hello class! "
return 0;}

A.Hello class
B.Hello class!
C.Syntax error
D.None

108
35. What will be the output of the following C++ code?

#include <iostream>
int main ()
{
cout << "Hello World! ";
cout << "I like a C++ program";
return 0;
}
A. Hello World! I like a C++ program
B. Hello World I like a C++ program
C. Hello World!
I like a C++ program
D. Hello World
I like a C++ program

109
Types of Header Files in C++

• There are two types of header files in C++:


• Standard Header Files/Pre-existing header files
• User-defined header files
• 1. Standard Header Files/Pre-existing header files and
their Uses
• These are the files that are already available in the C++
compiler we just need to import them. Standard header files
are part of the C++ Standard Library and provide commonly
used functionalities. They contains the declarations for
standard functions, constants, and classes.

110

You might also like