1 / 47

Introduction

Software Crisis. Common software systems behaviorDoes not provide required functionalityIs over budget with respect to time and money and computer resource usageNot adaptable to changing user needsWhy?User needs are ill-specifiedComplexity of interactions grows multiplicativelyHuman coopera

kaveri
Download Presentation

Introduction

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


    1. Introduction Software Engineering with OOP

    2. 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

    3. 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

    4. 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 values and behavior — objects

    5. 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]

    6. A C++ Program // Canonical first program #include <iostream> #include <string> using namespace std; int main() { cout << "Hello world!" << endl; return 0; }

    7. Review of C/C++: Variables Several different types int integers (2, 7, 12) float decimal numbers (3.14, 7.81) char single characters (‘a’, ‘4’) char[] used for strings (“Hello”, “Hi”) bool true or false

    8. Control Structures (if-then-else)

    9. Control Structures (while/do-while)

    10. Control Structures (for)

    11. Control Structures (switch)

    12. Arrays Group homogenous information together REMEMBER WE START COUNTING AT 0! int v[4] means we actually have 4 elements: v[0], v[1], v[2], and v[3]. There is no v[4]!

    13. Functions

    14. struct Essentially a collection of variables Used when heterogenous information needs to be grouped Can have arrays of structs (orthogonality) By default, everything’s public Functions allowed within structs in C++ (class is a struct on steroids)

    15. Pointers Special variable that only holds memory addresses Holds the location (address) of information, not the information itself Two operators: address-of and dereferencing operators &variable “the address of variable” *pointer “data at the address contained in pointer”

    16. C and C++ C++ Improves on many of C's features Has object-oriented capabilities Increases software quality and reusability Allows faster and better development of large projects Developed by Bjarne Stroustrup at Bell Labs Called "C with classes" C++ (increment operator) - enhanced version of C Superset of C Can use a C++ compiler to compile C programs Gradually evolve the C programs to C++ C++ is much stricter than C ANSI C++ Final version at http://www.ansi.org/

    17. Some differences & conventions File extensions C files: .c C++ files: .cpp (which we use), .cxx, .C (uppercase) Header files: .h Differences C++ allows you to "comment out" a line by preceding it with // For example: // text to ignore <iostream> - input/output stream header file (no .h!) Return types - all functions must declare their return type C does not require it, but C++ does Variables in C++ can be declared almost anywhere In C, required to declare variables in a block, before any executable statements

    18. Input/Output Input/Output in C++ Performed with streams of characters Streams sent to input/output objects Data inserted into or extracted out of these streams Output std::cout - standard output stream (connected to screen) << stream insertion operator ("put to") std::cout << "hi"; Puts "hi" to std::cout, which prints it on the screen Input std::cin - standard input object (connected to keyboard) >> stream extraction operator ("get from") std::cin >> myVariable; Gets stream from keyboard and puts it into myVariable

    19. 1. Load <iostream> 2. main 2.1 Initialize variables integer1, integer2, and sum 2.2 Print "Enter first integer" 2.2.1 Get input 2.3 Print "Enter second integer" 2.3.1 Get input 2.4 Add variables and put result into sum 2.5 Print "Sum is" 2.5.1 Output sum 2.6 exit (return 0) Program Output A Simple Program: Adding Two Integers

    20. Input/Output modifiers std::endl "end line" Stream manipulator - prints a newline and flushes output buffer Some systems do not display output until "there is enough text to be worthwhile" std::endl forces text to be displayed using directive statements Allow us to remove the std:: prefix Just add “using namespace std;” or “using std::cout;” Discussed further later Cascading Can have multiple << or >> operators in a single statement (“chaining”) std::cout << "Hello " << "there" << std::endl;

    21. Namespaces Sets the scope of variables and identifiers (names), including functions! All unnamed namespaces are in global scope Just add “using namespace std;” directive Then you can just say cout instead of std::cout

    22. IO Manipulation Use “#include <iomanip>” to access the input/output manipulation functions setw(int) ? set width of the field setprecision(int) ? sets # of decimal places setiosflags(ios::left) ? set alignment, etc.

    23. Scopes, Casts, & Manipulators Unary scope resolution operator (::) Access global variables if a local variable has same name Instead of variable use ::variable static_cast<newType> (variable) Creates a copy of variable of type newType Convert ints to floats, etc. Stream manipulators Can change how output is formatted setprecision - set precision for floats (default 6 digits) setiosflags - formats output setwidth - set field width

    24. 1. Initialize global const PI 1.1 cast global PI to a local float 2. Print local and global values of PI 2.1 Vary precision and print local PI

    25. Software Engineering Goals

    26. An object represents some thing E.g., a physical entity, a concept, software module, etc. An object knows things (attributes) An object does things (methods) Objects ride to the rescue!

    27. 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 (divided into classes or types) Encapsulation Hide and protect essential information (implementation details) behind a controlled interface Inheritance Ability to create new classes based on existing ones Polymorphism Exhibiting the same behaviour differently on different classes or subclasses Persistance

    28. 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

    29. What about encapsulation? Let’s look at an Operating System: Kernel and HW are encapsulated together and hidden from the user (User only has access to HW via the UI)

    30. Objects and Encapsulation The idea that the attributes and methods of an object are encapsulated together Information Hiding refers to the idea that the only way to access data is via the public interface

    31. 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

    32. 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

    33. A class can extend from a previously defined class A class is a collection of similar objects Inheritance!

    34. 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

    35. Polymorphism Principle that objects in different classes may understand the same message (same function name) yet respond in different ways.

    36. 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.

    37. 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)

    38. 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)

    39. 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

    40. 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

    41. Some Control Structures Sequence Selection Looping

    42. 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 integer int2: (integer) to store the second integer sum: (integer) to store the sum of the numbers Pseudocode: Prompt the user to enter the first integer int1 Prompt the user to enter a second integer int2 Compute the sum of the two user inputs sum = int1 + int2 Display an output prompt that explains the answer Display the result

    43. 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

    44. 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

    45. 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.

    46. Flowchart Procedure Solution One Person’s Move:

    47. In-Class Exercise Write an algorithm that will, given the current date, find the date of the next day.

    48. 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

More Related