Unit 1 Notes: Introduction to Computers and Programming (CS1)

1.1 Why Program?

  • Computer: a programmable machine designed to follow instructions. So, without programmers, no programs; without programs, a computer cannot do anything!

  • Programmer: a person who writes instructions (programs) to make the computer perform a task.

  • Program: instructions in computer memory to make it do something.

  • Example (typical starting C++ program):

// A standard Hello World program (typical starting point)
#include <iostream>
using namespace std;

int main() {
    cout << "Hello World\n";
    return 0;
}
  • Note: The transcript shows a common Hello World snippet with a formatting issue; the corrected form above reflects a conventional, compilable example.

1.2 Computer Systems: Hardware and Software

  • Hardware vs Software: the two broad categories of computing components.

  • Hardware includes the physical components of a computer.

  • Software includes programs and data that run on hardware.

  • Hardware main categories (as presented):

    • Central Processing Unit (CPU)

    • Main Memory (RAM)

    • Secondary Memory / Storage

    • Input Devices

    • Output Devices

  • Software categories:

    • Application software: programs that provide services to the user (word processors, games, problem-solving programs).

    • System software: programs that manage the computer hardware and the programs that run on them (operating systems, utilities, development tools).

Main Hardware Component Categories (Figure 1-2)

  • 1) Central Processing Unit (CPU)

  • 2) Main Memory RAM

  • 3) Secondary Storage Devices

  • 4) Input Devices

  • 5) Output Devices

  • Watch/Refer: How does Computer Hardware Work? (video resource in the transcript)

1- Central Processing Unit (CPU)

  • CU (Control Unit): retrieves and decodes program instructions; coordinates activities of all other parts of the computer.

  • CPU is the brain of a computer.

  • ALU (Arithmetic & Logic Unit): hardware designed for true/false, yes/no decisions; hardware optimized for high-speed numeric calculation.

CPU Organization

  • Diagram concepts (textual description):

    • Input (Instruction) → Central Processing Unit → ALU / CU → Output (Result)

    • Includes supporting elements: CACHE, MEMORY, REGISTERS

  • Terms visible in the diagram: CPU, ALU, CU, CACHE MEMORY, L-1 REGISTERS

2- Main Memory

  • Characteristics:

    • Volatile: main memory is erased when the program terminates or the computer is turned off.

    • RAM is the common form of main memory.

  • Addresses: Each byte in memory is identified by a unique address; a byte consists of 8 consecutive bits.

  • Bits and bytes:

    • bit: smallest piece of memory; values are 0 (off/false) or 1 (on/true).

  • Organization: memory is addressed by bytes; commonly referred to as RAM when discussing main memory.

Main Memory (in Figure 1-6) sample statement

  • Example: The number 149 is stored in the byte with address 16, and the number 72 is stored at address 23.

3- Secondary Storage

  • Non-volatile: data retained when the program is not running or the computer is turned off.

  • Media types:

    • Flash drives: connected via USB port.

    • Optical: CD-ROM, DVD.

    • Solid-state: SSDs (data stored in chips, no moving parts).

    • Magnetic: traditional hard drives that use moveable mechanical arms to read/write.

4- Input Devices

  • Devices that send information to the computer from outside.

  • Examples: Keyboard, mouse, touch-screen, scanner, digital camera, microphone.

  • Other input sources: Disk drives, CD drives, and DVD drives can provide input as well.

5- Output Devices

  • Devices that display information from the computer to the outside.

  • Examples: Monitor, printer, projector, numeric display, speaker, plotters.

  • Output options include Disk drives and USB flash drives (as data destinations).

Software – a program that runs on Computers

  • Categories:

    • Application software: programs that provide services to the user (word processors, games, problem-solving programs).

    • System software: programs that manage the computer hardware and the programs that run on them (operating systems, utility programs, software development tools).

1.3 Programs and Programming Languages

  • A program is a set of instructions that the computer follows to perform a task.

  • To write a program, we usually start with an algorithm, which is a set of well-defined steps.

  • Example snippet (Hello World) is shown again in the transcript and is characteristic of introducing C++ language concepts.

Algorithm for Gross Pay (Example)

1) Display a message on the screen asking, “How many hours did you work?”
2) Wait for the user to enter the number of hours worked; store it in memory.
3) Display a message on the screen asking, “How much do you get paid per hour?”
4) Wait for the user to enter an hourly pay rate; store it in memory.
5) Multiply the number of hours by the amount paid per hour and store the result in memory.
6) Display a message that tells the amount of money earned (the result of Step 5).

  • Formula: pay=hours×rate\text{pay} = \text{hours} \times \text{rate}

Machine Language

  • Although the algorithm defines steps, the computer can only execute machine language instructions.

  • Machine language instructions are binary numbers.

  • Humans typically write in higher-level languages and rely on translation tools to machine code.

  • Example binary string (as shown in transcript):
    001000000010001000000000101011110001000000010001000000000101011110

Programs and Programming Languages — Types

  • Types of languages:

    • Low-level: direct communication with computer hardware; often written in binary machine code.

    • High-level: closer to human language; easier to read/write.

  • Visual representation in the transcript:

    • High level ⇄ Low level, with examples such as binary sequences like 10100010111010111010001011101011

Some Well-Known Programming Languages

  • Java, C, FORTRAN, Visual Basic, Ruby, COBOL, C++, BASIC, C#, JavaScript, Python

From High-Level Program to Executable File

a) Create file containing the program with a text editor.
b) Run preprocessor to convert #include directives and other directives to source code statements.
c) Run compiler to convert source program into machine instructions.
d) Run linker to connect hardware-specific code to machine instructions, producing an executable file.
e) Steps b–d can be performed by a single command or button click in modern environments.
f) Errors at any step will prevent execution of the following steps.

Example flow (high-level view) — Code and workflow

#include <iostream>
using namespace std;
int main() {
    // program that prints a message or performs a simple calculation
    return 0;
}
  • The transcript shows a modified flowchart/diagram: Preprocessor → Source Code → Compiler → Object Code → Executable Code, or C++ program flow in an IDE environment.

Integrated Development Environments (IDEs)

  • IDEs combine all the tools needed to write, compile, and debug a program into a single application.

  • Examples: MS Visual Studio, Code::Blocks, Eclipse, etc.

  • The transcript includes a sample IDE window (Solution Explorer, Editor, Debug tools) demonstrating a simple pay-calculation project named Example1 with the file Example1.cpp.

1.4 What is a Program Made of?

  • Common elements in programming languages:

    • Syntax

    • Punctuation

    • Operators

    • Programmer-Defined Identifiers

    • Keywords

Program 1-1 — Example and Mapping

// This program calculates the user's pay.
#include <iostream>
using namespace std;

int main() {
    double hours, rate, pay;
    // Get the number of hours worked.
    cout << "How many hours did you work?";
    cin >> hours;
    // Get the hourly pay rate.
    cout << "How much do you get paid per hour?";
    cin >> rate;
    // Calculate the pay.
    pay = hours * rate;
    // Display the pay.
    cout << "You have earned $" << pay << endl;
    return 0;
}
  • A high-level mapping of the program steps (as shown in the transcript):

    • 1: Start Program

    • 2: Declare Variables hours, rate, and pay

    • 3: Print “How many hours did you work?”

    • 4: Read & Assign Variable hours

    • 5: Print “How much do you get paid per hour?”

    • 6: Read & Assign Variable rate

    • 7: Multiply hours & rate, and Assign to pay

    • 8: Print “You have earned” and the variable pay

    • 9: End Program

Keywords

  • Keywords (reserved words) have special meaning in C++ and cannot be used for other purposes.

  • Examples of keywords in C++ (as listed in the transcript):

    • using, namespace, int, double, return

  • Additional keyword list (as shown): auto, double, int, struct, break, else, long, switch, case, enum, register, typedef, char, extern, union, continue, for, signed, void, do, if, static, while, default, goto, sizeof, volatile, const, float, short, unsigned

Programmer-Defined Identifiers

  • Names created by the programmer (not part of the C++ language itself).

  • Used to represent various things: variables, functions, arrays, etc.

  • In Program 1-1: hours, rate, and pay are examples of programmer-defined identifiers.

Operators

  • Operators perform operations on data. Major types:

    • Arithmetic: +,ext−,imes,\+, ext{ }-, imes, \backslash

    • Assignment: ==

  • In Program 1-1, operators seen include the shift operators (<<, >>) and the multiplication operator (∗*).

Punctuation

  • Punctuation marks that end statements or separate items:

    • Comma ","

    • Semicolon ";"

  • In Program 1-1, these appear in statements such as variable declarations and input/output lines.

Syntax and Variables

  • Syntax: rules of grammar for writing a program; controls use of keywords, operators, identifiers, and punctuation.

  • Variables: named storage locations in memory for holding data.

  • In Program 1-1, three variables were used:

    • hours: used to hold hours worked

    • rate: used to hold pay rate

    • pay: used to hold calculated gross pay

  • Variable declarations example (double precision): double hours, rate, pay;\text{double hours, rate, pay;}

Variables — Declarations

  • A variable definition (declaration) creates a variable and specifies its type.

  • The declaration defines the kind of data it can hold and its name.

  • In 1-1, the line double hours, rate, pay;\text{double hours, rate, pay;} defines three double-precision variables.

Data Types and Memory (Preview)

  • There are many data types; the course notes indicate that more will be learned in the next unit.

  • The variable definition ties to the data type, which determines how much memory is allocated and what kind of values can be stored.

1.5 Input, Processing, and Output

  • Three steps that a typical program performs:

    • Input: gather data from sources such as files or the keyboard

    • Processing: compute or manipulate the data

    • Output: display results or write to files

  • Examples of input sources: keyboard, files on disk drives.

  • Processing may involve arithmetic, data transformation, or decision logic.

  • Output destinations can be the screen (display) or files on disk drives.

1.6 The Programming Process

1) Clearly define what the program is to do.
2) Visualize the program running on the computer.
3) Use design tools like flowcharts or pseudocode to create a model of the program.
4) Check the model for logical errors.
5) Type the code, save it, and compile it.
6) Correct any errors found during compilation. Repeat Steps 5 and 6 as necessary.
7) Run the program with test data for input.
8) Correct any errors found while running the program. Repeat Steps 5 through 8 as many times as necessary.
9) Validate the results of the program.

1.7 Procedural and Object-Oriented Programming

  • Procedural programming: focus is on the process; procedures/functions are written to process data.

  • Object-Oriented programming: focus is on objects, which contain data and the means to manipulate the data; messages are sent to objects to perform operations.

End Unit 1

  • This marks the conclusion of Unit 1: Introduction to Computers and Programming, as presented in the transcript.