Professional Documents
Culture Documents
Lecture 1
Lecture 1
Lecture # 1
Basic Introduction
Instructor: Lec Razia Sharif
Sequence
• Why study programming language
• What is computer and its organization
• Types of Programming Languages
• History of C and C++
• Basics of a Typical C++ Environment
• Errors
• Identifiers in C/C++
• Basic C/C++ Program Structure
• Dissection of program
Why study programming
languages?
• Programming languages are important for
students in all disciplines of engineering because
they are the primary tools of the central
activity of any science.
3
Why study programming
languages? (cont.)
• To improve your ability to develop effective
algorithms and to improve your use of existing
programming language.
• To increase your vocabulary of useful
programming constructs.
• To allow a better choice of programming
languages.
• To make it easier to learn a new language.
4
What is a Computer?
• Computer
– A device capable of performing computations and making
logical decisions
• Computer programs
– Sets of instructions that control a computer’s processing of
data
• Hardware
– Various devices comprising a computer
• Examples: keyboard, screen, mouse, disks, memory, CD-ROM, and
processing units
• Software
– Programs that run a computer
Computer Organization
• Six logical units in every computer:
– Input unit
• Obtains information from input devices (keyboard, mouse)
– Output unit
• Outputs information (to screen, to printer, to control other devices)
– Memory unit
• Rapid access, low capacity, stores input information
– Arithmetic and logic unit (ALU)
• Performs arithmetic calculations and logic decisions
– Central processing unit (CPU)
• Supervises and coordinates the other sections of the computer
– Secondary storage unit
• Cheap, long-term, high-capacity storage, stores inactive programs
Types of Programming Languages
• Machine languages
– Combination of 1 and 0 giving machine specific instructions
– Example:
00000 00001 00010 00110 00000 100000
100011 00011 01000 00000 00001 000100
000010 00000 00000 00000 10000 000000
• Assembly languages
– English-like abbreviations representing elementary computer
operations (translated via assemblers)
– Example:
LOAD BASEPAY
ADD OVERPAY
STORE GROSSPAY
• High-level languages
– Similar to everyday English, use mathematical notations
(translated via compilers)
– Example:
grossPay = basePay + overTimePay
Some High-Level Languages
• Java used to
– 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 as cell phones, pagers and
personal digital assistants)
• FORTRAN
– Used in scientific and engineering applications
• COBOL
– Used to manipulate large amounts of data
• Pascal
– Used to teach structured programming
• C/C++
– Middle-level language
– Provides facilities for both high level as well as low level programming
History of C and C++
• C++ evolved from C
– C evolved from B
• ANSI C
– Established worldwide standards for C programming
• C invented by Dennis Ritchie of AT&T Bell Labs in the 1970s
• C++ by Bjarne Stroustrup of the same labs in the early 1980s
• C++ “spruces up” C
– Provides capabilities for object-oriented programming
• Objects are reusable software components that model things in the real world
• Object-oriented programs are easy to understand, correct and modify
• C is a subset of C++
Basics of a Typical C++ Environment
Phases of C++ Programs: Editor Disk
Program is created in
the editor and stored
on disk.
6. Execute Disk ..
..
..
Files: Primary
Memory
CPU
CPU takes each
instruction and
*.cpp, *.c, *.h executes it, possibly
storing new data
values as the program
.. executes.
*.obj, *.exe ..
..
Errors
• Syntax errors
– reported by the compiler
• Linker errors
– reported by the linker
• Execution/Run-time errors
– reported by the operating system
• Logic errors
– not reported
Identifiers in C/C++
• A name assigned to:
– A constant
– Variable
– Function
– User defined data type (will be discussed in the next course)
Identifiers in C/C++ …
• Rules
– Can be from one to several characters long
– First 1024 characters are significant
– May consist of alphanumeric and underscore characters
– May start with any letter of alphabet, or with an underscore
– Are case sensitive
– No special characters are allowed
– Spaces are not allowed as part of the identifier name
– Keywords cannot be used as identifiers
– Any other reserved words by the language (such as names of
library functions) shall not be used as identifiers
Identifiers in C/C++ …
• Conventions
– Use identifier names that reflect the meaning or usage
of the items being named
– THISISACONSTANT or THIS_IS_A_CONSTANT
– thisisavariable or this_is_a_variable
– thisIsAFunction
– ThisIsAUserDefinedDataType
Basic C/C++ Program Structure
/**********************************************************
* Header Comments
**********************************************************/
Pre-processor directives
int main()
{
declarations and executable statements
return 0;
}//end block of main
#include <stdio.h>