Chapter 2: Programming Basics Flashcards
Week 1
Why do we program? What is a program in the first place?
A program exists to solve a pre-existing problem.
Since the advent of the computer, many of society’s problems have been solved, such as:
- Inefficient paper filing systems
- Difficult access to entertainment.
- Slow communication.
Week 1
List the problems one must consider when programming.
Listed below are the questions one must ask oneself before programming.
- What problem to solve?
- Who to design for?
- Who can collaborate with it/communicate using it?
Week 1
Why is programming important?
- It is fun
- It is more than vocational
- By designing programs, we learn skills that can be applied in numerous fields.
Week 1
What is computational thinking?
Computational thinking refers to the thought processes involved in formulating problems so their solutions can be represented as computational steps and algorithms.
Listed below are the steps to engage in computational thinking.
- Collect data.
- Analyze data.
- Find patterns.
- Decompose problems.
- Abstract.
- Build models.
- Desktop algorithms.
Week 2
Explain the function of the following C++ command
#include <iostream> #include ”accounts.h”
The #include
directive in C++ is used to include external files and/or libraries in your program.
In this case, the line of code instructs the program to include a standard library header named iostream
and a custom header file named accounts
All header files use a .h extension
The use of angle brackets (<>) signifies that you are including a system or standard library header. Custom header files are encased in quotations (“”)
In short, this line of code instructs the program to include external files that contain other functions and/or variables.
Week 2
What is the difference between using angle brackets (<>) and quotations (“”) in the #include
directive?
Let’s look at two examples here
#include <vector> #include "custom.h"
The first command instructs C++ to include a standard library header (SLH) vector
that comes with the language itself i.e. it does not need to be created by the programmer.
The second command instructs C++ to include a custom header file custom.h
that the programmer has already created and stored somewhere.
Week 2
What is an algorithm?
An algorithm is a set of instructions designed to solve a specific problem or perform a particular task.
It’s like a recipe that guides a computer or person through a series of logical actions to achieve a desired outcome.
Algorithms are a fundamental concept in computer science and are used to solve problems, make decisions, and process data efficiently.
Week 2
Explain the function of the following code snippet
#include <iostream> int main() { int A = 5; int B = 6; int sum = A + B; std::cout << "The sum is: " << sum << std::endl; return 0; }
-
#include <iostream>
: the function of this command is to include a SLH that facilitates all input/output stream operations. -
int main() {}
is a command where the program essentially starts executing instructions. -
int A
andint B
are assigned their respective values. - Another integer variable
sum
is declared.sum
contains the sum ofint A
andint B
.
std::cout << "The sum is: " << sum << std::endl;`
- The code snippet above basically instructs the language to output the value stored in the
sum
variable along with contextual text. - We’ve essentially created a simple calculator that can add two numbers and output the sum.
Week 2
List common pseudocode conventions.
- Indentation: Use indentation to represent control structures like loops and conditionals. This helps visualize the flow of the algorithm.
- Variables: Declare variables and assign values using a colon or arrow (: or ->).
- Operations: Use standard mathematical notations (+, -, *, /, etc.) for operations.
- If-Else: Use if, else if, and else for conditional statements.
- Looping: Use for, while, or repeat for loops.
- Declare functions and procedures with a keyword.
- Specify parameters and return types if needed.
- Use input or similar keywords for taking input.
- Use output or similar keywords for displaying output.
- Comments: Use plain language comments to explain complex parts of the algorithm.
- Naming Conventions: Use meaningful names for variables, functions, and procedures to improve clarity.
- Flow Control Keywords: Use words like break, continue, and return to indicate flow control actions.
- Boolean Logic: Use AND, OR, NOT or their symbols (&&, ||, !) for logical operations.
- Initialization: Explicitly show variable initialization.
- Termination: Indicate the end of the algorithm with a clear keyword or marker.
Week 2
What is the function of the return 0;
command in C++
In C++, return 0
; is a statement commonly used in tandem with the int main()
function.
Its solitary purpose is to signal to the operating system that the program has successfully completed execution.
This convention comes from the historical practice where a return value of 0 indicates success and non-zero values indicate various error conditions or issues.
Week 2
Name the operators in C++
The operators used to perform arithmetic operations in C++ fall into the following categories: High precedence, and low precedence
Types of Low Precedence Operators
- Addition (+)
- Subtraction (-)
Types of High Precedence Operators
- Multiplication (*)
- Division (/)
- Modulus (%)
- (Parentheses) take the highest precedence regardless
C++ will always prioritize high-precedence operations while executing an arithmetic sequence.
If C++ executes two operations with the same precedence, it will execute them from left to right, in sequence.
Week 2
What is the function of the mod operator?
The mod (%) operator in C++ returns the remainder of division, useful for checking even/odd, cycling values, and time wrapping.
Explain the function of the following program
#include<iostream> int main () { int n = 19; int u = n % 10; int d = n / 10; int rev = u * 10 + d; std::cout<<"reverse of "<<n<< " = "<<rev<<std::endl; return 0; }
#include<iostream>
This command asks the program to include the SLH named iostream, which enables input/output operations with the console.
int main () {
This serves as the entry point for the program execution. At this point, the program starts executing instructions.
int n = 19; int u = n % 10; int d = n / 10; int rev = u * 10 + d;
These series of commands declare integer variables and store all the calculations required to store the inverse of int n
std::cout<<"reverse of "<<n<< " = "<<rev<<std::endl;
This command line asks the program to output the value of int rev along with a string of text.
return 0;
This command line returns error code 0 to the operating system, which indicates to it that the program has successfully executed.
Week 2 (L) / Week 3
How many bits do different data types take up in C++?
First off, let’s define all the ARM data types for 32-bit and 64-bit systems.
- A byte consists of 8 bits.
- A word consists of 32 bits.
- A half word consists of 16 bits.
- A double word consists of 64 bits.
- A quad word consists of 128 bits.
Now, let’s define the capacity of several data types in C++ in terms of the aforementioned ARM conventions.
Primitive Data Types
- int : word (32 bits)
- short : half-word (16 bits)
- long : double word (64 bits)
- char : byte (8 bits)
- float : word (32 bits)
- double : double word (64 bits)
- boolean : byte (8 bits)
- void : double word (64 bits)
The “string” data type
Unlike its counterparts, string is a dynamic data type that occupies storage based on how many characters are stored in it.
Each character occupies a byte, so, for example, 10 characters would occupy 10 bytes or 80 bits. So, if 10 characters are stored in a string variable, that variable will occupy 10 bytes of storage.
Week 3
List different types of software.
For a detailed explanation with exact definitions and infographics, visit this link.
Computer software can be divided into two subcategories: application software and system software
System Software
System software is designed to communicate with the hardware of your system, hence, you don’t interact with it that often; it acts as a messenger between your application software and your system software.
The types of system software are as follows:
- Operating systems
- Device drivers
- Utility programs
Types of Application Software
Application software is designed to be operated by a human user in order to allow them to communicate with a computer, instruct it to perform specific actions, and read the output of said actions, if any.
Application software can be divided into two categories:
- Specific application software
- General purpose application software
Week 3
What is an operating system (OS)?
An operating system is a type of system software that allows the user to communicate with the hardware of the computer.
The OS instructs the hardware to open different software, perform different actions ( such as copy/paste), and enumerate different mathematical calculations based on the user’s input.
The OS essentially serves as a translator with the human (the user) and the machine (the hardware).
Week 3
Where is the OS stored?
In the HDD/SSD of your computer.
Week 3
What are the different types of operating systems?
Command Line Operating Systems
In a command-line interface, the use types keywords or press special keys as a keyboard command to enter data and instructions. The instruction set used to communicate with the computer is called the command language
Command-line interfaces, albeit efficient, are very difficult to interpret and learn for a layman; the necessity of an easy-to-use operating system prompted the invention of Graphical User Interfaces (GUI)
The Graphical User Interface
As a graphical user interface does not need you to memorize the command language, it is easier to understand and use the command-line interface.
The Graphic User Interface (GUI) allows you to allocate a command to a graphical object.
Some examples of very popular GUIs are as follows:
- Windows
- Linux
- macOS
- Ubuntu
Week 3
Define booting.
The process of loading the operating system (OS) into the computer’s memory upon startup so that it can be used.