Overview - sheerazwalid/COMP-I GitHub Wiki

Computers

Computers are comprised of three main components:

  • Central Processing Unit (CPU)
  • Main Memory, also called random access memory (RAM)
  • Devices (disk drive, keyboard, monitor, etc.)

Main memory is a sequence of numbers represented with ones and zeros. These numbers are used to represent both instructions and data. The CPU executes the instructions, which results in reading and writing of memory and interaction with devices.

Programs

A collection of machine instructions that performs a task is called a program.

Programs are stored in files in persistent storage devices (disk drives, flash memory).

File Systems

The data in persistent storage devices are organized into file systems. File systems are typically presented to the user using a tree of expanding and contracting nodes.

Operating Systems

The operating system is a program that is loaded into memory and runs when the computer is turned on. The operating system loads and runs other programs as requested (or configured) by the user.

A running program is called a process.

Languages

Programs can be specified using computer languages. The instructions comprising a program are stored in files, which are referred to as source code.

There are different computer languages. In this course, we will study a language called C++.

C++ is evolving; we will use a version referred to as C++11. The number 11 in C++11 means the version was released in 2011.

Compilers

A compiler is a program that translates source code into programs. The input to a compiler are files containing human readable instructions (source code). The output of a compiler is a file that contains machine readable instructions (executable file).

To compile our C++ programs from the command line in Linux and OS X, use the following, where the source code is stored in a file named main.cpp.

c++ -std=c++11 main.cpp

Under windows, you can use Visual Studio, CodeBlocks or other development tool to compile source code. In these tools, you can select C++11 as the language version to use in a project settings window.

Most likely, you can ignore the C++ version when compiling source code in this course. In this case, the following command will do the job.

c++ main.cpp

Console programs

Programs that manipulate a window are window-based applications; programs that run inside terminal windows are called console programs. In this course, we will focus on console-based programs.

Hello Program

/*
    Comments are ignored by the compiler;
    they are meant to be read by humans.
    This is an example of a multi-line comment.
*/
#include <iostream>

using namespace std;

int main() {
    // This is another example of a comment.
    cout << "Hello.\n";
    return 0;
}

Spaces and line breaks increase readability.

// This program is equivalent to the one above.
// Line breaks and spaces are for improving readability;
// the compiler skips over them.
// However, the line break after the include statement is needed.
// Also, the space between "int" and "main" is also needed.
#include <iostream>
using namespace std;int main(){cout<<"Hello.\n";}

If you don't use the std namespace, then you need to prefix identifiers from that namespace with std:: See the following.

#include <iostream>

int main() {
    std::cout << "Hello.\n";
    return 0;
}

Additional Reading

Optional Videos

⚠️ **GitHub.com Fallback** ⚠️