Docsity

Principles of Computer programming assignt 1, Assignments of Computer Programming

Toggle sidebar
bg1
1
QUESTION 1
COMPUTER PROGRAMMING.
Computer Programming is an art and science, of giving a mechanism or computer, the
directions or instructions to follow to solve a problem or accomplish a task.
QUESTION 2
DIFFERENCES BETWEEN EVENT-DRIVEN AND OBJECT-ORIENTED
AND PROCEDURAL PROGRAMMING LANGUAGES.
To put it mildly, in Event-Driven the flow of Control is determined by events
triggered by the user, (click of a mouse), whilst Object-Oriented Programming
requires the programmer to focus on the objects that the program can use to
accomplish its goal. Finally, in Procedural Oriented Programming, the programmer
only concentrates on the major tasks that the program needs to perform step by step.
EVENT- DRIVEN
OBJECT ORIENTED (OOP)
PROCEDURAL
The flow of control for the
program is determined by
events mostly triggered by
users.
That is, execution is
determined for example by a
user action such as mouse
click, keypress, or a message
from the Operating System
(OS) or another user.
Visual Basics and Visual C++
are specially designed to
facilitate event-driven
programming and provide an
integrated development
environment (IDE) that
partially automates the
production of code.
Relies on the concept of classes
(abstract blueprints used to
create concrete objects) and
objects. Examples are, Java,
C++, Python, PHP, JavaScript
Unlike Event-Driven
Languages, OOP organises
software design around objects
rather than functions and logic.
Three major differentiating
features of OOP are i)
encapsulation; creation of self-
contained modules that bind
processing functions to data. ii)
Inheritance Passes “knowledge”
Down; allows the structure and
methods in one class to be
passed down the hierarchy. iii)
Polymorphism Takes any
Shape; allows procedures about
objects to be created whose
type is not known until runtime.
It follows a step-by-step
approach to break down a task
into a collection of variables and
routines (or subroutines) through
a sequence of instructions or
procedures.
The procedures or routines,
simply consist of a series of
computational steps to be carried
out, during which any given
procedure might be called at any
point by other procedures or
itself.
Languages used in Procedural
Programming are Fortran, Algol
Basic Visual, Pascal, and C++.
pf3
pf4
pf5

Partial preview of the text

Download Principles of Computer programming assignt 1 and more Assignments Computer Programming in PDF only on Docsity!

QUESTION 1

COMPUTER PROGRAMMING.

Computer Programming is an art and science, of giving a mechanism or computer, the directions or instructions to follow to solve a problem or accomplish a task.

QUESTION 2

DIFFERENCES BETWEEN EVENT-DRIVEN AND OBJECT-ORIENTED

AND PROCEDURAL PROGRAMMING LANGUAGES.

To put it mildly, in Event-Driven the flow of Control is determined by events triggered by the user, (click of a mouse), whilst Object-Oriented Programming requires the programmer to focus on the objects that the program can use to accomplish its goal. Finally, in Procedural Oriented Programming, the programmer only concentrates on the major tasks that the program needs to perform step by step.

EVENT- DRIVEN OBJECT ORIENTED (OOP) PROCEDURAL

The flow of control for the program is determined by events mostly triggered by users.

That is, execution is determined for example by a user action such as mouse click, keypress, or a message from the Operating System (OS) or another user.

Visual Basics and Visual C++ are specially designed to facilitate event-driven programming and provide an integrated development environment (IDE) that partially automates the production of code.

Relies on the concept of classes (abstract blueprints used to create concrete objects) and objects. Examples are, Java, C++, Python, PHP, JavaScript

Unlike Event-Driven Languages, OOP organises software design around objects rather than functions and logic.

Three major differentiating features of OOP are i) encapsulation; creation of self- contained modules that bind processing functions to data. ii) Inheritance Passes “knowledge” Down; allows the structure and methods in one class to be passed down the hierarchy. iii) Polymorphism Takes any Shape; allows procedures about objects to be created whose type is not known until runtime.

It follows a step-by-step approach to break down a task into a collection of variables and routines (or subroutines) through a sequence of instructions or procedures.

The procedures or routines, simply consist of a series of computational steps to be carried out, during which any given procedure might be called at any point by other procedures or itself.

Languages used in Procedural Programming are Fortran, Algol Basic Visual, Pascal, and C++.

QUESTION 3

DIFFERENCES BETWEEN LANGUAGES

High-Level Languages This is a machine-independent language that enables a user to write a program in a language that resembles English words and familiar mathematical symbols. Python is an example of a High-level language. An example of this would be, Gross pay= hours*rate/hr. Programmers writing in a high-level language can be used on many different types of computers.

Assembly Languages To alleviate the limitations of machine language the Assembly language which is an intermediary language was invented. Assembly language is numbers, symbols and abbreviations called mnemonics instead of the 1s and 0s. For example, in addition, or subtractions and multiplication, it uses symbols like Add, Sub, and Mul, etc. Assembly language is only understood by human beings and this, therefore, means programs written in an assembly language require an assembler which is also a program to convert the assembly instructions into machine language- the 1s and 0s the computer can understand.

Machine Language Machine language is the low-level programming language that can only be represented by 0s and 1s. This language is only understood by computers. These 0s and 1s are microscope switches that can be either on or off respectively. For example, to write 120 in a computer system its representation is 1111000. This method is very difficult and prone to errors. Execution though is faster since all data is already in binary. The following table clear states the differences between these Languages

MACHINE LANGUAGE ASSEMBLY LANGUAGE HIGH-LEVEL LANGUAGE

Data is only represented by binary formats 0s and 1s

Data can be represented with the help of mnemonics. For example Add, Sub, End

A programmer uses language which resembles English words and familiar mathematical symbols Execution is fast because all data is already present in binary format

Uses an assembler to convert the assembly instruction into machine code

It uses an interpreter which translates the instruction line by line as the program is running Machine language is hardware dependent

Assembly Language is machine-dependent and is not portable

A high-level language is machine-independent

QUESTION 5

DISTINCTIONS BETWEEN PAIRS OF TERMS:

i. Arithmetic Operator and Relational Operator. Arithmetic operators are used to performing basic mathematical operations like addition, subtraction, multiplication, and division. There are five arithmetic operators available in C (+, -, *, /, %). Relational operators are binary operators used to relate or compare two operands. There are four relational operators in C (i.e <, <=, >, >=). If the relationship between the operands is correct, it will return 1 and returns 0 otherwise. The difference, therefore, is that the former is used for mathematical operations whereas the latter, is used for comparisons between two operands.

ii. Constant and Variable. A variable is a memory location whose value can change (vary) during Runtime , that is, when a program is running. Whereas a Constant is a Memory location whose value cannot be changed during runtime. Thus, a variable changes values during run time and a constant does not change values during run time.

iii. Expression and Statement. An arithmetic expression is a way of directing a computer to perform a calculation. The Arithmetic Expression contains one or more arithmetic operators. The full name Assignment Statement, on the other hand, refers to the allocation of a value to a variable while a program is running. The assignment statement is therefore used to assign a variable to the result/calculation of an arithmetic expression.

iv. Numeric Type and String Type. A string type consists of one or more characters, which can include letters, numbers, and other types of characters. A string represents alphanumeric data.

This means that a string can contain many different characters, but they are all considered as if they were text, even if the characters are numbers. Numeric Type on the other hand are numbers, whole numbers, that can be positive or negative and these numbers can also have decimals.

v. Remark and Declaration. Declaration of a variable is for informing the compiler of the following information: Name of the variable, type of value it holds, and the initial value if any it takes. i.e., declaration gives details about the properties of a variable. Memory will not be allocated during declaration. For example int f (int) A Remark is text notes added to the program to provide explanatory information about the source code. They are used in a programming language to document the program and remind programmers of what tricky things they just did with the code and also helps the later generation for understanding and maintenance of code. The compiler considers these as non-executable statements.

QUESTION 6

a) Debugging Debugging is the process of fixing, cleaning, and/or correcting a bug in the software. It can be defined as identifying, analyzing, and removing errors. This activity begins after the software fails to execute properly and concludes by solving the problem and successfully testing the software.

b) Differences between Design time and Run time Run time is the period time when a program is running. It begins when a program is opened (or executed) and ends with the program is quit or closed. Design Time refers to either the operations performed by a compiler, programming language requirements that must be met by source code for it to be successfully compiled, or properties of the program that can be reasoned about at design time. The operations performed at design time usually include syntax analysis, various kinds of semantic analysis, and code generation. Programming language definitions usually specify design-time requirements that source code

REFERENCES

Runtime. (n.d.). Retrieved March 18, 2021, from https://techterms.com/definition/runtime

Gaddis, T. (2019, November 21). (PDF) starting out with Java, 6th edition. Pp 54 Retrieved March 18, 2021, from https://www.thefreestudy.com/pdf-starting-out-with-java-6th- edition/

Errors in C/C++. (2019, April 01). Retrieved March 18, 2021, from https://www.geeksforgeeks.org/errors-in-cc/

Liang, Y. (n.d.). Introduction to programming with C++ ... 3rd edition. Retrieved March 18, 2021, from https://www.redshelf.com/book/61432/introduction-to-programming-with- c-61432-9780133253160-y-daniel-liang

Differences between testing and debugging. (2020, February 27). Retrieved March 18, 2021, from https://www.geeksforgeeks.org/differences-between-testing-and-debugging/