Avel-COVID19-Comp Sc-Nd1 Course- Intro to Programming
COVID – 19 SIT@HOME
INTEL DEV. CLASS
ND COMPUTER SCIENCE
INTRO TO COMPUTER PROGRAMMING
BY
Committee of Intellectuals [CoI]
@
INTELLECTUAL DEVELOPMENT CONFERENCE CENTER [INTEL CENTER]
INTRO TO COMPUTER PROGRAMMING
Programming
is an act of writing program or set of instruction that the computer execute to produce a desired result. A programming is the art of engineering that deals with the design and construction of real systems it is the act of writing programs or set of instruction using computer language to solve a given problem.
Computer Program
is a set of instruction written in computer language to solve a specific problem
or is a sequence of instructions written to perform a specified task.
B
QUESTION: Briefly describe an Algorithm in programming?
An algorithm is a self-contained step by step of operations to be performed. It is an effective method that can be expressed within a finite amount of space and time and in a well determined formal language for calculating a function. It is a set of rules that precisely defines a sequence of operations to be performed about a given problem.
QUESTION: Briefly describe the following terms: (i). Module cohesion (ii) Module coupling
Module cohesion is an indication of how closely each of the statements in a module are to one another. As cohesion is increased, module independence, clarity, maintainability and portability are increased.
Module coupling refers to the connections, or interfaces between modules. Modules should be loosely coupled such that what goes on inside one module should not affect the operation other module.
C
QUESTION: Compare Syntax and Run Time Errors
Syntax error is an error in the syntax of a sequence of character or tokens that is intended be written in a particular programming language
Run Time Errors occurs at compile time, however for interpreted language not all syntax errors are reliably detected until run time.
QUESTION: Compare machine code and assembly code?
Machine code consist of sequences of binary numbers or bits which one usually represented by 1s and 0s that forms the basic instruction that quite the operation of the computer. It is low level programming language that can be understood directly by the computer CPU.
Assembly code are low level programming language in which each statement corresponds directly with a single machine instruction. They are specific to a given processor. It is written using symbols and memories as short cut to long command but uses an assembler to convert the codes into machine codes.
QUESTION: Compare and contrast how is an algorithm different from a flowchart? Give definitions and two (2) advantages of each.
Algorithm is the set rules, which gives the sequence of operations for solving a specific type problem. It is a recipe, method, step by step process or routine to follow when accomplishing a task.
Flowchart is the representation of algorithm using standard symbols It is the pretrial representation of the solution to a particular problem.
Algorithm
- Simplicity and clarity
- Brakes the problem into understandable form
Flowchart
- Communication
- Documentation
- Modification
- Analysis
D
QUESTION: Define the following terms:
Comment, Reserved word, Variable, Line numbers, Data types
- Comment: – Is an un-executable line of statement that describes what a programmer is doing in a computer program.
- Reserved word: – These are key words that have special meaning to a particular programming language it belongs to.
- Variable: – Is a memory location that is used to store or holds data.
- Line numbers: – These are positive integer number that differentiate one line of statement from another, it also enhance the transfer of control from one portion of the program to the other.
- Data types: – Data types are used to describe the types of data or values a particular variable can hold.
QUESTION: Describe the following logic structure in a program: Simple Sequence and Selection?
Simple sequence instruction are executed in the straight line sequence starting with the first instruction and terminating at the last instruction. If the instruction is executed control is transferred to the next instruction following it. It is flowcharted sequentially as indicated below
Selection instruction structure consist of a test for condition follows by two alternative paths for the program control to follow i.e. IF ——– ELSE statement here follows dual paths or dual alternative decision statement e.g.
IF expression THEN
Statement A
ELSE
Statement B
End if
QUESTION: Describe the pseudo code form of algorithm hence write out the pseudo code that find the area of triangle.
A pseudo code is the English- like representation the program logic (i.e Algorithm). It is the sequential step by step principle for sketching out the structure of the program before the actual coding take place.
Begin;
Read b, h
Compute the product of b and h;
Set the result to array;
Compute the division of area with 2;
Set the result to Area
Display Area;
End
QUESTION: Develop an algorithm to show whether a given number is even or odd
Begin
Read n
Set rem to n MOD 2
If rem is equal to 0
Display “Number is odd”
End if
End
QUESTION: Draw a flowchart to add the first 100 integer numbers?
E
QUESTION: Enumerate the basic steps of debugging in programming.
- Recognize that bug exist
- Isolate the source of the bug
- Identify the cause of the bug
- Determine a fix for the bug
- Apply the fix and test it
QUESTION: Explain the use of comment, pscudo code, and modular programming practice.
Comment makes a program more readable. Every routine should start with at least one comment that document the purpose of the routine and any non-obvious dependencies or effects that the routine may have on other portion of the program.
Psendo code resembles a cross between English and the programming language that the code will eventually be written in. It allow the programmer to concentrate on the conceptual aspect of program with a being distracted by syntax rules.
Modular coding implies that the line of a routine should fit entirely on one screen of the editor. Keeping routine short make it easy to comprehend and see errors. It also forces the programmer to break easy task into distinct subtasks for ease of maintenance and modification. Modular coding also create reusable routine that can be used in other programs.
QUESTION: Enumerate the stages involved in program development.
- Problem Definition
- Analysis and Modeling
- Design
- Development
- Code testing and evaluations
- Implementation
- Documentation
H
QUESTION: Highlight five (5) flowchart symbols; hence explain the methods of representing an algorithm
The methods of representing an algorithm
The following methods could be used to represent algorithm
- English like form
- Flow Chart
- Pseudo code
- Decision table and
- Data Flow Diagram
I
QUESTION: In the design of algorithm, there are three (3) logical structures involved, mention and explain them.
- Simple sequence consist of one action followed by another. The flow of the control is find to perform operation A and then to perform operation B. A simple sequence is flowcharted as two process symbol connected by a flow line.
- Selection sequence structure consist of a test for condition followed by two alternative paths for one program to follow. The program select one of the program control path s depending on the test of the condition. After performing one of the two paths the program control returns to a single prompt. The pattern could be IF——-ELSE.
- Iteration logic also called additive structure or loop has a situation where an operation or set of operation is repeated until some conditions is satisfied. The basic form of repetition is the DO WHILE in structure programming or PERFORM UNTIL; the program logic tests a condition, if it is true the program executes the operation and loops repetition ceases.
- Repeat for K=R to S by T
- (module end of loop).
L
QUESTION: List sequentially, and explain the recommended step which should be taken in the process of programming.
- Identify the problem:-in fact, this stage should really be called identifying the solution because what you are really trying to do is to the down exactly what it is that you are trying to achieve.
There are two stages to identifying a solution.
- Requirement ii. Specification
- Design a solution:-once you have identified the things required to solve your problem, and the next step is to work out just how you are going to turn that specification into a working program.
- Write a program:-programming is then the task of describing your design to the computer. There are usually three stages to writing a program
- Coding
- Compiling
- Debugging
(d) Check the solution:- the finally step in the grand programming process is that of testing you creation to check that it does what you wanted it to do.
M
QUESTION: Mention four high-level languages?
- COBOL: Common Business Oriented Language.
- BASIC: All-purpose Symbolic Instruction Code.
- FORTRAN: FORmularTRANslator
- PASCAL:
QUESTION: Mention 6 features of a good programming language.
- Security
- Reliability
- Usability
- Maintainability
- Correctness
- Speed
QUESTION: Mention 5 criteria for selecting a good programming language?
- Ease of learning
- Ease of understanding
- Speed of development
- Help with enforcement of correct code
- Portability
- Maintainability
- Security
- Fit for purpose
- Supported platform environments
S
QUESTION: Sketch the flowchart to determine which of the following numbers is the smallest n1, n2, n3, n4, and n5.
U
QUESTION: Using the FOR-NEXT statement, write a basic program to computer the factorial of any positive integer number.
5 REM PROGRAM TO FIND THE FACTORIAL OF ANY INTEGER NUMBER
10 INPUT “ENTER THE NUMBER”; N
15 LET FACTO =1
20 FOR K = 1 TO N
30 FACTO = FACT * N
40 NEXT K
50 PRINT N,”—> ” , FACTO
60 END
W
QUESTION: What is programming, hence define a computer program?
Programming is an act of writing program or set of instruction that the computer execute to produce a desired result. A programming is the art of engineering that deals with the design and construction of real systems it is the act of writing programs or set of instruction using computer language to solve a given problem.
Computer Program is a set of instruction written in computer language to solve a specific problem. Is a sequence of instructions written to perform a specified task.
QUESTION: What do you understand by Module Coupling and Module Cohesion?
Module coupling is the manner and degree of interdependence between software module, a measure of how closely connected two routines or modules are the strength of the relationship between modules, how coupling correlates with high cohesion and vice versa how coupling is a sign of well-structured programming and a good design and when combine with high cohesion support the general goal of high readability and maintainability.
Module cohesion refer to the degree to which the element of a module belong together cohesion measures the straight of relationship between pieces of functionality within a given module. Either high or low, high cohesion is preferable because it is associated with software robustness, reliability, reusability and understandability
QUESTION: What are the advantage of High Level Language over the Low level Language?
- program development very fast
- fewer times of code are required
- program maintenance easier
- ease of use
- portable programs
QUESTION: Write a program to test any number entered by the user is a prime number or not using BASIC language.
10 INPUT “Enter any Number” ; N
20 SUM = 0
30 FOR I = 1 TO N
40 IF N MOD I = 10 THEN
50 SUM = SUM + 1
60 NEXT
I 1
70 IF SUM = 21 THEN
80 PRINT “ IT IS A PRIME NUMBER” ; N
90 ELSE
100 PRINT “IT IS NOT A PRIME NUMBER”; N
110 END IF
120 END IF
130 END
QUESTION: Write out the syntax of IF THEN ELSE and FOR NEXT statement.
IF (condition) THEN
Statement A
ELSE
Statement B
END IF
FOR (initialization statement; condition; increment/decrement)
Action statement
NEXT
QUESTION: What are the goals of good program documentation
- description of the design of program
- it tells other programmers what the program does and how it works
- program modification is made –easier
- documentation during development allows for security in maintenance
- it make the structure of program well organized
- it aid debugging in programming
QUESTION: Write short notes on the following i. Graphic User Interface ii. Structured Programming
Graphic user interface (GUI) is a graphical display in one or more windows containing controls called component that enable a user to perform initiative tasks. The user of the call does not have to create a scripts or write commands at the command line to accomplish the tasks. Graphic user interface accept input via devices such as keyboard and mouse and provide articulated graphical output on the computer monitor.
GUI component include menu, toolbar, push buttons, radio button etc
Structured programming is a procedural programming in which programs were taught of as a series of procedures that acted upon data. The principle idea behind it is as simple as the idea of divide and conquer. Any task that is too complex to be describe simply would be broken down into a set of smaller component tasks until the tasks were sufficiently small to be executed and self contained enough that they can easily be understood
QUESTION: What are the source of bugs in a program?
- calling wrong function
- using wrong variable
- failing to initialize variable
- using wrong delimeter
- slapping a check for error return
- failure to hide complexity
- incompetence
QUESTION: What is computer PROGRAM?
A Program is a set of instructions that a computer follows to perform a task.
QUESTION: What is an algorithm?
An algorithm is a step by step procedure or routine that must be followed to get a particular problem solved.
QUESTION: Write a program to find the volume of 20 cylinders in
(i) BASIC PROGRAMMING (ii) FORTRAN PROGRAMMING?
BASIC PROGRAMMING:-
REM PROGRAM TO FIND THE AREA OF 20 TRIANGLES?
For k =1 to 20
Input “ENTER THE RADIUS”;R
Input “ENTER THE HEIGHT”;H
VOLUME = 3.142 *R^2*H
PRINT “VOLUME =”; VOLUME
NEXT K
END
FORTRAN PROGRAMMING:-
C234567
PROGRAM TO FIND THE AREA OF 29 TRIANGLES
DO 20 K =1,20
PRINT*, ‘ENTER THE RADIUS’
READ*,R
PRINT*,’ENTER THE HEIGHT’
READ*, H
VOLUME =3.142 *R**2*H
PRINT*, VOLUME =’,VOLUME
CONTINUE
END
QUESTION: What is a flowchart?
A flowchart is the diagrammatical representation of (algorithm) the step by step procedure or routine of solving a particular problem.
QUESTION: Write a BASIC program to find the root of a quadratic equation?
10 REM PROGRAM TO FIND THE ROOTS OF A QUADRATIC EQUATION
20 INPUT “ENTER VALUE FOR A,B,C”;A,B,C
30 LET D = SQRT (B^2-4*A*C)
40 X1 = -B + D/2 *A
50 X2 = -B – D/2 *A
60 PRINT “X=”, X1, “OR X=”,X2
70 END
QUESTION: What is a control structure?
Control structure are used to test or determine where control should be passed to in a program. These includes branching, selection and iteration (loops).
QUESTION: Why is visual basic event driven?
Visual basic is a tool allows you to develop windows (GRAPHIC USER INTERFACE – GUI) application. The application has a familiar appearance to the user.
Visual basic event-driven, meaning code remains idle until called upon to respond to some event such as button pressing, menu selection, double clicking etc.
QUESTION: Write a FORTRAN program to find the volume of a cone?
C234567
PROGRAM TO FIND VOLUME OF A CONE
PRINT*,’ENTER THE HIEGHT’
READ*,H
PRINT*,’ENTER THE RADIUS’
READ*R,R
VOLUME = 1/3 *3,142*R**2 * H
PRINT*,VOLUME OF THE CONE =’,VOLUME
END
QUESTION: What is modular program?
Modular programming involve the breaking down of program into small parts that one move easily understood as the problem and program. The planning, coding and testing can be close on these small scale, relative simple unit, rather than one large complex body of code.
QUESTION: Write short notes on following vis-à-vis definition, advantages and disadvantages. Machine language (ii) Assembly language (iii) High-level language
Machine language is a low level language which is much me dependent. It is written in OS and IS consisting of binary numbers or bits. The language form the basic instructions that guide the operation of the machine.
Assembly language is a low level language in which each statement correspond directly to a single machine instruction. They are specific to a given processor. It is written using symbols and mnemonics as short cut to long command but uses an assembler to convert codes in machine language.
High level language are computer languages that provides certain level of abstraction from the underlying machine language through the use of declarations, control, statements and other syntax real structure. These language gives fluency, flexibility and the opportunity to express solution to problem. They are problem oriented languages and not specific to a particular machine e.g FORTRAN, Basic, Pascal e.t.c.
QUESTION: What are the basic steps involved in debugging a program? Mention and give concise explanation.
- Recognize that a bug exist
- Isolate the source of the bug
- Identify the cause of the bug
- Apply the fix and test it
QUESTION: What do you understand by good programming practice?
Good programming practice makes code program easier to maintain and modify. These is achieved by following some technique in programming.
The use of comments variables and constant description names, and sketched out basic structure or the program at beginning in psendo-code and modular coding often make programming easy.
QUESTION: What is a programming language? State the major programming language levels?
Programming language usually refers to high-level languages such as BASIC,C, CTT, COBOL, FORTRAN, Ada and Pascal. Each language has a unique set of keywords and a special syntax for organizing program instruction.
OR
A programming language is use by human programmer to direct a computer to accomplish a specific set of steps which lead to a desired outcome.
State the major programming language levels?
- Machine
- Assembly
- High-level
- Low level
QUESTION: What is BASIC variables? What are the rules governing these variable names
Variable is a name given to a location
Rules governing these variable names
- A variable name must be of the form (name or $ {name}
- The string name can consist of letters [a-z and A-Z], NUMBER (0-9) and underscore characters () .
- The first character of name must be an alphabetic character (a-z or A-Z).
- If the ${name} form is used, spaces can also appear in name. this allows you to use multiple word names without the underscore character.
QUESTION: What are operators in BASIC? Identify the various categories of operator and state the general use of each category. Write BASIC statements to illustrate the use of at least one (1) operator in each category.
Operators are used to perform mathematical or logical operations on values. An operator is something that can combine values to produce a new result, or that than produce a new value from existing one.
Categories of Operators in Basic
OPERATOR | USAGE |
^ | Exponential |
*, / | Multiplication and division |
+, – | Addition and subtrator |
<, >, <>,<=, >= | Greater and less than and equal to |
NOT | |
OR | |
AND |
Basic Statements to Illustrate At Least One Operator
x = 0
x = x + 1
QUESTION: What are the features of OOP language
Object, Classes, Encapsulation, Polymorphism and Inheritance
QUESTION: Write an interactive program to add two numbers in QBASIC, FORTRAN and Visual Basic 6
QBASIC
REM PROGRAM TO ADD 2 INTEGER NUMBERS
INPUT A, B
LET C = A+B
PRINT C
END.
FORTRAN
Print *, ‘enter the 1st Number’
Read *, X
Print *, ‘enter the 2nd Number’
Read *, Y
Z = X + Y
Print *, ‘Sum is=’, Z
Stop
End
VISUAL BASIC
Private Sub and add_click ()
Dim fsumAs double, Ffirstno As double, fsecondno As double
Ffirstno = Val (textNumb1.Text)
Fsecondno = Val (textNumb2.Text)
Fsum = Ffirstno + Fsecondno
textResult.text = Format (Fsum)
End Sub
End
End Sub.