Computer Programming Concepts PDF

Summary

This document covers essential concepts in computer programming. Topics include programming languages, object-oriented programming (OOP), data types, and software applications. It explains key features, provides examples, and discusses various aspects of programming.

Full Transcript

1. what is computer programming? Computer programming is the process of writing instructions (code) that a computer can execute to perform specific tasks. 2. Discuss the following types of Computer Programming Languages with examples: i. Procedural Programming Languages...

1. what is computer programming? Computer programming is the process of writing instructions (code) that a computer can execute to perform specific tasks. 2. Discuss the following types of Computer Programming Languages with examples: i. Procedural Programming Languages ii. Functional Programming Languages iii. Low Level Programming Languages iv, High Level Programming Languages I. Procedural Programming Languages Procedural programming languages follow a step-by- step approach where a program is divided into procedures (or functions). E.g. C. ii. Functional Programming Languages Functional programming languages focus on mathematical functions to perform tasks. They avoid changing variables (immutability) and emphasize pure functions, where the output depends only on the input. E.g. haskell iii. Low Level Programming Languages Low-level programming languages are closer to machine language and provide direct access to hardware. They are fast and efficient but harder to write and understand. E.g. Assembly iv. High-Level Programming Languages High-level programming languages are designed to be easy to read, write, and understand. They use human-like syntax and handle complex operations behind the scenes, making them more user-friendly. E.g. python. 3. Discuss the concept of object-oriented programming Object-Oriented Programming (OOP) is a programming approach that organizes code into objects, which contain data (attributes) and functions (methods) that work on the data. It helps make programs more structured, reusable, and easier to manage. 4. Discuss the following features of object-oriented programming. i. Abstraction 2. Encapsulation 3. inheritance 4. polymorphism Abstraction: Hiding unnecessary details and showing only the essential features of an object. Encapsulation: Hiding an object's data and allowing access only through methods to protect it. Inheritance: Allowing a class to inherit properties and methods from another class, promoting code reuse. Polymorphism: Allowing a single method to behave differently depending on the object it is applied to. 5. What is a computer program? A computer program is a set of instructions written in a programming language that tells a computer what to do. 6. list down ways you use computer regularly. Browsing the Internet – Checking emails, social media, or researching topics. Writing Documents – Using word processors like Microsoft Word or Google Docs. Watching Videos – Streaming movies or videos on platforms like YouTube. Playing Games – Playing video games or mobile games. Coding – Writing and testing programs or learning new programming languages. Managing Files – Storing, organizing, and backing up files on the computer. 6. Discuss with examples the following types of computer. 1. system software 2. software application 3. utility software. 1. System Software – Software that helps the computer run and manage its hardware. Examples: Windows, Linux, macOS, Printer drivers. 2. Application Software – Software designed for users to perform specific tasks. Examples: Microsoft Word, Google Chrome, Spotify. 3. Utility Software – Software that helps improve the computer’s performance and security. Examples: Antivirus (Avast), Disk Cleanup (CCleaner), Backup Software (Google Drive). 7. Discuss the following object-oriented programming concepts Classes – A class is a blueprint for creating objects. It defines the attributes (data) and methods (functions) that objects will have. Functions (Methods) – Functions inside a class (called methods) define the behavior of objects. They allow objects to perform actions. Objects – An object is an instance of a class. It has the properties and behaviors defined in the class. What is a Data Type? A data type defines the kind of data a variable can store in a programming language. It tells the computer how much memory to allocate and what operations can be performed on the data. A primitive data type is a basic type of data built into a programming language that stores a single value and does not have methods or properties. Five examples of primitive data types in Java are: 1. int – Stores whole numbers, e.g., int age = 25; 2. double – Stores decimal numbers, e.g., double price = 19.99; 3. char – Stores a single character, e.g., char grade = 'A'; 4. boolean – Stores true or false values, e.g., boolean isStudent = true; 5. float – Stores smaller decimal numbers, e.g., float height = 5.8f; A composite data type is a complex type that can store multiple values or a collection of data in a structured way. Public: When a member (class, method, or variable) is declared as public, it can be accessed from anywhere in the program, both inside and outside the class. Private: A member declared as private is only accessible within the same class. It cannot be accessed from outside the class. Protected: A member declared as protected can be accessed within the same package and by subclasses, even if they are in different packages. Default (No Modifier): If no access modifier is specified, it is considered default. This means the member is accessible only within the same package. High-Level Language: A programming language that is easy for humans to read and write, using simple, readable syntax. It is abstracted from the hardware. Examples include Java, Python, and C++. Machine Language: The lowest-level programming language, consisting of binary code (1s and 0s) that the computer's hardware can directly understand and execute. Assembly Language: A low-level language that uses human-readable codes (called mnemonics) to represent machine-level instructions. It is slightly easier to read than machine language but still closely tied to the hardware. Method: A block of code that performs a specific task and can be called to execute. Declaration: The process of defining a variable, method, or class by specifying its type and name. Initialization: The process of assigning a value to a declared variable or object. Argument: A value passed to a method when it is called. Class: A blueprint for creating objects, defining their properties and behaviours.