Presentation is loading. Please wait.

Presentation is loading. Please wait.

ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 3: Requirements Specification, C++ Basics.

Similar presentations


Presentation on theme: "ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 3: Requirements Specification, C++ Basics."— Presentation transcript:

1 ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 3: Requirements Specification, C++ Basics

2 Lecture outline Review: software design cycle Requirements specifications  Introduce UML, use case diagrams Applying design cycle to ECE 264 C++ basics 10/3/2015 ECE 264: Lecture 3 2

3 Software design cycle Software engineering: application of systematic approach to development, operation, and maintenance of software  Not just programming!  Lots of management involved Traditional software design cycle  Requirements engineering  Design  Programming  Integration  Delivery  Maintenance 10/3/2015 ECE 264: Lecture 3 3

4 Use case modeling Often preceded by “requirements gathering”  Formal name for “figure out what the clients want”  Can be done through use case modeling Formally model interactions of user(s) with system  Can then go from use cases to requirements specification Take general use cases and break down into more specific examples Formalize these steps into a specification for actions May also have to specify data to be stored, states to be kept, etc. 10/3/2015 ECE 264: Lecture 3 4

5 Use case diagrams Textbook example: ATM system  Assume we’re designing software for basic ATM  Given hardware description of user interface Screen to display messages Keypad for numeric input  Assume account # must be entered Cash dispenser Deposit slot  For what operations might someone want to use this ATM? 10/3/2015 ECE 264: Lecture 3 5

6 Use case modeling Source: http://newportoregon.gov/dept/npd/atmsafety.asp 10/3/2015 ECE 264: Lecture 3 6

7  2008 Pearson Education, Inc. All rights reserved. 7 Fig. 2.18 | Use case diagram for the ATM system from the user’s perspective.

8 From use case to requirements spec. What steps occur before accessing account?  Screen displays basic welcome message  Enter account #  Screen prompts user to enter PIN  Screen displays main menu if PIN correct; error otherwise (and returns to welcome) What steps should we take to withdraw money?  Choose “Withdraw money” option from menu  Screen displays amounts to be withdrawn, option to cancel, potentially option to enter different amount  Based on user input, system either proceeds with withdrawal or cancel To proceed, must check two conditions: account has enough money, and ATM has enough cash available Display error message if either condition is not true Supply money and debit account otherwise 810/3/2015 ECE 264: Lecture 3

9 UML diagrams Use case diagram is example of Unified Modeling Language (UML) diagram  General-purpose modeling language  Uses graphical techniques to create abstract system models Can use UML to describe  Requirements: how can someone use system?  Design: both at high and low level Overall and specific structures Overall and specific behaviors 10/3/2015 ECE 264: Lecture 3 9

10 UML diagrams Thirteen types of UML diagram  Model either system structure or system behavior  We’ll focus on: Use case diagram: model interactions between system and external entities in terms of system capabilities Class diagram: shows classes: building blocks of system State machine diagram: models way in which object changes state (i.e., attributes change value) Activity diagram: models actions performed and specifies order for an object Communication diagram: shows interaction between objects; focus on what interactions occur Sequence diagram: shows interaction between objects; focus on when interactions occur 10/3/2015 ECE 264: Lecture 3 10

11 Basic Program 1 // Adapted from figure 2.1 in text // Text-printing program #include // Allows program to // output data to the screen using std::cout; // function main begins program execution int main() { // display message cout << "Welcome to C++!\n"; return 0; // indicate program ended successfully } // end function main 10/3/2015 ECE 264: Lecture 3 11

12 Namespaces; using Directive The using directive instructs the compiler to use files defined within a specific namespace  Namespaces allow us to declare different scopes  Typically written right after the relevant header file(s) Example: using namespace std;  std is the name of the Standard C++ namespace  Including this line allows you to avoid specifying namespace for every identifier in your headers …  … but allows everything in the std namespace  Compromise: list namespace members actually used using std::cout; Otherwise, you’d have to write “ std::cout ” every time 10/3/2015 ECE 264: Lecture 3 12

13 Input/output streams C++ has three standard input/output streams  cin is the standard input (e.g., keyboard)  cout is the standard output  cerr is the standard error 10/3/2015 ECE 264: Lecture 3 13

14 Input/output streams (cont.) Standard output  Use the stream output operator << to direct data to cout  General Form: cout << expression << expression;  Note: An expression is a C++ constant, identifier, formula, or function call.  endl can be used to place an output character in the buffer and flush the buffer 10/3/2015 ECE 264: Lecture 3 14

15 15 Modifying Our First C++ Program Two examples  Print text on one line using multiple statements (Fig. 2.3) Each stream insertion resumes printing where the previous one stopped  Print text on several lines using a single statement (Fig. 2.4) Each newline escape sequence positions the cursor to the beginning of the next line Two newline characters back-to-back outputs a blank line 10/3/2015 ECE 264: Lecture 3

16 Modified program: two cout statements // Adapted from figure 2.3 in text // Printing a line of text with multiple statements #include // Allows program to // output data to the screen using std::cout; // function main begins program execution int main() { // display message cout << "Welcome " cout << "to C++!\n"; return 0; // indicate program ended successfully } // end function main 10/3/2015 ECE 264: Lecture 3 16

17 Modified program: multiple output lines 10/3/2015 ECE 264: Lecture 3 17 // Adapted from figure 2.4 in text // Printing multiple lines of text with one statement #include // Allows program to // output data to the screen using std::cout; // function main begins program execution int main() { // display message cout << "Welcome\nto\n\nC++!\n"; return 0; // indicate program ended successfully } // end function main

18 Another C++ Program: Adding Integers Variable  Is a location in memory where a value can be stored  Common data types (fundamental, primitive or built-in) int – for integer numbers char – for characters double – for floating point numbers  Declare variables with data type and name before use int integer1; int integer2; int sum; 10/3/2015 ECE 264: Lecture 3 18

19 Input streams Standard input  Use the stream input operator >> to direct keyboard input to variables  General Form: cin >> identifier >> identifier;  Input value must be compatible with identifier type 10/3/2015 ECE 264: Lecture 3 19

20 Basic program 2 // Adapted from figure 2.5 in text // Addition program that displays the sum of two integers. #include using std::cout; using std::cin; using std::endl; int main() { // variable declarations int number1; int number2; int sum; // prompt user for data and read into appropriate variables cout << "Enter first integer: "; cin >> number1; cout << "Enter second integer: "; cin >> number2; sum = number1 + number2; // add the numbers; store result in sum cout << "Sum is " << sum << endl; // display sum; end line return 0; // indicate that program ended successfully } // end function main 10/3/2015 ECE 264: Lecture 3 20

21 Final notes Next time Continue with C++ basics More examples of basic I/O Acknowledgements: this lecture borrows heavily from lecture slides provided with the following texts: Deitel & Deitel, C++ How to Program, 8 th ed. Etter & Ingber, Engineering Problem Solving with C++, 2 nd ed. 10/3/2015 ECE 264: Lecture 3 21


Download ppt "ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 3: Requirements Specification, C++ Basics."

Similar presentations


Ads by Google