1
300580
Programming
Fundamentals
With C++
1
Intro to Programming and Computer Systems Architecture
2
Contact Details
� Name: Zhuhan Jiang
� Office: ER 1.04, Parramatta campus
� Telephone: 9685 9336
� Email: [email protected]
� Unit Homepage: vUWS at
http://vuws.uws.edu.au/
3
Assessments
� Practical Attendance/Performance: 15%
� 9 marks for 9 tuts/pracs
� 6 marks for practice quizzes
� detailed marks breakdown in each prac page
� Assignment 1: 10%
� Assignment 2: 15%
� Mid Semester Test: 10%
� Final Examination: 50%
� Closed book
4
Textbooks
� Bronson, G.J., (2006) A First Book of C++ From Here to There, 3rd Ed, Thomson Learning
� Or: Bronson, G.J., (2012), A First Book of C++, 4th Ed, Thomson Learning.
� Robertson, L.A., (2007) Simple Program Design, 5th Ed, Thomson Learning (this book is for optional reading).
� Most of the tutorial/practical exercises will be taken from this Bronson’s book
5
1stYear Unit Specials
� How to use� unit learning guide, vUWS site, online library links, 1st
year coordinator, support services?
� What’s done in response to SFU etc?� While some changes may be in response to the student feedback in the past, a great many of others are also introduced for the further improvement of this unit.
� Some of the improvements� More drilling and examples on the basics – including flowcharts and code walking; More animation effects to present lecture material; Further narrowing on the coretut/prac exercises; Free access of online exercise drills; Free additional videos on basic programming; Additional sample assignments and their solution hints; More effective class structure and assessment format on tutorial/prac classes; More concrete approaches/styles to assignments; Clearer guide on expectations on different grades of different assessments
6
Unit Web Site
� vUWS at http://vuws.uws.edu.au
� Register a permanent password for the unit (not the same as SCEM account)
� Check regularly the unit announcements (at least twice a week)
� Read unit outline and learning guide there
� First practical starts in the second week (for tutorial enrolment problems, contact [email protected])
7
How to find
the relevant
information
or material?
8
� Lecture notes are to give a relatively more concise coverage on the most important aspects of this unit
� Lecturers may selectively concentrate on the more critical aspects of the notes during the class, and thus may leave some slides to be studied by the students themselves
9
What Is a Computer System?
A computer system is a device of performing computations and making logical decisions. It consists of hardware devices and software components
10
Hardware:von Neumann Model
CPU
Main
Memory
Output
Devices
Input
Devices
Secondary
Memory
keyboard,
mouse
scanner
microphone
hard disks
floppy disks,
tapes
CD-ROMs
display screen,
printer
speakers
11
CPU: Central Processing Unit
� Perform arithmetic calculations using the Arithmetic/Logical Unit (ALU)
� Decode and execute instructions under the control unit
ALU
Control
Unit
Instruction(Input)
Result(Output)
12
The Motherboard
CPU
main memory
expansionslots
13
Secondary Storage
� Floppy/hard disks
� CD ROM
� Tapes
� Smart cards
� Memory sticks
� ...
14
Peripherals
� A peripheral is a device attached to a host computer but not part of it
� its primary functionality is dependent upon the host
� can be considered as expanding the host's capabilities, while not forming part of the system's core architecture
StorageInput deviceOutput deviceDisplay deviceGraphical output device…
15
Bus in Computer Architecture
� is a subsystem that transfers data between computer components inside a computer or between computers
Bus card slots
a traditional 32-bit PCI bus card slot
16
Evolution of Computershttp://www.computersciencelab.com/ComputerHistory/History.htm
Abacus about 1500BC Pascal's Adder 1642 Leibniz's calculator 1670sBabbage's difference
engine 1822
ENIAC 1946
(1st generation)IBM PC 1977
(4th generation)
17
Computer Programs and Programming
� Computer program:
� Uses data and instructions to operate a computer
� Programming:
� Writing computer program in a language that the computer can respond to and that other programmers can understand
18
Programming Language
� Set of instructions, data, and rules used to construct a program
� High-level languages use human language type instructions
� Low-level languages use instructions tied to a computer type
19
Hierarchies of Programming Languages
� High-level languages:easy for humans to read/write programs, but too complicated for the computer to understand
Z = X + Y
� Machine Language: written in the form of 0’s and 1’s, can be understood directly by the computer
0110 1001 1010 1011
� Low-level languages:consist of simple instructions understood by the computer after a minor translation
ADD X Y Z
20
Procedural Programming Languages
� Instructions are used to create self-contained units (procedures)
� Procedures accept data as input and transform data to produce a specific result as an output
� Initially, high-level programming languages were predominately procedural
21
Typical Programming Languages
� High-level programming language:
� C, C++, Java, Python, PHP, Basic, Fortran, Pascal, Haskell, Ada
� Low-level programming language:
� Macro Assembler
� Machine language:
� Machine-dependent languages
22
Software:The intangible part of the computer
� System software: programs that support the execution and development of other programs� Operating systems
� Translation systems
� Application software� Programs designed to perform specific tasks
23
Operating Systems
� Control and manage the computing resources
� Important services that an operating system provides� File system: Directories, folders, files…
� Commands that allow for manipulation of the file system: Sort, delete, copy…
� Perform input and output on a variety of devices
� Management of the running systems
� Typical operation systems� Windows (7, Vista, XP), Linux, Unix, Mac OS, MS-DOS, and etc
24
Program Translation
� Source program cannot be executed until it is translated into machine language� Interpreted language:translates one statement at a time - interpreter
� Compiled language:translates all statements together - compiler
TranslationProgram
C++ language source program
Machine language program
25
Translation Systems
� Translation System: set of programs used to develop software
� Integrated Development Environment (IDE): Performs compilation, linking, and other activities in the same environment
� Examples: � Visual C++, Borland C++, Visual J++, JBuilder, Dev-C++, CodeBlocks C++
26
Application Software
� Application software is the software that has made using computers indispensable and popular
� Common application software…� Word processors
� Desktop publishing programs
� Spreadsheets
� Presentation managers
� Drawing programs
27
Stored Program Concept
Program Instructions can be stored in Main Memory just as data can.
-- Von Neumann's idea
Program Instructions can be stored in Main Memory just as data can.
-- Von Neumann's idea
28
Input:
Data and
Instructions
Output:
Data
Main Memory
10110111
01101001
00110100
…
…
00110111
11101001
01110100
…
…
Bus
CPU
Control
Unit
ALU
Program
Counter
10110111
01101001
00110100
01111101
11100000
…
PC
Von Neumann’s Machine Model
Fetch an instructionfrom the memory cellwhere the PC points
Increment the PC
Decode the instruction
Execute the instruction
29
Memory Allocation (1 Possible Case: DOS)
BIOSBIOS (stored in ROM)
FREEFREE (Unused)
DATA SEGMENTDATA SEGMENT
CODE SEGMENTCODE SEGMENT
OPERATING SYSTEMOPERATING SYSTEM
MemoryMemory
addressaddress
lowlow
highhigh
STACK AREASTACK AREA
30
Arithmetic/ Logic Unit
Control Unit
…
R0
R1
Rn
CPU
BUS
registers
Registers are used to hold the data immediatelyapplicable to the operation at handMain memory is used to hold the data that will be needed in the near future.Secondary storage is used to hold data that will be likely not be needed in the near future.
Main Memory
Input devices
Output devices
SecondaryStorage
31
Processing a High-Level Language Program
Editor Compiler Linker
Library
Executable Execution
Program source code
32
The main Function .
� Each C+ program must have one and only one function named main
� Called a driverfunction because it drives the other modules
main
1st module
2nd module
3rd module
last module
You go first
I’m done
You go second
I’m done
33
The main Function ..
� First line of function is called header line
� What type of data, if any, is returned from function
� The name of function
� What type of data, if any, is sent into function
� Data transmitted into a function at run time are referred to as arguments of the function
34
main Function Composition
int main ( )
{
program statements here
return 0;
}
the function name an empty argument list
type of returned value
the function body
35
The cout Object
� The cout object sends data to the
standard output display device
� The display device is usually a video screen
� Name derived from Console OUTput and
pronounced “see out”
� Data is passed to cout by the insertion
symbol
cout << "Hello, World!" ;
2 consecutive characters "<"
36
Trivial C++ Program
#include<iostream>using namespace std;int main( ){cout << "Hello World!\n" ;return 0;}
main is the
program entry
function
#include gives info on
standard IO library etc
C++ program is case sensitive Code saved as
file hello.cpp
White spaces are delimiters; line break is just a white
space
Each function is defined by a code block specified by a pair of { }
This is how things are sent
to the standard
output (screen here)
Literal strings are quoted
Statement must be ended with “; ”
37
More Explanations
#include<iostream>using namespace std;int main( ) {cout << "Hello World!\n" ;return 0;}
int is key
word for integer, type for returned value
#include is a
complier directive
Header file containing info on the use of cout
cout is an
built-in object for output Value 0 here actually
treated as the program exit error level
“\n” presents
the newlinecharacter
Program edited by a text editor, not a word processor!
38
Newline Escape Sequence
� Instructs the display device to move to a new line� A newline caused when the characters backslash \ and n are used together
� Backslash provides an “escape” from the normal interpretation of the character that follows
� Newline escape sequences can be placed anywhere within a message to cout
39
Preprocessor Command
� Performs an action before the compiler translates source code to machine code
� e.g. #include <iostream>
� causes the iostream file to be inserted wherever the #includecommand appears
� iostream is part of the C++ standard library
40
Namespaces
� Files accessed by compiler when looking for prewritten classes or functions
� Sample namespace statement:
� using namespace std;
� iostream contained in a namespace called std
� Compiler uses iostream’s cout object from std whenever cout is referenced
41
DEV-C++ IDE
Free Compilers Downloadable at vUWS
TextPad Dev-C++
42
Reading and Actions
� Get SCEM username and password before the start of the next week!
� Visit the unit website via vUWS, and read the unit outline and lecture schedule there
� Check out your tutorial/practical time and venue
� First practical starts in the second week
� Read Bronson’s Chapter 1