Skip to content

Computers and Programming

Chapter 1

Only the first two weeks contain theses slide-based videos. After that, you will see more demonstration videos and resources.

This looks like a lot of videos, but each video is not very long (about 55 minutes total).

What is a computer?

  • One that computes (makes calculations).

  • A programmable computer is an electronic device that:

    1. Retrieves numerical data
    2. Stores numerical data
    3. Performs arithmetic or logical operations on numerical data
    4. Outputs numerical data
NACA (NASA) - Dryden Flight Research Center “Computer Room” (1949)
NACA (NASA) - Dryden Flight Research Center “Computer Room” (1949)

Hardware

Hardware components
  • Input devices feed data and programs into computers
    • Keyboard
    • Mouse
  • Output devices display results
    • Monitor
    • Printer
    • Network Interface Card (NIC) (input/output)
  • Central Processing Unit (CPU)
    • Brain of the computer
    • Usually, the most expensive piece of hardware
    • Carries out arithmetic and logical operations
    • Commonly a single chip called a microprocessor.
  • Main memory (RAM)
    • Main memory is an ordered sequence of memory cells.
      • Each cell has a unique location in main memory, called the address of the cell
      • Also called primary storage or physical memory
    • Each cell can contain either a programming instruction or data.
  • Secondary storage: device that stores information permanently
    • Hard drives
    • Flash drives
    • CDs
    • Tapes

Software

Software: programs that do specific tasks. There are two types of software.

  1. System programs control the computer.
    • Operating system monitors the overall activity of the computer and provides services such as:
      • Memory management
      • Input/output activities
      • Storage management
  2. Applications perform a specific task. For example,
    • Word processors
    • Web browsers
    • Games

What does a computer understand?

The language of computers.

Two Types of Signals

  1. Analog signals: continuous wave forms
  2. Digital signals: sequences including only a finite set of values (generally only 0s and 1s, which is call Binary).
Examples of Analog and Digital Signals
Examples of Analog and Digital Signals

Binary

  • Machine language: language of a computer a binary sequence (0s and 1s).
  • Binary digit (bit): the digit 0 or 1
  • Binary code (binary number): a sequence of 0s and 1s
Decimal0123456789
Binary01101110010111011110001001
  • Bit: A binary unit (can be either 0 or 1)
  • Byte: A sequence of eight bits
  • Kilobyte (KB): 210 bytes = 1024 bytes
  • ASCII (American Standard Code for Information Interchange)
    • 128 characters
    • A is encoded as 01000001 (65th ASCII character)
    • 3 is encoded as 00110011 (51st ASCII character)
UnitSymbolSizeSize in BytesSize in Bytes
Byte8 bits1
KilobyteKB bytes1024
MegabyteMB KB1024 KB1,048,576
GigabyteGB MB1024 MB1,073,741,824
TerabyteTB GB1024 GB1,099,511,627,776
PetabytePB TB1024 TB1125899,906,842,624
ExabyteEB PB1024 PB1,152,921,504,606,846,976
ZettabyteZB EB1024 EB1,180,591,620,717,411,303,424
YottabyteYB ZB1024 ZB1,208,925,819,614,629,174,706,176

The Evolution of Programming Languages

  • Early programmed written in machine language
  • To calculate wages = rate × hours, where the rate is 20 and wages is 40 in machine language:
Machine CodePurpose
11000111 01000101 11111100 00010100Set rate to 20
11000111 01000101 11111000 00101000Set hours to 40
00000000 10001011 01000101 11111100Move the rate for multiplication
00001111 10101111 01000101 11111000Multiply the rate by the hours
00000000 10001001 01000101 11110100Store the results in wages

Using assembly language instructions,
rate = 20
hours = 40
wages = rate × hours
can be written as:

Assembly CodePurpose
mov 20, ecxSet rate to 20
mov 40, edxSet hours to 40
mov eax, ecxMove the rate for multiplication
imul eax, edxMultiply the rate by the hours
mov DWORD PTR [r8], eaxStore the results in wages
  • High-level languages include FORTRAN, COBOL, Basic, Pascal, C, C++, Java, Python, and C#.
  • Compiler: translates a program written in a high-level language into machine language
  • The equation, wages = rate × hours, can be written in C++ as:
    rate = 20;
    hours = 40;
    wages = rate * hours;

Introducing C++

  • Without software, the computer is useless.
  • Software is developed with programming languages like C++.
  • C++ is suited for a wide variety of programming tasks with a focus on:
    • Performance
    • Efficiency
    • Flexibility of use

How does a C++ program run?

Processing a C++ Program

C++ Example Program

/*
 * Displays the message: "Hello World!"
 */
#include <iostream>
using namespace std;
int main()
{
    cout << "Hello World!" << endl;
    return 0;
}

Program Output when Run

Hello World!
Processing a C++ Program
The steps to process a C++ program
  1. Create a plain-text file with the source program in C++
  2. Preprocessor directives begin with # and are processed by the preprocessor.
  3. Use the compiler to:
    • Check that the program obeys the language rules.
    • Translate into machine language (object program).
  4. Linker:
    • Combines object program with other programs provided by a Software Development Kit (SDK) to create executable code.
    • Library: contains prewritten code you can use
  5. Loader: Loads executable program into main memory.
  6. The last step is to execute the program.
  • Some IDEs (like Visual Studio) compile, link, and run with single Build or Rebuild command.
  • IDE = Integrated development environment

An Early History of Computing

This is a great overview of the early computing, which is included in Chapter 1. You may skip to 2 minutes 27 seconds into the video to start.