01 introduction uml pseudocode
TRANSCRIPT
IntroductionSoftware Engineering with OOP
Software Crisis
Common software systems behavior Does not provide required functionality Is over budget with respect to time and money and computer
resource usage Not adaptable to changing user needs
Why? User needs are ill-specified Complexity of interactions grows multiplicatively Human cooperation limits Programming is difficult
Software Engineering
Goal Ease the development of reliable, flexible,
economical software Techniques
Group management Complexity management Measuring software quality
Caveat Throwing more people at a problem isn’t always the
best way to fix it
Software Development Basics
System Design What is the solution?
Program DesignWhat are the mechanismsthat best implement thesolution?
Program ImplementationHow is the solutionconstructed?
Testing Is the problem solved?
Delivery Can the customer use the solution?
Maintenance Are enhancements needed?
ProblemDomain
ProblemDomain
ImplementationDomain
ImplementationDomain
Over 50% of development costs!
Requirements Analysis What is the problem?
Specifications Problem statement for programmers
C++ Designer
Stroustrup Purpose
To implement software tools more quickly, reliably, and economically
Principal features Implements most of C (superset) Supports object-oriented programming Reusable software components that have both
attributes and behavior — i.e., objects
Where Do We Go From Here? Machine organization, programming, translation software, programming
environments, data representations, terminology, history, software engineering, object-oriented design [1]
C++ fundamentals, C++ programs, C++ objects, input, output [2] Modifying objects, arithmetic, operator precedence, strings [3] Control constructs, Boolean objects, programming logic, conditional
execution, switch statement [4.1-4.5] Repetition, looping, for and while and do loops [4.6-4.12] Functions, library programs: iostream, iomanip, fstream, generating and
using random numbers [5] Programmer-defined functions, parameters, pass by value, pass by
reference [6] Classes: programmer-defined data types, constructors, object-oriented
design and analysis [7] Inheritance [8]
A C++ Program// Canonical first program
#include <iostream>
#include <string>
using namespace std;
int main() {cout << "Hello world!" << endl;
return 0;
}
Pre-processor directives
A using directive
Software Engineering Goals
Reliability An unreliable life-critical system can be fatal
Understandability Future development is difficult if software is hard to
understandCost Effectiveness
Cost to develop and maintain should not exceed profitAdaptability
System that is adaptive is easier to alter and expandReusability
Improves reliability, maintainability, and profitability
Software Engineering with OOP Identity
Data are organized into (named) objects Abstraction
Extract the relevant properties while ignoring inessentials Divide an object into smaller modules (modularity) Simplify to make it easier to understand
Classification (Hierarchy) Ranking or ordering of objects based on some relationship
between them Encapsulation
Couple the data PLUS the operations on that data together; Also, hide and protect essential information (implementation details) behind a controlled interface – i.e., information hiding.
Inheritance Ability to create new classes based on existing ones
Polymorphism Exhibiting the same behaviour differently on different classes or
subclasses Persistence
Extract the relevant object properties while ignoring inessentials Defines a view of the object
Example - car Car dealer views a car from selling features standpoint
Price, length of warranty, color, … Mechanic views a car from systems maintenance standpoint
Size of the oil filter, type of spark plugs, … Driver views a car from usability standpoint
How fast does it go, fuel consumption, etc…
Abstraction
Price? Oil change?
Encapsulation Steps
Decompose an object into parts Data and Methods that operate on them go together
Hide and protect essential information (implementation details) Information Hiding is hiding implementation details; encapsulation (a
language construct) is not the same thing as information hiding (a design principle), although it implements it
Supply interface that allows information to be modified in a controlled and useful manner
Internal representation can be changed without affecting other system parts
Example - car radio Interface consists of controls
and power and antenna connectors The details of how it works is hidden To install and use a radio
Do not need to know anything about the radio’s electronics
Modularity
Dividing an object into smaller pieces or modules so that the object is easier to understand and manipulate
Most complex systems are modular
Example - Automobile can be decomposed into subsystems
Cooling system Radiator Thermostat Water pump
Maneuvering Steering Wheels Brakes
Ignition system Battery Starter Spark plugs
Hierarchy Hierarchy
Ranking or ordering of objects based on some relationship between them
Help us understand complex systems Example - a company hierarchy helps employees
understand the company and their positions within it
For complex systems, a useful way of ordering similar abstractions is a taxonomy from least general to most general
OO Design and Programming Object-oriented design and programming methodology
supports good software engineering
Promotes thinking in a way that models the way we think and interact with the real world
Example - watching television The remote is a physical object with
properties Weight, size, can send message
to the television The television is also a physical object
with various properties You are also a physical object
With eyes, ears, etc.
Objects An object is almost anything with the following
characteristics
Name (Identity)
Properties (data and function members)
The ability to act upon receiving a message Basic message types
• Directive to perform an action (function member)• Request to change one of its properties (mutator)• Request to get the value of one of its attributes
(accessor)
All you need is love objects?
Objects are implementations of Abstract Data Structures
But to make programs, we also need algorithms!
Algorithms + Data Structures = Programs Nicklaus Wirth (creator of Pascal)
What’s an Algorithm?
A predetermined series of instructions for carrying out a task in a finite number of steps I.e., Baking A Cake!
Two commonly used tools to help document the program logic (the algorithm): Flowcharts and Pseudocode.
Generally, Flowcharts work well for small problems but Pseudocode is used for larger problems
Flowchart: Symbolic Representation of Algorithms
Flowchart: A graphic representation of an algorithm, often used in the design phase of programming to work out the logical flow of a program
Some Control Structures Sequence Selection Repetition (Looping)
Pseudocode! What is pseudocode?
Pseudocode is basically short, English phrases used to explain specific tasks within a program's algorithm. Pseudocode should not include keywords in any specific computer languages. Indentation can be used to show the logic in pseudocode as well.
Why is pseudocode necessary? Writing pseudocode WILL save you time later during the construction & testing phase of a program's
development let’s you “think out” the program before you code it. How do I write pseudocode?
Consists mainly of executable statements
Original Program Specification: Write a program that obtains two integer numbers from the user. It will print out the sum of those numbers.
Variables required (names and types): int1: (integer) to store first integerint2: (integer) to store the second integersum: (integer) to store the sum of the numbers
Pseudocode: Prompt the user to enter the first integer int1Prompt the user to enter a second integer int2Compute the sum of the two user inputs sum = int1 + int2Display an output prompt that explains the answerDisplay the result
If you can’t write it in pseudocode, you won’t be able to write it in C++!
Error, error… does not compute! Syntax Errors – Typing Errors
Errors in spelling and grammar (syntax). “Doag. Bites, Man”
You can use the compiler or interpreter to uncover syntax errors.
You must have a good working knowledge of error messages to discover the cause of the error.
Semantic Errors – Logic or Meaning Errors Errors that indicate the logic used when coding the program
failed to solve the problem. “Man bites dog.”
You do not get error messages with logic errors. Your only clue to the existence of logic errors is the
production of wrong solutions. Run-time Errors (Exceptions)
Code does something illegal when it is run (hence runtime) E.g., divide by zero
Syntax refers to the structure of a program and the rules about that structure
In-Class Exercise
Write an algorithm that will, given the current date, find the date of the next day.
Pseudo-code Solution 1) Get the current date
- Get the current month, day, and year in numerical form
2) If month is 2, If day = 29 or day = 28 and it's not a leap year increment month else increment day else if month = 1,3,5,7,8,10,12 If day = 31 increment month else increment day else if month = 4,6,9,11 If day = 30 increment month else increment day
3) Report "new" date [month, day, year]
Increment Day add 1 to current day
Increment Month if month = 12 increment year else add 1 to current month day = 1
Increment Year add 1 to current year month = 1
Leap Year divisible by 400 or divisible by 4 but not 100
In-Class Exercise
Write the pseudo-code for a Game of Monopoly
Write the pseudo-code for one person’s move as a procedure
Draw a flowchart representing one person’s move as a procedure
Pseudo-Code Solutions This is the pseudocode for a Game of Monopoly, including one person's move as a
procedure:
Main Procedure Monopoly_Game Hand out each player's initial money. Decide which player goes first. Repeat Call Procedure Monopoly_Move for next player. Decide if this player must drop out. Until all players except one have dropped out. Declare the surviving player to be the winner.
Procedure Monopoly_Move Begin one's move. Throw the dice. Move the number of spaces on the board shown on the dice. If the token landed on "Go to Jail," then go there immediately. Else if the token landed on "Chance" or "Community Chest," then draw a card and follow its instructions. Else follow the usual rules for the square (buying property, paying rent, collecting $200 for passing "Go", etc.). End one's move.
Flowchart Procedure Solution
One Person’s Move: