230 likes | 329 Views
Chapter-01. Introduction to Software Engineering. Software Engineering. Object-Oriented Design. Problem Solving. Does anyone carpet? Let’s solve this area problem: Write a program that, given a length and width, computes the area of a carpet. Behavior.
E N D
Chapter-01 Introduction to Software Engineering
Software Engineering Object-Oriented Design
Problem Solving • Does anyone carpet? • Let’s solve this area problem: • Write a program that, given a length and width, computes the area of a carpet.
Behavior A. Describe the desired behavior of the program: Our program should display a prompt for length and width of the carpet, read length and width of the carpet from the keyboard, compute the corresponding area, and display the area, along with a descriptive label on the screen.
Objects and Attributes B. Identify the nouns in the behavioral description (other than program and user): Our program should display a prompt for length and width of the carpet on the screen, read length and width of the carpet from the keyboard, compute the corresponding area, and display the area, along with a descriptive label on the screen. These make up the objects and data members in our program.
Operations C. Identify the verbs in the behavioral description: Our program should display a prompt for the length and width of the carpet on the screen, read the length and width from the keyboard, compute the corresponding area, and display the area, along with a descriptive label on the screen. These make up the operations in our program.
Algorithm D. Organize the objects and operations into a sequence of steps that solves the problem, called an algorithm. 1. Define the class carpet and its operations. 2. Create the object carpet_1. 2.1. Display a prompt for length and width on the screen. 2.2. Read length and width from the keyboard. 3. Send message to Compute area from length and width . 4. Display area , plus an informative label on the screen.
Coding Once we have designed an algorithm, the next step is to translate that algorithm into a high level language like C++. This involves figuring out how to • represent our objects and its operations, • send messages to objects for processed data, in C++ (with the aid of a book...)
Representing Objects A. Determine a type and name for each object:
Performing Operations B. Identify the C++ operator to perform a given operation, if there is one... To compute area, object needs to find the area-length-width formula in a geometry book...
Length and Width-to-Area In a geometry book, we find that • area is the product of length and width
Documentation Always begin a file with an openingcomment: /* area.cpp is a area calculating utility. * Author: Bazlur Rasheed * Date: 02 July 2000 * Purpose: Calculate area of a rectangle. */
Coding: Defining class carpet /* area.cpp is a area calculating utility. * ... */ class carpet{ public: carpet(); int cal_area(); private: int length, width; };
Coding: Defining class carpet //... carpet::carpet() { cout <<"\n Enter the length (meter) and” << “ width (meter)” << "\n seperated by a space and “ << “ followed by the enter key: ”; cin >> length >> width; } int carpet::cal_area() { return (length*width); }
Coding: Program Stub /* area.cpp is a area calculating utility. * ... */ #include <iostream> // cin, cout, <<, >> using namespace std; void main(void) { }
Coding: Algorithm Steps 1 // ... void main(void) { cout << “\n Rectangular Area Calculator!!”; }
Coding: Algorithm Steps 2 // ... void main(void) { cout << “\n Rectangular Area Calculator!”; carpet carpet_1; }
Coding: Algorithm Step 3 // ... void main(void) { cout << “\n Rectangular Area Calculator!”; carpet carpet_1; int area = carpet_1.cal_area(); }
Coding: Algorithm Step 4 // ... void main(void) { cout << “\n Rectangular Area Calculator!”; carpet carpet_1; int area = carpet_1.cal_area(); cout << "\n The area is " << area << ” square meter. \n\n"; }
Testing Run your program using sample data (whose correctness is easy to check): Rectangular Area Calculator! Enter the length (meter) and width (meter) separated by a space and followed by the enter key: 10 20 The area is 200 square meter
Summary of OOD OOD is a methodology for designing programs: 1. Describe the desired behavior of the program. 2. Identify the objects and it’s operations required. 4. Organize objects and messages into an algorithm, refining object and its operation lists as necessary.
Summary of OOP Programming Writing a program consists of these steps: 1. Design relevent objects and algorithm for your program. 2. Code your design. 3. Test your program. 4. Maintain/upgrade your program as necessary.