Professional Documents
Culture Documents
Introduction
P .J.Deitel and H.M. Deitel, C How to Program, Fifth Edition, Pearson Prentice-Hall, 2007. Jeri R.Hanly and Elliot B.Koffman, Problem Solving and Program Koffman, Design in C, Sixth Edition, Addison Wesley, 2009 Brian W.Kernighan and Dennis M. Ritchie, C Programming Language, Second Edition, Prentice Hall, PTR,1988. Anany Levitin, Introduction to The Design and Analysis of Algorithms, PearsonAddison Wesley, Wesley,2003.
Course Outline
P Programming Methodologies Algorithm Design Flowcharts and Pseudo Codes Top-down Program Design Language) P Structured Language (focus on CLanguage Data Types, Declarations, Operators and Expressions Input and Output Control Structures Functions and Program Structure Pointers Arrays, Strings, and Unions File Processing P Discipline of Programming Programming Style Structured Coding and Program Modularity Program Documentation and Maintenance
4
Outline Basic computer concepts Different types of programming languages Cprogramming language
What is a Computer?
Computer Device capable of performing computations and making logical decisions (hardware) Computers process data under the control of sets of instructions called computer programs (software) Hardware Various devices comprising a computer, such as central processing unit (CPU), memory, motherboard and hard disks as well as peripheral devices (keyboard, mouse, external display, optical drive) Hardware trends - Every year or two the following approximately double:
Amount of memory in which to execute programs The processor speed at which computers execute their programs (Moores Law)
Output unit
Outputs information (to screen, to printer, to control other devices)
Memory unit
Rapid access, low capacity, stores input information
Hardware
Do only one job or task at a time Resource managment and sharing for multiple programs Quasi-simultaneous program execution Single user
Multiprogramming
Operating Systems
10
P Personal computers
Economical enough for individual Computing distributed over networks Sharing of information across computer networks between file servers and clients
P Distributed computing
P Client/server computing
11
12
Outline Basic computer concepts Different types of programming languages Cprogramming language
13
Machine languages
machine specific instructions, executed by CPU lowest level representation of computer program
Assembly languages
English-like abbreviations representing elementary computer operations (translated via assemblers) Example: mov ax, 1234h (mov value 1234h into register ax)
High-level languages
Codes similar to everyday English Use mathematical notations (translated via compilers) Example: grossPay = basePay + overTimePay
14
Outline
Basic computer concepts Different types of programming languages Cprogramming language His History CStandard Library His Object-oriented Programming His His Typical CProgram Development Environment
15
History of C C
Evolved by Dennis Ritchie from two previous programming languages, BCPLand B Used to develop UNIX Used to write modern operating systems Hardware independent (portable) Many slight variations of Cexisted, and were incompatible existed, Committee formed to create a "unambiguous, machineindependent" definition Standard created in 1989, updated in 1999
Standardization
16
17
Outline
B Basic computer concepts t B Different types of programming languages t B Cprogramming language t Hist History CStandard Library Hist Object-oriented Programming Hist Hist Typical CProgram Development Environment
18
C++ . C++
Superset of Cdeveloped by Bjarne Stroustrup at Bell Labs "Spruces up" C, and provides object object-oriented capabilities Object-oriented design very powerful
10 to 100 fold increase in productivity
. Learning C++
19
Create Web pages with dynamic and interactive content Develop large-scale enterprise applications Enhance the functionality of Web servers Provide applications for consumer devices (such ascell phones, pagers and personal digital assistants)
20
Outline
Basic computer concepts Different types of programming languages Cprogramming language His History CStandard Library His Object-oriented Programming His His Typical CProgram Development Environment
21
P Phases of CPrograms: Edit (Cprogram file names should end with the .c extension) Preprocess Compile Link Load Execute
22
Outline
Basic computer concepts Different types of programming languages Cprogramming language His History CStandard Library His Object-oriented Programming His His Typical CProgram Development Environment
23
Outline Print a line Escape sequence Variables and Data types Memory concepts Arithmetic operators If-then statements Review
24
/* and */ indicate comments ignored by compiler #include directive tells C to load a particular file Left brace declares beginning of main function Statement tells C to perform an action return statement ends the function Right brace declares end of main function
Comments T surrounded by / * and * / is ignor by computer ext red Used to describe program
#include <stdio.h>
Adirective to the Cpreprocessor T computer to load contents of a certain file ells <stdio.h> allows standard input/output operations
25
C programs contain one or more functions, exactly one of which must be main Parenthesis used to indicate a function int means that main "returns" an integer value Braces({ and }) indicate a block
Escape character (\ )
Indicates that printf should do something out of the ordinary \n is the newline character
26
Away to exit a function return 0, in this case, means that the program terminated normally Indicatesend of main has been reached When a function is called, linker locates it in the library Inserts it into object program If function name is misspelled, the linker will produce an error because it will not be able to find function in the library
Right brace }
Linker
27
Outline Print a line Escape sequence Variables and Data types Memory concepts Arithmetic operators If-then statements Review
28
29
Example 02:
fig02_03.c
printf statement starts printing from where the last statement ended, so the text is printed on one line.
30
Example 03:
31
Objectives Print a line Escape sequence Variables and Data types Memory concepts Arithmetic operators If-then statements Review
32
Example 04:
Definitions of variables scanf obtains a value from the user and assigns it to integer1 scanf obtains a value from the user and assigns it to integer2 Assigns a value to sum
33
i n t i n t e g e r 1 , i n t e g e r 2 , sum;
When executing the program the user responds to the scanf statement by typing in a number, then pressing the enter (return) key
35
Outline Print a line Escape sequence Variables and Data types Memory concepts Arithmetic operators If-then statements Review
36
37
Memory Concepts
38
Outline Print a line Escape sequence Variables and Data types Memory concepts Arithmetic operators If-then statements Review
39
(assignment operator)
Assigns a value to a variable Is a binary operator (has two operands)
sum = variable1 + var iable2; sum gets variable1 + variable2;
40
Use * for multiplication and / for division Integer division truncates remainder
7/5 evaluates to 1
A Operator precedence
Some arithmetic operators act before others (i.e., multiplication before addition)
Use parenthesis when needed
42
43
Outline Print a line Escape sequence Variables and Data types Memory concepts Arithmetic operators If-then statements Review
44
E if control statement
45
46
47
48
49
Cs keywords.
50
Outline Print a line Escape sequence Variables and Data types Memory concepts Arithmetic operators If-then statements Review
51
Review Comments begin with / * and end with * / . Comments document programs and improve readability. The #include directive tells the preprocessor to include the content of another file (typically a header file such as <stdio.h> ). The <stdio.h> header contains information used by the compiler when compiling calls to standard input/output library functions such as pr intf . Every program in Cbegins executing at the function main. Functions can return information. Functions can receive information. Afunction starts by a left brace { and ends by a right brace } . Every statement must end by a semicolon semicolon. Escapesequences, for example \ newline. \n
52
Review Avariable is a location in memory where a value can be stored for use by a program. All variables must be defined with a name and a data type before they can be used in a program. The %d indicates that the data should be an decimal integer. The & indicates the memory address of an variable. Function p r i n t f can also use a format control string. Every variable has a name, a type and a value. Variable names correspond to locations in the computers memory. Arithmetic operators and precedence.
53
Review
if
statement allows a program to make a decision based on the truth or falsity of a statement of fact called a condition. Conditions in if statement are formed by using the equality operators and relational operators. The precedence of relational operators = should be readgets and == should be readdouble equals. Keywords.
54