Download presentation
Presentation is loading. Please wait.
Published byCora Robbins Modified over 9 years ago
1
Problem Solving and Software Engineering Chapter 1
2
C++, An Introduction to Computing, 3rd Ed. 2 Objectives Indicate uses of computers First look at a C++ program Basic phases of software life cycle Object-centered design Issues, ethical principles First look: classes and object-oriented design
3
C++, An Introduction to Computing, 3rd Ed. 3 Uses of Computers Industry Robots, CAD, project management and control Government Defense, space, compile data, weather Medicine Medical records, life support systems, CAT scan, MR scan Entertainment Animation, colorization, special effects Science Simulations, molecule analysis, food quality testing Information Technology Digital libraries, online art
4
C++, An Introduction to Computing, 3rd Ed. 4 What is Programming? Computer Program A sequence of statements that instruct a computer in how to solve a problem. Programming The act of designing, writing and maintaining a program Programmers People who write programs
5
C++, An Introduction to Computing, 3rd Ed. 5 The World of C++ Sample program /* greeting.cpp greets its user. * * Input: The name of the user * Output: A personalized greeting *********************************************************/ #include // cin, cout, > #include // string using namespace std; int main() { cout << "Please enter your first name: "; string firstName; cin >> firstName; cout << "\nWelcome to the world of C++, " << firstName << "!\n"; } Comment Compiler directives Specifies standard related names Main portion of program. Contains C++ statements.
6
C++, An Introduction to Computing, 3rd Ed. 6 The World of C++ C++ statements int main() { cout << "Please enter your first name: "; string firstName; cin >> firstName; cout << "\nWelcome to the world of C++, " << firstName << "!\n"; } Output statement to prompt user Variable declaration Input from keyboard stored in variable Output character string and value stored in variable
7
C++, An Introduction to Computing, 3rd Ed. 7 Problem Solving through Software Engineering Phases Design Analysis, specify algorithms to solve problem Coding Write solution in syntax of language Testing, Execution, Debugging Get rid of “bugs” Maintenance Update, modify to meet changing needs
8
C++, An Introduction to Computing, 3rd Ed. 8 Problem World’s largest ball of twine found in Cawker City, Ks. Cawker City, Ks. How much does the ball weigh? How many miles would the twine reach if unrolled?
9
C++, An Introduction to Computing, 3rd Ed. 9 Object-Centered Design Steps State how you want the program to behave Identify real-world objects, categorize Identify operations needed to solve the problem Develop algorithm – arrange objects, operations in an order which solve the problem
10
C++, An Introduction to Computing, 3rd Ed. 10 Behavior To find the weight of a ball of string: Enter radius of sphere : 9 Now computing... Weight of ball of string = 999.99
11
C++, An Introduction to Computing, 3rd Ed. 11 Objects Description Software Objects TypeKindName prompt for radius of sphere string constantnone screen ostream variable cout radius of sphere double variable radius keyboard istream variable cin weight of ball double variable weight
12
C++, An Introduction to Computing, 3rd Ed. 12 Operations Output prompt for radius of sphere to cout Input real value from cin Store it in radius Compute weight Output weight to cout
13
C++, An Introduction to Computing, 3rd Ed. 13 More Objects Computation of weight requires additional objectsW=density * 4 ( π r^3 )/3 Description Software Objects TypeKindName density of sphere double variable density 4.0 double constant π double constant PI 3 integer constant 3.0 double constant
14
C++, An Introduction to Computing, 3rd Ed. 14 Algorithm 1. Initialize constant PI 2. Output prompt for radius to cout 3. Input real value from cin, store in radius 4. Output prompt for density to cout 5. Input real value from cin, store in density 6. Compute 7. Output weight to cout
15
C++, An Introduction to Computing, 3rd Ed. 15 Coding First, create a program stub that contains opening documentation Compiler directives that add items in libraries needed for some of the Objects and operations An empty main function Convert each step of the algorithm into code. If it uses a software object that hasn’t already been declared, add a declaration statement that specifies the object’s type and name.
16
C++, An Introduction to Computing, 3rd Ed. 16 Coding /* sphereWeight.cpp computes the weight of a sphere. * * Input: The radius (feet) and * the density (pounds/cubic foot) of a sphere * Output: The weight of the sphere (pounds) ************************************************/ #include // cin, cout, > #include // pow() using namespace std; int main() { }
17
C++, An Introduction to Computing, 3rd Ed. 17 Coding int main() { const double PI = 3.14159; cout << "Enter the sphere's radius (feet): "; double radius; cin >> radius; cout << "Enter its density (pounds/cubic feet): "; double density; cin >> density; double weight = density * 4.0 * PI * pow(radius, 3) / 3.0; cout << "\nThe weight of the sphere is approximately " << weight << " pounds.\n"; }
18
C++, An Introduction to Computing, 3rd Ed. 18 Testing Enter radius of sphere (feet) : 6.5 Enter its density (pounds/cubic feet) : 14.6 The weight of the sphere is approximately 16795 pounds
19
C++, An Introduction to Computing, 3rd Ed. 19 Testing, Execution, Debugging Common error sources Violations of grammar rules of the high level language Errors that occur during execution Errors in the design of the algorithm
20
C++, An Introduction to Computing, 3rd Ed. 20 Syntax Errors Example: double radius Missing semi-colon Compiler finds most of these kinds of errors Different compilers give varying degrees of helpful diagnostics
21
C++, An Introduction to Computing, 3rd Ed. 21 Run Time Errors Not detected until program runs Examples Division by zero causes program to crash Taking square root of negative causes program crash Program must be modified to keep such events from happening
22
C++, An Introduction to Computing, 3rd Ed. 22 Logic Errors Program compiles, runs without crashing, but gives incorrect results These are hardest errors to find Find by using sample data and hand calculating the correct results, comparing Note: Testing grows increasingly more difficult with larger programs Some will run for years without logic error appearing
23
C++, An Introduction to Computing, 3rd Ed. 23 Maintenance Student programs run only a few times Real-world programs used for many years Due to significant investment of resources New features may be required during life of program usage Upgrading called “maintenance”
24
C++, An Introduction to Computing, 3rd Ed. 24 Problem Sam Splicer installs coax cable for Metro Cable Co. Basic service charge $25.00 Additional $2.00 for each foot of cable Company Pres. wants to compute revenue generated by Sam for given month Example: 263 yards of cable at 27 locations generates $2253.00 in revenue
25
C++, An Introduction to Computing, 3rd Ed. 25 Describe Behavior of Program Program should display prompt for number of installations performed and total number of yards of cable installed User enters values from keyboard Program computes, displays on screen total amount of revenue resulting from these installations
26
C++, An Introduction to Computing, 3rd Ed. 26 Behavior Envisioned To determine revenue generated, Enter number of installations : 27 Enter number of yards of cable installed : 263 Total revenue generated is $2253.00
27
C++, An Introduction to Computing, 3rd Ed. 27 Objects Use description to fill in chart for objects. Description Software Objects TypeKindName
28
C++, An Introduction to Computing, 3rd Ed. 28 Operations Description Name Predefined?LibraryOperator Use description to fill in chart for operations.
29
C++, An Introduction to Computing, 3rd Ed. 29 Algorithm and Coding Work together to determine the steps necessary to have the objects manipulated by the operations Write the source code Compile and Link Test the program
30
C++, An Introduction to Computing, 3rd Ed. 30 Ethics and Issues Consider the essay by Professor Anne Marchant (see web site of text) Ethics and Society Computer Crime and Security Health Concerns and the Environment Information Ownership “Netiquette” and Hoaxes Internet Content and Free Speech Privacy Quality Control and Risk Reduction The Future
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.