Previous: Preface
Next: 2. Basic Data Representation in Computers
1 An Overview of Computer Hardware and Software Systems
In today's world, computers are not for specific group of users such as scientists, engineers, and data analysts. Computers are used in daily life from grade school students to government workers, homes to stores, from kitchen appliances to sophisticated machineries. In most occasions of computer utilization, a person uses a computer by running some software programs on hardware devices to do his/her jobs. In this chapter we give an overview of computer hardware and software systems.
1.1 Introduction to Computer Hardware Systems
A computer is a computing machinery which is used to process data and store data. Usually, a computer hardware system consists of four major units: processing unit, storage unit, input unit, and output unit. The figure below shows an example of a computer hardware system.
A processing unit of a computer, known as central processing unit (CPU), is like the brain of a computer which is in charge of all operations performed by a computer. A CPU is capable of carrying out arithmetic operations, logic operations, data loading/storing operations, and branching operations. More detailed description of a CPU is given in Section 3.1.
Storage units of a computer are used to store data that can be classified as internal storage and external storage. An internal storage unit can be directly accessed by a CPU; an external storage is usually a peripheral device which is indirectly accessed by a CPU through a device controller, or called a device drive. Examples of internal storage are cache memory, random access memory (RAM), and read-only memory (ROM); examples of external storage are floppy disk, hard disk, CD-Rom, and magnetic tape. More details of memory storage are explained in Section 3.2.
Input/output units are devices from/to which a computer receives/sends data. Most external storage devices are also considered as input/output units because data are transmitted from/to these devices. Examples of input units are keyboard, mouse, track ball, light pen, scanner, and digital camera. Examples of output units are liquid crystal display (LCD), headphone and printer. The data sent to or received from these devices may have contents of various formats such as text, image, audio and video data.Strictly speaking, computer networks are not computer device. A computer network is a collection of computers connected by coaxial cables, optical fibers, or wireless networking. However, a network card is used to send/receive data to/from other computers on a network. This network card is sometimes considered as an input/output unit.
1.2 Introduction to Computer Software Systems
In general, there are three categories of computer software: system software, application software, and user software A software system is basically a collection of computer programs that are prescribed to perform certain operations and functions.
The core system software is called an operating system. An operating system is said to be the heart of a computer. It is mainly responsible for resource management and task scheduling. Resource management is the control of hardware devices so they can work together with the CPU in harmony. Some operating system functions regarding resource management are receiving a keystroke signal and displaying a corresponding character on a monitor, loading/storing a file on a disk, memory management, sending/receiving data from the Internet. Task scheduling is the control of software programs so they can perform proper operations and response to hardware devices and to users. A computer usually runs a multitasking system, i.e., it may execute many programs concurrently. An operating system will schedule the tasks so each of the task can get a share of CPU time and memory resource. Some popular operating systems are Unix, Solaris, Linux, Android, iOS, and Microsoft Windows.
Application software is a system for performing certain computing tasks. A user can use a specific application software to accomplish his/her task. For example, an office suite such as Microsoft Office is a set of application programs. It includes a word processor called Word, a presentation software called PowerPoint, a spreadsheet called Excel, a database management system called Access, and a personal information manager and email system called Outlook. Another example is a computer game which is also an application software system.
User software is a system developed to provide users' specific needs. A user may write his/her own word processing macros, spreadsheet templates, or graphics scripts to meet his/her specific needs.
1.3 How to Develop a Software Program?
Developing a software program to solve a problem is like writing an article to tell a story. When write an article, we first organize the ideas of the story and than express the ideas in a language that the readers can understand. When develop a software program, we must first design the solution of a problem and than express the solution in a way that a computer can understand.
Designing the solution of a problem is to transform the problem into step by step procedures that are logically correct and satisfy the problem specification. For example, to add up a sequence of 100 numbers, one must consider how these numbers are represented and how to perform proper operations of of the summation. Mathematically, we can express the numbers abstractly as a1, a2, ¼, a100. Then, the sum of the sequence of numbers is written as an arithmetic formula a1+a2+¼+a100.
To solve the problem using a computer, one must think how this problem is represented and expressed in a computer. In a computer the sequence of numbers a1, a2, ¼, a100 and the sum are stored in memory and the formula a1+a2+¼+a100 must be expressed in a way that can be understood by a computer. That is, the solutions must be written in a "language" that a computer can understand. Like people communicate with a natural language such as Chinese, English, and Japanese, etc., a person communicate with a computer with a programming language such as FORTRAN, COBOL, C, Java, etc.
The study of a programming language are divided into three aspects: syntax, semantics, and pragmatics. Syntax is the form of a programming language that is the grammatical rules. Semantics is the meaning of language constructs. Pragmatics is the usage of a programming. In this course, we will focus on the study of C programming language. Especially, we will study syntax and semantic of C programming language.
1.4 Software Tool for Program Development
When we develop a software program, we must write the program using a software tool. Usually, there are two important tools are needed. The first tool is an editor on which we can enter the program text. Basically, any text editor, e.g., Microsoft Note and Ultra Editor will do the job. The program text is usually an English text which is not understood by a CPU. Then, another tool is a compiler which will be translated the programming text into a sequence of codes that a CPU can understand, i.e., can execute. Examples of compilers for C programming language are GNU C, Microsoft Visual C++, Turbo C++. In fact, a tool like Microsoft Visual C++ is a combination of an editor and a compiler. In this course we will use a free software tool called Dev-C++ by Bloodshed Software. Dev-C++ is also a tool consisted of an editor and a compiler, GNU C/C++ compiler.
Dev-C++ can be downloaded from the web site of Bloodshed Software. The following figure is the main window of Dev-C++:
The sub-window "Untitled1" is the editor area to enter program text. This window can be customized by clicking "Tools" and selecting "Editor Options".
The Dev-C++ will pop up a window allows you to customize the editor window. In the "Fonts" page, we can modify the font size and enable the line numbers of the editor.
In the "Colors" page, we can modify foreground and background presentation of various elements in the program text.
Now, we are ready to enter the program text as below. Note that the current file name is called "Untitled".
When the program text is entered completely, we click the circled icon to compile the program. Before the program is compiled, the file name should be changed to a new file name, e.g., "hello_world.c".
If the program is compiled without any error. The next step is to execute the program. To run a compiled program, we need to open a Microsoft command window and change the directory to where the program is. We assume the program is stored in "D:". To run the program, we simply type the program name "hello_world".
1.5 Basic Programming in C: "Hello World!"
Before we study C programming language, we start with a classical program hello_world.c. In this course material, we use the following format to present a program. The first column is the line numbers. The second column is the program text. The third column is the input and output of the program when it is executed. The red characters denote input data, and the green characters denote output data.
1 2 3 4 5 6 7 8 9 10 |
#include <stdio.h>
|
John Hello World! I am John. |
We will explain the program briefly in the following. Line 1 is a preprocessing directive which specify the program will include the standard input/output library called stdio.h. A C program many include several standard libraries and external C program header files. Each library or external header file must be placed in an #include directive at the beginning of the program.
Lines 3 to 10 are the main program which is a function called main. A C program is a collection of functions and it must have a main function. Line 3 is the function head. A function head consists a type of the returned value, name of the function, and a parameter list enclosed in the parentheses. Reserved word int specifies that the function will return an integer value and void indicates function main does not require any parameter. Line 4 is a variable declaration which declares a character array name of size 10 (maximum 9 characters).
Line 6 is an input statement, scanf is an input function in standard library stdio.h. Format specifier %s means to input a string and this string will be stored in array name indicated by the address operation &name. Line 7 is an output statement, printf is an output function in standard library stdio.h. "Hello World! I am %s.\n" is the data output by the program. Format specifier %s means to output a string stored in name. A list of frequently used format specifiers is given in the following table:
Specifier |
Type |
%c |
character |
%s |
character string |
%d |
integer |
%u |
unsigned integer (in decimal) |
%o |
unsigned integer (in octal) |
%x |
unsigned integer (in hexadecimal, lower case) |
%X |
unsigned integer (in hexadecimal, upper case) |
%f |
floating point number (in fixed-point notation) |
%E |
floating point number (in floating-point notation) |
Line 9 is a return statement. It means function main will return 0 when its execution is completed. The brackets at line 3 and line 10 that encloses the body of a function. Note that lines 4, 6, 7, and 9 all end with a semicolon which is used to denote the end of a declaration or a statement.
When run program hello_world, it will wait for the user to enter a string, e.g., John, and then outputs a string Hello World! I am John. We have shown a simple program performing an input and an output operations. More study of C programming language and program design will be discussed in the course material.
Previous: Preface