Bài giảng Introduction to Computer Programming (C language) - Chapter 1: Introduction to Computers and Programming - Võ Thị Ngọc Châu

Ho Chi Minh City University of Technology  
Faculty of Computer Science and Engineering  
Chapter 1: Introduction to  
Computers and Programming  
Introduction to Computer Programming  
(C language)  
TS. Võ Thị Ngọc Châu  
2017 – 2018, Semester 2  
Course Content  
C.1. Introduction to Computers and  
Programming  
C.2. C Program Structure and its  
Components  
C.3. Variables and Basic Data Types  
C.4. Selection Statements  
C.5. Repetition Statements  
C.6. Functions  
C.7. Arrays  
C.8. Pointers  
C.9. File Processing  
2
References  
[1] “C: How to Program”, 7th Ed. – Paul  
Deitel and Harvey Deitel, Prentice Hall, 2012.  
[2] “The C Programming Language”, 2nd Ed.  
– Brian W. Kernighan and Dennis M. Ritchie,  
Prentice Hall, 1988  
and others, especially those on the Internet  
3
Content  
Introduction  
Computer Organization  
Programming Languages  
Programming Tasks  
Data and Algorithms  
Summary  
4
Introduction  
Computer Programming  
Computer  
a device that can perform computations and make  
logical decisions billions of times faster than human  
beings can  
Programming  
The act of writing the programs executable on the  
computers to produce intended results  
Program  
A sequence of instructions written in a programming  
language to perform a specified task by the computer  
5
Introduction  
Programs and  
their Results  
6
Computers  
Programming  
Computer Organization  
Hardware: physical components of  
computer (including peripherals)  
the keyboard, screen, mouse, hard disk,  
memory, DVDs and processing units, …  
Software: a set of machine-readable  
instructions that directs a computer's  
processor to perform specific operations  
[Wikipedia]  
Application softwares  
Operating system  
System softwares  
7
Computer Organization -  
Hardware  
Computer Architecture  
ALU = Arithmetic/logic gate unit: performing  
arithmetic and logic operations on data  
8
Computer Organization –  
Software  
9
Programming Languages  
Programming language: a formal language  
for writing a computer program as a  
sequence of instructions  
C, C++, C#, Java, PHP, Python, …  
Three general types  
Machine languages  
Assembly languages  
High-level languages  
Providing a sequence of instructions that directly  
understandable by computers or requiring some  
intermediate translation steps  
10  
Programming Languages –  
Machine Languages  
First-generation language: strings of  
numbers (ultimately reduced to 1s and 0s)  
that instruct computers to perform their  
most elementary operations one at a time  
Directly understandable by computers  
Machine-dependent  
For example, instructions for  
adding overtime pay to base  
pay and then storing the  
result in gross pay  
11  
Programming Languages –  
Assembly Languages  
Second-generation language: a low-level  
language used to interface with computer  
hardware using English-like abbreviations  
to represent elementary operations  
Less understandable by computers  
Need for translation steps to convert an  
assembly language program to machine codes  
Translator = Assembler  
For example, instructions for  
adding overtime pay to base  
pay and then storing the  
result in gross pay  
12  
Programming Languages –  
High-level Languages  
Third-generation language: written  
instructions that look almost like everyday  
English and contain commonly used  
mathematical notations  
Less understandable by computers  
Translator program is called compiler.  
The C language is a high-level language that needs  
a compiler.  
Scripting languages such as PHP and Perl need an  
interpreter.  
For example, instructions for adding overtime pay to base pay and  
then storing the result in gross pay: grosspay = basepay + overpay.  
13  
Programming Languages –  
High-level Languages  
Program File  
Compiler  
Binary File  
CPU  
Result  
Result  
C, C++, Java, …  
Program File  
Interpreter  
CPU  
PHP, Perl, …  
A history of computer programming languages – Wikipedia  
Graph of programming language history – www.levenez  
14  
Programming Languages –  
The C language  
Evolved from B by Dennis Ritchie at Bell  
Laboratories and originally implemented on  
a DEC PDP-11 computer in 1972  
Using many of the important concepts of  
BCPL and B while adding data typing and  
other powerful features  
Used for many important application trends  
Developing new major operating systems: UNIX,  
Linux, Android, …  
Developing programs in the embedded systems  
in cars, medical machines, …  
15  
Programming Languages –  
The C language  
Ken Thompson (left) with Dennis Ritchie (right,  
the inventor of the C programming language)  
[Wikipedia]  
The development of the C language  
Full history of the C language  
16  
Programming Tasks  
Library  
(Header: *.h)  
Library  
(Object code: *.lib; *.dll; *.so)  
Design of  
program  
Executable  
Program  
Preprocessor  
Linker  
Editor  
Compiler  
Source code Enhanced source code  
Object code  
*.obj  
*.h + *.c  
(*.cpp)  
*.h + *.c (*.cpp)  
gcc; g++  
Integrated Development Environment (IDE):  
Visual Studio; Eclipse; Qt Creator; Code block; Online tool; etc  
17  
Programming Tasks  
Editor: supports text editing feature for  
writing source code  
Preprocessor: preprocesses the source code  
with replacing macro, inserting library files  
*.h, …  
Compiler: translates the source code into  
target machine language  
Linker: links the object code to other library  
files  
18  
Data and Algorithms –  
Concepts  
Program  
= A Sequence of Instructions Written in a  
Programming Language to Perform a Specified  
Task by the Computer  
= Data and their Structures + Algorithms  
Input/Output/…  
Process  
Example 1: instructions for adding overtime pay to base pay and  
then storing the result in gross pay: grosspay = basepay + overpay.  
Example 2: given n positive numbers, find the smallest one.  
19  
Data and Algorithms –  
Data  
Atomic data: int, double, char, ...  
Non-atomic data: array, struct, enum, …  
A strong relationship between the data  
structures and the operations on the data in  
the corresponding structures  
Example 1: instructions for adding overtime pay to base pay and  
then storing the result in gross pay: grosspay = basepay + overpay.  
- Input Data: basepay and overpay are positive real numbers  
(double).  
- Output Data: grosspay is also a positive real number (double).  
Example 2: given n positive numbers, find the smallest one.  
- Input Data: n positive real numbers are treated individually OR as  
a collection (double)  
- Output Data: minNumber is a positive real number (double).  
20  
Tải về để xem bản đầy đủ
pdf 36 trang yennguyen 22480 Free
Bạn đang xem 20 trang mẫu của tài liệu "Bài giảng Introduction to Computer Programming (C language) - Chapter 1: Introduction to Computers and Programming - Võ Thị Ngọc Châu", để tải tài liệu gốc về máy hãy click vào nút Download ở trên

File đính kèm:

  • pdfbai_giang_introduction_to_computer_programming_c_language_ch.pdf