0% found this document useful (0 votes)
646 views5 pages

GET 211 - Computing and Software Engineering-N1

Uploaded by

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

GET 211 - Computing and Software Engineering-N1

Uploaded by

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

Introduction to Computer Programs

Computer programming is the act of writing computer programs.


A computer program is a sequence or set of instructions written
in a specific [Computer] Programming Language that a
computer can interpret and execute, so as to perform a task or
solve a problem. There exist several computer-programming
languages to provide instructions to the computer (i.e., to write
computer programs). Example: C, C++, Python, MATLAB, Java,
etc.

Simple program written in Python programming Language −


print("Hello, World!")
The above computer program instructs the computer to print
"Hello, World!" on the computer screen.

Algorithm
An algorithm is a step-by-step procedure to resolve any problem.
An algorithm is an effective method expressed as a finite set of
well-defined instructions.

A simple example of an algorithm to find out the largest number


from a given list of numbers −

1. Get a list of numbers L1, L2, L3....LN


2. Assume L1 is the largest, Largest = L1
3. Take next number Li from the list and do the following
4. If Largest is less than Li
5. Largest = Li
6. If Li is last number from the list then
7. Print value stored in Largest and come out
8. Else repeat same process starting from step 3

Assignment - Write the above algorithm in a simple MATLAB


& Python code.
Programs serve as the backbone of software development,
enabling computers to process data, automate tasks, and deliver
user-friendly applications.

In its human-readable form, a computer program is called source


code. Since computers can only execute native machine
instructions, source code requires translation or interpretation to
be executed.

- Translation to Machine Instructions: Source code is often


converted into machine instructions using a compiler designed
for the programming language. The output of this process is
called an executable file. For assembly language programs, this
translation is done using an assembler.
- Execution via Interpreter: Alternatively, source code can be
executed directly within an interpreter written for the
programming language, without being compiled into an
executable.

When an executable file is run, the operating system loads it into


memory and initiates a process. The CPU then switches to this
process, fetching, decoding, and executing each machine
instruction.

If source code is run instead, the operating system first loads the
interpreter into memory and starts a process. The interpreter
then loads the source code, translating and executing each
statement in real-time. This approach is slower than running an
executable and requires the interpreter to be installed on the
computer.

Computer Programming Languages are made of several


elements (as Human Interface Language - English Language
have verbs, nouns, adjectives, adverbs, propositions, and
conjunctions, etc.).
Basic elements of programming languages include −
1. Programming Environment: The setup, tools, and interfaces
required for writing, testing, and executing programs.
2. Basic Syntax: The set of rules that defines the structure and
format of valid code in a programming language.
3. Data Types: Categories of data (e.g., integers, floats, strings)
that determine the kind of value a variable can hold.
4. Variables: Named storage locations in memory used to hold
data values.
5. Keywords: Reserved words in a programming language that
have predefined meanings (e.g., `if`, `while`).
6. Basic Operators: Symbols or words used to perform
operations (e.g., addition `+`, comparison `==`).
7. Decision Making: Constructs like `if` or `switch` that allow
programs to execute specific code blocks based on conditions.
8. Loops: Structures (e.g., `for`, `while`) that repeat code
execution while a condition holds true.
9. Numbers: Data types representing numerical values, such as
integers or floating-point numbers.
10. Characters: Single symbols or letters, typically represented
using character data types.
11. Arrays: Collections of elements of the same type stored in
contiguous memory locations.
12. Strings: Sequences of characters treated as text.
13. Functions: Reusable blocks of code designed to perform
specific tasks and optionally return a result.
14. File I/O: Mechanisms for reading from and writing data to
files.

Assignment: Study the above elements in more details through


this link - Click Me!

Python program with implementation of the elements:

# Programming Environment: Python (write, test, and execute in


an IDE or editor)

# Basic Syntax: Python uses indentation for blocks


# Variables and Data Types
name = "Alice" # String
age = 25 # Number (integer)
grades = [85, 90, 78] # Array (list in Python)

# Keywords and Decision Making


if age >= 18:
print(f"{name} is an adult.") # String and Characters
else:
print(f"{name} is not an adult.")

# Loops
print("Grades:")
for grade in grades: # Loop through the array
print(grade)

# Basic Operators
average_grade = sum(grades) / len(grades) # Arithmetic
operator
print(f"Average Grade: {average_grade}")

# Functions
def greet_user(username):
return f"Hello, {username}!"

print(greet_user(name))

# File I/O
with open("output.txt", "w") as file: # File writing
file.write(f"Name: {name}\n")
file.write(f"Age: {age}\n")
file.write(f"Average Grade: {average_grade}\n")
print("Data written to 'output.txt'.")
```
Explanation of Elements Used:
1. Programming Environment: The code can be written and
executed in a Python IDE or text editor.
2. Basic Syntax: Proper indentation and syntax rules are
followed (e.g., `if` conditions, loops).
3. Data Types: Strings (`"Alice"`), integers (`25`), and a list
(`[85, 90, 78]`).
4. Variables: `name`, `age`, and `grades` store data values.
5. Keywords: `if`, `else`, `for`, `def`, `with` are Python reserved
keywords.
6. Basic Operators: Arithmetic (`+`, `/`), comparison (`>=`).
7. Decision Making: An `if-else` block checks if the user is an
adult.
8. Loops: A `for` loop iterates through the grades.
9. Numbers: Used for age and grades.
10. Characters: Included in strings (e.g., names, messages).
11. Arrays: Represented by a Python list, `grades`.
12. Strings: Used for textual output and file writing.
13. Functions: `greet_user` demonstrates a reusable function.
14. File I/O: Writes the user’s data to a file named `output.txt`.

Assignment - Clearly using the above elements, write a simple


program in Python and MATLAB that:
1. Accepts the following inputs; A= your Reg. Number, B = 2, C
= 3, D = your Reg. Number in reverse
2. Multiply A by B
3. Divide ‘Answer in Question 2’ by C
4. Subtract ‘Answer in Question 3’ by D
5. Print the results for Questions: 2, 3, 4
NB: Use ‘comments’ within your code to show the elements
used.

You might also like