0% found this document useful (0 votes)
5 views16 pages

Introduction to Computers and C++

The document is an introduction to computers and C++ programming, covering topics such as computer organization, programming languages, and the evolution of operating systems. It outlines the structure of C++ programs, the importance of object-oriented programming, and the history of various programming languages. Additionally, it discusses hardware trends and the development of the Internet.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views16 pages

Introduction to Computers and C++

The document is an introduction to computers and C++ programming, covering topics such as computer organization, programming languages, and the evolution of operating systems. It outlines the structure of C++ programs, the importance of object-oriented programming, and the history of various programming languages. Additionally, it discusses hardware trends and the development of the Internet.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1 2

Chapter 1 – Introduction to Computers Chapter 1 – Introduction to Computers


and C++ Programming and C++ Programming
Outline Outline
1.1 Introduction 1.16 History of the Internet
1.2 What is a Computer? 1.17 History of the World Wide Web
1.3 Computer Organization 1.18 World Wide Web Consortium (W3C)
1.4 Evolution of Operating Systems 1.19 General Notes About C++ and This Book
1.5 Personal Computing, Distributed Computing and 1.20 Introduction to C++ Programming
Client/Server Computing 1.21 A Simple Program: Printing a Line of Text
1.6 Machine Languages, Assembly Languages, and High-Level 1.22 Another Simple Program: Adding Two Integers
Languages 1.23 Memory Concepts
1.7 History of C and C++ 1.24 Arithmetic
1.8 C++ Standard Library 1.25 Decision Making: Equality and Relational Operators
1.9 Java 1.26 Thinking About Objects: Introduction to Object Technology
1.10 Visual Basic, Visual C++ and C# and the Unified Modeling Language
1.11 Other High-Level Languages
1.12 Structured Programming
1.13 The Key Software Trend: Object Technology
1.14 Basics of a Typical C++ Environment
1.15 Hardware Trends

© 2003 Prentice Hall, Inc. All rights reserved. © 2003 Prentice Hall, Inc. All rights reserved.

3 4

1.1 Introduction 1.2 What is a Computer?

• Software • Computer
– Instructions to command computer to perform actions and – Device capable of performing computations and making
make decisions logical decisions
• Hardware • Computer programs
• Standardized version of C++ – Sets of instructions that control computer’s processing of
data
– United States
• American National Standards Institute (ANSI) • Hardware
– Worldwide – Various devices comprising computer
• International Organization for Standardization (ISO) • Keyboard, screen, mouse, disks, memory, CD-ROM,
processing units, …
• Structured programming
• Software
• Object-oriented programming
– Programs that run on computer

© 2003 Prentice Hall, Inc. All rights reserved. © 2003 Prentice Hall, Inc. All rights reserved.

1
5 6

1.3 Computer Organization 1.3 Computer Organization

• Six logical units of computer • Six logical units of computer


1. Input unit 3. Memory unit
• “Receiving” section • Rapid access, relatively low capacity “warehouse” section
• Obtains information from input devices • Retains information from input unit
– Keyboard, mouse, microphone, scanner, networks, … – Immediately available for processing
2. Output unit • Retains processed information
• “Shipping” section – Until placed on output devices
• Takes information processed by computer • Memory, primary memory
• Places information on output devices 4. Arithmetic and logic unit (ALU)
– Screen, printer, networks, … • “Manufacturing” section
– Information used to control other devices • Performs arithmetic calculations and logic decisions

© 2003 Prentice Hall, Inc. All rights reserved. © 2003 Prentice Hall, Inc. All rights reserved.

7 8

1.3 Computer Organization 1.4 Evolution of Operating Systems

• Six logical units of computer • Early computers


5. Central processing unit (CPU) – Single-user batch processing
• “Administrative” section • Only one job or task at a time
• Supervises and coordinates other sections of computer • Process data in groups (batches)
6. Secondary storage unit • Decks of punched cards
• Long-term, high-capacity “warehouse” section • Operating systems
• Storage
– Software systems
– Inactive programs or data
– Manage transitions between jobs
• Secondary storage devices
– Increased throughput
– Disks
• Amount of work computers process
• Longer to access than primary memory
• Less expensive per unit than primary memory

© 2003 Prentice Hall, Inc. All rights reserved. © 2003 Prentice Hall, Inc. All rights reserved.

2
9 10
1.5 Personal Computing, Distributed
1.4 Evolution of Operating Systems
Computing, and Client/Server Computing
• Multiprogramming • Personal computers
– Many jobs or tasks sharing computer’s resources – 1977: Apple Computer
– “Simultaneous” operation of many jobs – Economical enough for individual
• Timesharing – 1981: IBM Personal Computer
– 1960s – “Standalone” units
– Special case of multiprogramming
– Users access computer through terminals
• Computer networks
• Devices with keyboards and screens – Over telephone lines
• Dozens, even hundreds of users – Local area networks (LANs)
– Perform small portion of one user’s job, then moves on to • Distributed computing
service next user
– Organization’s computing distributed over networks
– Advantage:
• User receives almost immediate responses to requests

© 2003 Prentice Hall, Inc. All rights reserved. © 2003 Prentice Hall, Inc. All rights reserved.

11 12
1.5 Personal Computing, Distributed 1.6 Machine Languages, Assembly
Computing, and Client/Server Computing Languages, and High-level Languages
• Workstations • Three types of computer languages
– Provide enormous capabilities 1. Machine language
• Only language computer directly understands
– Information shared across networks
• “Natural language” of computer
• Client/server computing • Defined by hardware design
– File servers – Machine-dependent
• Offer common store of programs and data • Generally consist of strings of numbers
– Ultimately 0s and 1s
– Client computers
• Instruct computers to perform elementary operations
• Access file servers across network
– One at a time
• UNIX, Linux, Microsoft’s Window-based systems • Cumbersome for humans
• Example:
+1300042774
+1400593419
+1200274027

© 2003 Prentice Hall, Inc. All rights reserved. © 2003 Prentice Hall, Inc. All rights reserved.

3
13 14
1.6 Machine Languages, Assembly 1.6 Machine Languages, Assembly
Languages, and High-level Languages Languages, and High-level Languages
• Three types of computer languages • Three types of computer languages
2. Assembly language 3. High-level languages
• English-like abbreviations representing elementary computer • Similar to everyday English, use common mathematical
operations notations
• Clearer to humans • Single statements accomplish substantial tasks
• Incomprehensible to computers – Assembly language requires many instructions to
– Translator programs (assemblers) accomplish simple tasks
• Convert to machine language • Translator programs (compilers)
• Example: – Convert to machine language
LOAD BASEPAY • Interpreter programs
ADD OVERPAY – Directly execute high-level language programs
STORE GROSSPAY • Example:
grossPay = basePay + overTimePay

© 2003 Prentice Hall, Inc. All rights reserved. © 2003 Prentice Hall, Inc. All rights reserved.

15 16

1.7 History of C and C++ 1.7 History of C and C++

• History of C • History of C++


– Evolved from two other programming languages – Extension of C
• BCPL and B – Early 1980s: Bjarne Stroustrup (Bell Laboratories)
– “Typeless” languages – “Spruces up” C
– Dennis Ritchie (Bell Laboratories) – Provides capabilities for object-oriented programming
• Added data typing, other features • Objects: reusable software components
– Development language of UNIX – Model items in real world
– Hardware independent • Object-oriented programs
• Portable programs – Easy to understand, correct and modify
– 1989: ANSI standard – Hybrid language
– 1990: ANSI and ISO standard published • C-like style
• ANSI/ISO 9899: 1990 • Object-oriented style
• Both

© 2003 Prentice Hall, Inc. All rights reserved. © 2003 Prentice Hall, Inc. All rights reserved.

4
17 18

1.8 C++ Standard Library 1.9 Java

• C++ programs • Java


– Built from pieces called classes and functions – 1991: Sun Microsystems
• C++ standard library • Green project
– 1995: Sun Microsystems
– Rich collections of existing classes and functions
• Formally announced Java at trade show
• “Building block approach” to creating programs – Web pages with dynamic and interactive content
– “Software reuse” – Develop large-scale enterprise applications
– Enhance functionality of web servers
– Provide applications for consumer devices
• Cell phones, pagers, personal digital assistants, …

© 2003 Prentice Hall, Inc. All rights reserved. © 2003 Prentice Hall, Inc. All rights reserved.

19 20

1.10 Visual Basic, Visual C++ and C# 1.10 Visual Basic, Visual C++ and C#

• BASIC • Visual C++


– Beginner’s All-Purpose Symbolic Instruction Code – Microsoft’s implementation of C++
– Mid-1960s: Prof. John Kemeny and Thomas Kurtz • Includes extensions
(Dartmouth College) • Microsoft Foundation Classes (MFC)
• Common library
• Visual Basic
– GUI, graphics, networking, multithreading, …
– 1991
– Shared among Visual Basic, Visual C++, C#
• Result of Microsoft Windows graphical user interface (GUI)
– Developed late 1980s, early 1990s • .NET platform
– Powerful features – Web-based applications
• GUI, event handling, access to Win32 API, object-oriented • Distributed to great variety of devices
programming, error handling – Cell phones, desktop computers
– Visual Basic .NET – Applications in disparate languages can communicate

© 2003 Prentice Hall, Inc. All rights reserved. © 2003 Prentice Hall, Inc. All rights reserved.

5
21 22

1.10 Visual Basic, Visual C++ and C# 1.11 Other High-level Languages

• C# • FORTRAN
– Anders Hejlsberg and Scott Wiltamuth (Microsoft) – FORmula TRANslator
– Designed specifically for .NET platform – 1954-1957: IBM
– Roots in C, C++ and Java – Complex mathematical computations
• Easy migration to .NET • Scientific and engineering applications
– Event-driven, fully object-oriented, visual programming • COBOL
language
– COmmon Business Oriented Language
– Integrated Development Environment (IDE)
– 1959: computer manufacturers, government and industrial
• Create, run, test and debug C# programs
computer users
• Rapid Application Development (RAD)
– Precise and efficient manipulation of large amounts of data
– Language interoperability
• Commercial applications

© 2003 Prentice Hall, Inc. All rights reserved. © 2003 Prentice Hall, Inc. All rights reserved.

23 24

1.11 Other High-level Languages 1.12 Structured Programming

• Pascal • Structured programming (1960s)


– Prof. Niklaus Wirth – Disciplined approach to writing programs
– Academic use – Clear, easy to test and debug, and easy to modify
• Pascal
– 1971: Niklaus Wirth
• Ada
– 1970s - early 1980s: US Department of Defense (DoD)
– Multitasking
• Programmer can specify many activities to run in parallel

© 2003 Prentice Hall, Inc. All rights reserved. © 2003 Prentice Hall, Inc. All rights reserved.

6
25 26
1.13 The Key Software Trend: Object
1.14 Basics of a Typical C++ Environment
Technology
• Objects • C++ systems
– Reusable software components that model real world items – Program-development environment
– Meaningful software units – Language
• Date objects, time objects, paycheck objects, invoice objects, – C++ Standard Library
audio objects, video objects, file objects, record objects, etc.
• Any noun can be represented as an object
– More understandable, better organized and easier to maintain
than procedural programming
– Favor modularity
• Software reuse
– Libraries
• MFC (Microsoft Foundation Classes)
• Rogue Wave

© 2003 Prentice Hall, Inc. All rights reserved. © 2003 Prentice Hall, Inc. All rights reserved.

27 28

1.14 Basics of a Typical C++ Environment 1.14 Basics of a Typical C++ Environment
Program is created in
Editor Disk
Phases of C++ Programs: the editor and stored
on disk. • Input/output
Preprocessor Disk Preprocessor program – cin
1. Edit processes the code.
Compiler creates • Standard input stream
Compiler Disk object code and stores
2. Preprocess it on disk. • Normally keyboard
Linker links the object
Linker Disk code with the libraries,
– cout
3. Compile Primary
creates [Link] and
stores it on disk • Standard output stream
Memory
Loader • Normally computer screen
4. Link – cerr
Loader puts program
in memory.
5. Load Disk ..
..
• Standard error stream
..

• Display error messages


Primary
6. Execute CPU
Memory

CPU takes each


instruction and
executes it, possibly
storing new data
..
.. values as the program
..
executes.
© 2003 Prentice Hall, Inc. All rights reserved. © 2003 Prentice Hall, Inc. All rights reserved.

7
29 30

1.15 Hardware Trends 1.16 History of the Internet

• Capacities of computers • Late 1960s: ARPA


– Approximately double every year or two
– Advanced Research Projects Agency
– Memory used to execute programs • Department of Defense
– Amount of secondary storage – ARPAnet
• Disk storage
– Electronic mail (e-mail)
• Hold programs and data over long term
– Processor speeds • Packet switching
• Speed at which computers execute programs – Transfer digital data via small packets
– Allow multiple users to send/receive data simultaneously
over same communication paths
• No centralized control
– If one part of network fails, other parts can still operate

© 2003 Prentice Hall, Inc. All rights reserved. © 2003 Prentice Hall, Inc. All rights reserved.

31 32

1.16 History of the Internet 1.17 History of the World Wide Web

• TCP/IP • World Wide Web


– Transmission Control Protocol (TCP) – 1990: Tim Berners-Lee (CERN)
• Messages routed properly – Locate and view multimedia-based documents
• Messages arrived intact – Information instantly and conveniently accessible worldwide
– Internet Protocol (IP) – Possible worldwide exposure
• Communication among variety of networking hardware and • Individuals and small businesses
software
– Changing way business done
• Current architecture of Internet
• Bandwidth
– Carrying capacity of communications lines

© 2003 Prentice Hall, Inc. All rights reserved. © 2003 Prentice Hall, Inc. All rights reserved.

8
33 34

1.18 World Wide Web Consortium (W3C) 1.18 World Wide Web Consortium (W3C)

• World Wide Web Consortium (W3C) • Recommendations


– 1994: Tim Berners-Lee – 3 phases
– Develop nonproprietary, interoperable technologies • Working Draft
– Standardization organization – Specifies evolving draft
– Three hosts • Candidate Recommendation
• Massachusetts Institute of Technology (MIT) – Stable version that industry can begin to implement
• France’s INRIA (Institut National de Recherche en • Proposed Recommendation
Informatique et Automatique) – Considerably mature Candidate Recommendation
• Keio University of Japan
– Over 400 members
• Primary financing
• Strategic direction

© 2003 Prentice Hall, Inc. All rights reserved. © 2003 Prentice Hall, Inc. All rights reserved.

35 36
1.19 General Notes About C++
1.20 Introduction to C++ Programming
and This Book
• Book geared toward novice programmers • C++ language
– Stress programming clarity – Facilitates structured and disciplined approach to computer
– C and C++ are portable languages program design

• Portability • Following several examples


– C and C++ programs can run on many different computers – Illustrate many important features of C++
– Each analyzed one statement at a time
• Compatibility
– Many features of current versions of C++ not compatible • Structured programming
with older implementations • Object-oriented programming

© 2003 Prentice Hall, Inc. All rights reserved. © 2003 Prentice Hall, Inc. All rights reserved.

9
37 38
1 // Fig. 1.2: fig01_02.cpp
1.21 A Simple Program: 2 // A first program in C++. Single-line comments. Outline
3 Function main
#include <iostream> returns an
Printing a Line of Text 4 integer { begins Preprocessor
value.
Left brace function directive to
fig01_02.cpp
5 // function main Function
body. program
begins include input/output Statements
main appears
execution stream end with a(1 of 1)
6 int main() header file <iostream>.
exactly once in every C++ semicolon ;.
• Comments 7 {
program..
8 std::cout << "Welcome to C++!\n"; fig01_02.cpp
– Document programs 9 Corresponding right brace } output (1 of 1)
10 return 0; // ends function
indicate thatbody.
program ended successfully
– Improve program readability 11 Stream
Name cout insertion
belongs to operator.
12 } // end function main
– Ignored by compiler namespace std.
Keyword return is one of
– Single-line comment Welcome to C++!
several means to exit
• Begin with // function; value 0 indicates
program terminated
• Preprocessor directives successfully.

– Processed by preprocessor before compiling


– Begin with #

© 2003 Prentice Hall, Inc.


© 2003 Prentice Hall, Inc. All rights reserved. All rights reserved.

39 40
1.21 A Simple Program: 1.21 A Simple Program:
Printing a Line of Text Printing a Line of Text
• Standard output stream object
– std::cout Escape Sequence Description
– “Connected” to screen
\n Newline. Position the screen cursor to the
– << beginning of the next line.
• Stream insertion operator \t Horizontal tab. Move the screen cursor to the next
• Value to right (right operand) inserted into output stream tab stop.
\r Carriage return. Position the screen cursor to the
• Namespace beginning of the current line; do not advance to the
– std:: specifies using name that belongs to “namespace” next line.
std \a Alert. Sound the system bell.
– std:: removed through use of using statements \\ Backslash. Used to print a backslash character.
\" Double quote. Used to print a double quote
• Escape characters character.
– \
– Indicates “special” character output

© 2003 Prentice Hall, Inc. All rights reserved. © 2003 Prentice Hall, Inc. All rights reserved.

10
41 42
1 // Fig. 1.4: fig01_04.cpp 1 // Fig. 1.5: fig01_05.cpp
2 // Printing a line with multiple statements.
Outline 2 // Printing multiple lines with a single statement
Outline
3 #include <iostream> 3 #include <iostream>
4 4
fig01_04.cpp fig01_05.cpp
5 // function main begins program execution Multiple stream insertion 5 // function main begins program execution Using newline characters to
6 int main()
(1 of 1) 6 int main() print on multiple lines. (1 of 1)
statements produce one line
7 { 7 {
of output. fig01_04.cpp fig01_05.cpp
8 std::cout << "Welcome "; 8 std::cout << "Welcome\nto\n\nC++!\n";
9 std::cout << "to C++!\n"; output (1 of 1) 9 output (1 of 1)
10 10 return 0; // indicate that program ended successfully
11 return 0; // indicate that program ended successfully 11
12 12 } // end function main
13 } // end function main
Welcome
Welcome to C++! to

C++!

© 2003 Prentice Hall, Inc. © 2003 Prentice Hall, Inc.


All rights reserved. All rights reserved.

43 44
1.22 Another Simple Program: 1.22 Another Simple Program:
Adding Two Integers Adding Two Integers
• Variables • Variables
– Location in memory where value can be stored – Variable names
– Common data types • Valid identifier
• int - integer numbers – Series of characters (letters, digits, underscores)
• char - characters – Cannot begin with digit
• double - floating point numbers – Case sensitive
– Declare variables with name and data type before use
int integer1;
int integer2;
int sum;
– Can declare several variables of same type in one declaration
• Comma-separated list
int integer1, integer2, sum;

© 2003 Prentice Hall, Inc. All rights reserved. © 2003 Prentice Hall, Inc. All rights reserved.

11
45 46
1 // Fig. 1.6: fig01_06.cpp
1.22 Another Simple Program: 2 // Addition program.
Outline
3 #include <iostream>
Adding Two Integers 4
fig01_06.cpp
5 // function main begins program execution
6 int main()
(1 of 1)
• Input stream object 7 { Declare integer variables.
8 int integer1; // first number to be input by user
– >> (stream extraction operator) 9 int integer2; // second number to be input by user
10 int sum; Usewhich
// variable in stream extraction
sum will be stored
• Used with std::cin operator with standard input
11
• Waits for user to input value, then press Enter (Return) key 12 stream to obtain
std::cout << "Enter first integer\n"; user input.
// prompt
13 std::cin >> integer1; // read an integer
• Stores value in variable to right of operator 14
15 std::cout << "Enter second integer\n"; // prompt
– Converts value to variable data type
16 std::cin >> integer2; Calculations can be performed
// read in output
an integer statements: alternative
Stream manipulator
• = (assignment operator) 17
18 sum = integer1 + integer2;
for lines 18 and 20:
// assign result to sum
std::endl outputs a
– Assigns value to variable 19 std::cout << "Sum is " <<
newline, then “flushes output
integer1 + integer2 << std::endl;
20 std::cout << "Sum is " << sum << std::endl; // print sum buffer.”
– Binary operator (two operands) 21
22 return 0; // indicate that program ended successfully
– Example: 23
sum = variable1 + variable2; 24 } // end function main Concatenating, chaining or
cascading stream insertion
operations.

© 2003 Prentice Hall, Inc.


© 2003 Prentice Hall, Inc. All rights reserved. All rights reserved.

47 48
Enter first integer
45
Outline
Enter second integer 1.23 Memory Concepts
72
fig01_06.cpp
Sum is 117
output (1 of 1)
• Variable names
– Correspond to actual locations in computer's memory
– Every variable has name, type, size and value
– When new value placed into variable, overwrites previous
value
– Reading variables from memory nondestructive

© 2003 Prentice Hall, Inc.


All rights reserved. © 2003 Prentice Hall, Inc. All rights reserved.

12
49 50

1.23 Memory Concepts 1.24 Arithmetic

std::cin >> integer1; integer1 45 • Arithmetic calculations


– Assume user entered 45 – *
• Multiplication
std::cin >> integer2; integer1 45 – /
– Assume user entered 72 integer2 72 • Division
• Integer division truncates remainder
– 7 / 5 evaluates to 1
45 – %
sum = integer1 + integer2; integer1
• Modulus operator returns remainder
integer2 72
– 7 % 5 evaluates to 2
sum 117

© 2003 Prentice Hall, Inc. All rights reserved. © 2003 Prentice Hall, Inc. All rights reserved.

51 52
1.25 Decision Making: Equality and
1.24 Arithmetic
Relational Operators
• Rules of operator precedence • if structure
– Operators in parentheses evaluated first – Make decision based on truth or falsity of condition
• Nested/embedded parentheses • If condition met, body executed
– Operators in innermost pair first • Else, body not executed
– Multiplication, division, modulus applied next • Equality and relational operators
• Operators applied from left to right
– Equality operators
– Addition, subtraction applied last • Same level of precedence
Operator(s) • Operators applied fromOrder
Operation(s) leftoftoevaluation
right (precedence)
– Relational operators
() Parentheses Evaluated first. If the parentheses are nested, the
expression in the innermost pair is evaluated first. If • Same level of precedence
there are several pairs of parentheses “on the same level”
(i.e., not nested), they are evaluated left to right. – Associate left to right
*, /, or % Multiplication Division Evaluated second. If there are several, they re
Modulus evaluated left to right.
+ or - Addition Evaluated last. If there are several, they are
Subtraction evaluated left to right.

© 2003 Prentice Hall, Inc. All rights reserved. © 2003 Prentice Hall, Inc. All rights reserved.

13
53 54
1.25 Decision Making: Equality and 1.25 Decision Making: Equality and
Relational Operators Relational Operators

Sta nd a rd a lg eb ra ic C++ eq ua lity Exa m p le Me a ning of


• using statements
eq ua lity op era to r or or rela tiona l of C++ C++ c ond itio n – Eliminate use of std:: prefix
rela tiona l op era tor op era tor c ond ition
– Write cout instead of std::cout
Relational operators
> > x > y x is greater than y
< < x < y x is less than y

≥ >= x >= y x is greater than or equal to y

≤ <= x <= y x is less than or equal to y

Equality operators
= == x == y x is equal to y

≠ != x != y x is not equal to y

© 2003 Prentice Hall, Inc. All rights reserved. © 2003 Prentice Hall, Inc. All rights reserved.

55 56
1 // Fig. 1.14: fig01_14.cpp 26 if ( num1 < num2 )
2 // Using if statements, relational
Outline 27 cout << num1 << " is less than " << num2 << endl;
Outline
3 // operators, and equality operators. 28
4 #include <iostream> 29 if ( num1 > num2 )
fig01_14.cpp fig01_14.cpp
5 30 cout << num1 << " is greater than " << num2 << endl;
(1 of 2) Statements may
(2 of 2) be split over
6 using std::cout; // program uses cout 31
7 using std::cin; // program uses cin 32 if ( num1 <= num2 )
several lines.
using statements eliminate
8 using std::endl; // program uses endl 33 cout << num1 << " is less than or equal to " fig01_14.cpp
need for std:: prefix.
9 34 << num2 << endl; output (1 of 2)
10 // function main begins programDeclare variables.
execution 35
11 int main() 36 if ( num1 >= num2 )
12 { 37 cout << num1 << " is greater than or equal to "
13 Can write
int num1; // first number to be readand
cout cin
from user 38 << num2 << endl;
14 withouttostd::
int num2; // second number prefix.
be read from user 39
15 40 return 0; // indicate that program ended successfully
16 cout << "Enter two integers, and I will tell you\n" 41
17
if structure compares values
<< "the relationships they satisfy: "; 42 } // end function main
18 cin >> num1 >> num2; of num1
// read and num2
two integers to test for
If condition is true (i.e.,
19 equality. values are equal), execute this Enter two integers, and I will tell you
20 if ( num1 == num2 ) if structure compares
[Link] the relationships they satisfy: 22 12
21 of num1
cout << num1 << " is equal to " << If condition
andnum2
num2 << to is true
test for
endl; (i.e., 22 is not equal to 12
22 inequality. values are not equal), execute 22 is greater than 12
23 if ( num1 != num2 ) this statement. 22 is greater than or equal to 12
24 cout << num1 << " is not equal to " << num2 << endl;
25

© 2003 Prentice Hall, Inc. © 2003 Prentice Hall, Inc.


All rights reserved. All rights reserved.

14
57 58
Enter two integers, and I will tell you
the relationships they satisfy: 7 7
Outline 1.26 Thinking About Objects: Introduction to
7 is equal to 7
7 is less than or equal to 7
Object Technology and the Unified Modeling
fig01_14.cpp
7 is greater than or equal to 7
output (2 of 2) Language
• Object oriented programming (OOP)
– Model real-world objects with software counterparts
– Attributes (state) - properties of objects
• Size, shape, color, weight, etc.
– Behaviors (operations) - actions
• A ball rolls, bounces, inflates and deflates
• Objects can perform actions as well
– Inheritance
• New classes of objects absorb characteristics from existing classes
– Objects
• Encapsulate data and functions
• Information hiding
– Communicate across well-defined interfaces
© 2003 Prentice Hall, Inc.
All rights reserved. © 2003 Prentice Hall, Inc. All rights reserved.

59 60
1.26 Thinking About Objects: Introduction to 1.26 Thinking About Objects: Introduction to
Object Technology and the Unified Modeling Object Technology and the Unified Modeling
Language Language
• User-defined types (classes, components) • Object-oriented analysis and design (OOAD)
– Data members process
• Data components of class – Analysis of project’s requirements
– Member functions – Design for satisfying requirements
• Function components of class – Pseudocode
– Association • Informal means of expressing program
– Reuse classes • Outline to guide code

© 2003 Prentice Hall, Inc. All rights reserved. © 2003 Prentice Hall, Inc. All rights reserved.

15
61
1.26 Thinking About Objects: Introduction to
Object Technology and the Unified Modeling
Language
• Unified Modeling Language (UML)
– 2001: Object Management Group (OMG)
• Released UML version 1.4
– Model object-oriented systems and aid design
– Flexible
• Extendable
• Independent of many OOAD processes
• One standard set of notations
– Complex, feature-rich graphical language

© 2003 Prentice Hall, Inc. All rights reserved.

16

You might also like