SlideShare a Scribd company logo
1 of 24
Programming and
Problem Solving —
Software Engineering
(Read Chap. 2)
1
Problem Solving
A Temperature-conversion problem:
Write a program that, given a temperature in Celsius,
displays that temperature in Fahrenheit.
• Implementation (Coding)
• Testing, Execution and Debugging
• Maintenance
OCD (Object-Centered Design)
2
5 Phases of (Simplified) Software Life Cycle:
• Problem Analysis and Specification
• Design
OCD (Object-Centered Design)
1. Describe the behavior of the program.
2. Identify the problem’s objects and make
a table of information about them.
3. Identify the problem’s operations and
make a table of information about them.
4. Organize the objects and operations into a
sequence of steps, called an algorithm,
to solve the problem.
3
Behavior
A. Describe the desired behavior of the program:
Our program should display program information
to the user and then a prompt for the
Celsius temperature on the screen, read that
temperature from the keyboard, compute the
corresponding Fahrenheit temperature, and
display the result, along with a descriptive
label on the screen.
4
Using
OCD
Problem Objects
B. Identify the nouns in the behavioral description (other than
"non-behavioral" ones like "program" and "user"):
Our program should display program information
to the user and then a prompt for the
Celsius temperature on the screen, read that
temperature from the keyboard, compute the
corresponding Fahrenheit temperature, and
display that temperature, along with a descriptive
label on the screen.
These make up the objects in our problem.
5
Using
OCD
cout
cin
Information about Objects
Determine a type and a name (if necessary) for each
object and whether it is a constant or a variable.
6
Problem Object Type Kind Name
program information text constant none
prompt text constant none
Celsius temperature real
number
variable celsius
screen output variable
keyboard input variable
Fahrenheit temperature real
number
variable fahrenheit
label text constant none
Using
OCD
C++ Type
?
?
double
?
?
double
?
Operations
These make up the operations in our problem.
C. Identify the verbs in the behavioral description:
Our program should display program information
to the user and then a prompt for the
Celsius temperature on the screen, read that
temperature from the keyboard, compute the
corresponding Fahrenheit temperature, and
display that temperature, along with a descriptive
label on the screen.
7
Using
OCD
Information about Operations
Identify the C++ operator to perform
a given operation, if there is one.
To compute the Fahrenheit temperature, we need to
know/find the Celsius to Fahrenheit conversion formula.
8
Operation
Pre-
defined?
C++
Operator Library
Display yes << iostream
Read yes >> iostream
Compute the Fahrenheit
temperature
?? ?? ??
Using
OCD
Celsius-to-Fahrenheit
Formula for converting Celsius to Fahrenheit:
fahrenheit = 1.8 × celsius + 32
Converting the temperature thus adds new
objects and operations to our problem.
9
Using
OCD
Information about Objects
(Revised)
10
Problem Object Type Kind C++ Type Name
program information text constant ? none
prompt text constant ? none
Celsius temperature real
number
variable double celsius
screen output variable ? cout
keyboard input variable ? cin
Fahrenheit temperature real
number
variable double fahrenheit
label text constant ? none
conversion
factor 1.8
real
number
constant double none
conversion
factor 32
integer constant int none
Using
OCD
Information about Operations
(Revised)
11
Operation
Pre-
defined?
C++
Operator Library
Display yes << iostream
Read yes >> iostream
Compute the Fahrenheit
temperature:
Multiply two real values
(1.8 and celsius)
yes * built-in
Add a real value (the result
above) and an integer (32)
yes + built-in
Store a real value (the
result above) in a variable
yes = built-in
Using
OCD
Algorithm
D. Organize the objects and operations into a
sequence of steps that solves the problem,
called an algorithm.
1. Display via cout information about the program
to the user.
2. Display via cout a prompt for the Celsius temperature.
3. Read the temperature from cin.
4. Compute the Fahrenheit temperature from the Celsius
temperature.
5. Display via cout the Fahrenheit temperature and an
informative label.
12
Using
OCD
Coding
Once we have designed an algorithm, the next
step is to translate that algorithm into a high
level language like C++.
This involves writing instructions to
— represent the objects, and
— perform the operations
in C++.
13
14
The Code
When learning
to program, it
is helpful to
just start with
the algorithm
as comments
in main()
/*
John Doe
CS 104X
Input:
Output:
-----------------------------------------------*/
#include <iostream> // cin, cout, <<, >>
using namespace std;
int main()
{
}
/* temperature.cpp converts a Celsius
temperature to Fahrenheit.
John Doe Lab 1 Jan. 5, 2012
CS 104X
Input: A Celsius temperature
Output: Corresponding Fahrenheit temperature
-----------------------------------------------*/
#include <iostream> // cin, cout, <<, >>
using namespace std;
int main()
{
// 1. Display via cout information about the
// program to the user.
// 2. Display via cout a prompt for the Celsius
// temperature.
// 3. Read the temperature from cin.
// 4. Compute the Fahrenheit temperature from the
// Celsius temperature.
// 5. Display via cout the Fahrenheit temperature
// and an informative label.
}
cout << "John Doe CS 104X -- Lab 1nn";
cout << "** Convert Celsius temps to Fahrenheit **n";
cout << "Please enter a temperature in Celsius: "; 15
/* temperature.cpp converts a Celsius
temperature to Fahrenheit.
John Doe Lab 1 Jan. 5, 2012
CS 104X
Input: A Celsius temperature
Output: Corresponding Fahrenheit temperature
-----------------------------------------------*/
#include <iostream> // cin, cout, <<, >>
using namespace std;
int main()
{
// 1. Display via cout information about the
// program to the user.
// 2. Display via cout a prompt for the Celsius
// temperature.
The Code
double celsius;
cin >> celsius;
double fahrenheit = 1.8 * celsius + 32;
cout << celsius << " degrees Celsius is "
<< fahrenheit << " degrees Fahrenheit.n";
16
// 3. Read the temperature from cin.
// 4. Compute the Fahrenheit temperature from the
// Celsius temperature.
// 5. Display via cout the Fahrenheit temperature
// and an informative label.
}
The Code
It’s wise to echo input
data to insure computer
read what you intended.
17
Comments
/* temperature.cpp converts a Celsius
temperature to Fahrenheit.
John Doe Lab 1 Jan. 5, 2012
CS 104X
Input: A Celsius temperature
Output: Corresponding Fahrenheit temperature
-----------------------------------------------*/
#include <iostream> // cin, cout, <<, >>
using namespace std;
int main()
{
// 1. Display via cout information about the
// program to the user.
cout << "John Doe CS 104X -- Lab 1nn";
cout << "** Convert Celsius temps to Fahrenheit **n";
// 2. Display via cout a prompt for the Celsius
// temperature.
cout << "Please enter a temperature in Celsius: ";
Always begin
a program with
opening
documentation
enclosed in
/* and */.
/* temperature.cpp converts a Celsius
temperature to Fahrenheit.
John Doe Lab 1 Jan. 5, 2012
CS 104X
Input: A Celsius temperature
Output: Corresponding Fahrenheit temperature
-----------------------------------------------*/
#include <iostream> // cin, cout, <<, >>
using namespace std;
int main()
{
// 1. Display via cout information about the
// program to the user.
cout << "John Doe CS 104X -- Lab 1nn";
cout << "** Convert Celsius temps to Fahrenheit **n";
// 2. Display via cout a prompt for the Celsius
// temperature.
cout << "Please enter a temperature in Celsius: "; 18
Libraries
This loads the C++
library that we need.
Lab & Proj. 1: #include <cmath>
19
/* temperature.cpp converts a Celsius
temperature to Fahrenheit.
John Doe Lab 1 Jan. 5, 2012
CS 104X
Input: A Celsius temperature
Output: Corresponding Fahrenheit temperature
-----------------------------------------------*/
#include <iostream> // cin, cout, <<, >>
using namespace std;
int main()
{
// 1. Display via cout information about the
// program to the user.
cout << "John Doe CS 104X -- Lab 1nn";
cout << "** Convert Celsius temps to Fahrenheit **n";
// 2. Display via cout a prompt for the Celsius
// temperature.
cout << "Please enter a temperature in Celsius: ";
Each step of the
algorithm is implemented
by one or more C++
program statements
inside main() function.
Why no n ?
20
// 3. Read the temperature from cin.
double celsius;
cin >> celsius;
// 4. Compute the Fahrenheit temperature from the
// Celsius temperature.
double fahrenheit = 1.8 * celsius + 32;
// 5. Display via cout the Fahrenheit temperature
// and an informative label.
cout << celsius << " degrees Celsius is "
<< fahrenheit << " degrees Fahrenheit.n";
}
Each step of the
algorithm is implemented
by one or more C++
program statements
inside main() function.
Note spacing, indentation, & alignment to make
program “look nice” and easier to read.
This will be one criterion used in grading.
Always
a good
idea to
echo
input data
Testing
Run your program using sample data (whose
correctness is easy to check):
John Doe CS 104X -- Lab 1
** Convert Celsius temps to Fahrenheit **
Please enter the temperature in Celsius: 0
0 degrees Celsius is 32 degrees Fahrenheit.
21
John Doe CS 104X -- Lab 1
** Convert Celsius temps to Fahrenheit **
Please enter the temperature in Celsius: 100
100 degrees Celsius is 212 degrees Fahrenheit.
When you are convinced that the program is
correct, run it with the required data values.
John Doe CS 104X -- Lab 1
** Convert Celsius temps to Fahrenheit **
Please enter the temperature in Celsius: -17.78
-17.78 degrees Celsius is -0.004 degrees Fahrenheit.
22
23
For a programming assignment:
Lose a few points or may be lucky and the grader doesn’t
catch it.
For a real-world problem:
Much more may be at stake: money, jobs, and even lives.
Why Testing is Important:
• September,1999: Mars Climate Orbiter
• June, 1996: Ariane 5 rocket
• March,1991: DSC Communications
• February 25, 1991(Gulf War): Patriot missile
Testing is never finished; it is only stopped.
Testing can only show the presence of errors,
not their absence.
See
Other Course
Information
(CS 104 page):
• Importance of
Program Testing
— Horror Stories
Maintenance
24
• Large % of computer center budgets
• Large % of programmer's time
• Largest % of software development cost
Why?
Poor structure, poor documentation, poor style
⇒ less likely to catch bugs before release
⇒ fixing of bugs difficult and time-consuming
⇒ impede implementation of enhancements
See
Other Course
Information
(CS 104 page):
• Time Spent on
Program
Maintenance

More Related Content

Similar to 02.softwareengr.ppt

Lecture # 1 introduction revision - 1
Lecture # 1   introduction  revision - 1Lecture # 1   introduction  revision - 1
Lecture # 1 introduction revision - 1SajeelSahil
 
Introduction to C++ lecture ************
Introduction to C++ lecture ************Introduction to C++ lecture ************
Introduction to C++ lecture ************Emad Helal
 
C++ Overview
C++ OverviewC++ Overview
C++ Overviewkelleyc3
 
C++ programming language basic to advance level
C++ programming language basic to advance levelC++ programming language basic to advance level
C++ programming language basic to advance levelsajjad ali khan
 
Bottom of FormCreate your own FunctionFunctionsFor eac.docx
Bottom of FormCreate your own FunctionFunctionsFor eac.docxBottom of FormCreate your own FunctionFunctionsFor eac.docx
Bottom of FormCreate your own FunctionFunctionsFor eac.docxAASTHA76
 
Practical basics on c++
Practical basics on c++Practical basics on c++
Practical basics on c++Marco Izzotti
 
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...bhargavi804095
 
Cmis 102 Effective Communication / snaptutorial.com
Cmis 102  Effective Communication / snaptutorial.comCmis 102  Effective Communication / snaptutorial.com
Cmis 102 Effective Communication / snaptutorial.comHarrisGeorg12
 
AssignmentACSC_424_midterm_fall_2012.pdf1 ACSC42.docx
AssignmentACSC_424_midterm_fall_2012.pdf1  ACSC42.docxAssignmentACSC_424_midterm_fall_2012.pdf1  ACSC42.docx
AssignmentACSC_424_midterm_fall_2012.pdf1 ACSC42.docxssuser562afc1
 
Xilinx ISE introduction Tutorial #1
Xilinx ISE introduction Tutorial #1Xilinx ISE introduction Tutorial #1
Xilinx ISE introduction Tutorial #1guest1e88645e
 

Similar to 02.softwareengr.ppt (18)

Ch02.pdf
Ch02.pdfCh02.pdf
Ch02.pdf
 
Labsheet1stud
Labsheet1studLabsheet1stud
Labsheet1stud
 
Lecture # 1 introduction revision - 1
Lecture # 1   introduction  revision - 1Lecture # 1   introduction  revision - 1
Lecture # 1 introduction revision - 1
 
Introduction to C++ lecture ************
Introduction to C++ lecture ************Introduction to C++ lecture ************
Introduction to C++ lecture ************
 
C++ Overview
C++ OverviewC++ Overview
C++ Overview
 
C++ programming language basic to advance level
C++ programming language basic to advance levelC++ programming language basic to advance level
C++ programming language basic to advance level
 
Bottom of FormCreate your own FunctionFunctionsFor eac.docx
Bottom of FormCreate your own FunctionFunctionsFor eac.docxBottom of FormCreate your own FunctionFunctionsFor eac.docx
Bottom of FormCreate your own FunctionFunctionsFor eac.docx
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Apclass
ApclassApclass
Apclass
 
Practical basics on c++
Practical basics on c++Practical basics on c++
Practical basics on c++
 
Apclass (2)
Apclass (2)Apclass (2)
Apclass (2)
 
Chapter2
Chapter2Chapter2
Chapter2
 
Labsheet_3
Labsheet_3Labsheet_3
Labsheet_3
 
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
 
Cinfo
CinfoCinfo
Cinfo
 
Cmis 102 Effective Communication / snaptutorial.com
Cmis 102  Effective Communication / snaptutorial.comCmis 102  Effective Communication / snaptutorial.com
Cmis 102 Effective Communication / snaptutorial.com
 
AssignmentACSC_424_midterm_fall_2012.pdf1 ACSC42.docx
AssignmentACSC_424_midterm_fall_2012.pdf1  ACSC42.docxAssignmentACSC_424_midterm_fall_2012.pdf1  ACSC42.docx
AssignmentACSC_424_midterm_fall_2012.pdf1 ACSC42.docx
 
Xilinx ISE introduction Tutorial #1
Xilinx ISE introduction Tutorial #1Xilinx ISE introduction Tutorial #1
Xilinx ISE introduction Tutorial #1
 

More from hesam ahmadian

Jupyter Notebook_CheatSheet.pdf
Jupyter Notebook_CheatSheet.pdfJupyter Notebook_CheatSheet.pdf
Jupyter Notebook_CheatSheet.pdfhesam ahmadian
 
Microsoft PowerPoint - Ch120886.PDF
Microsoft PowerPoint - Ch120886.PDFMicrosoft PowerPoint - Ch120886.PDF
Microsoft PowerPoint - Ch120886.PDFhesam ahmadian
 
Microsoft PowerPoint - Ch120884.PDF
Microsoft PowerPoint - Ch120884.PDFMicrosoft PowerPoint - Ch120884.PDF
Microsoft PowerPoint - Ch120884.PDFhesam ahmadian
 
Microsoft PowerPoint - Ch106606.PDF
Microsoft PowerPoint - Ch106606.PDFMicrosoft PowerPoint - Ch106606.PDF
Microsoft PowerPoint - Ch106606.PDFhesam ahmadian
 
Microsoft PowerPoint - Ch91092.PDF
Microsoft PowerPoint - Ch91092.PDFMicrosoft PowerPoint - Ch91092.PDF
Microsoft PowerPoint - Ch91092.PDFhesam ahmadian
 
Microsoft PowerPoint - Ch90279.PDF
Microsoft PowerPoint - Ch90279.PDFMicrosoft PowerPoint - Ch90279.PDF
Microsoft PowerPoint - Ch90279.PDFhesam ahmadian
 
آشنایی_با_جعبه_ابزار_شبکه_عصبی_در.pdf
آشنایی_با_جعبه_ابزار_شبکه_عصبی_در.pdfآشنایی_با_جعبه_ابزار_شبکه_عصبی_در.pdf
آشنایی_با_جعبه_ابزار_شبکه_عصبی_در.pdfhesam ahmadian
 
5658 2018 10-22-13-55-26
5658 2018 10-22-13-55-265658 2018 10-22-13-55-26
5658 2018 10-22-13-55-26hesam ahmadian
 
Stock management in hospital pharmacy using chance constrained model predicti...
Stock management in hospital pharmacy using chance constrained model predicti...Stock management in hospital pharmacy using chance constrained model predicti...
Stock management in hospital pharmacy using chance constrained model predicti...hesam ahmadian
 

More from hesam ahmadian (14)

Jupyter Notebook_CheatSheet.pdf
Jupyter Notebook_CheatSheet.pdfJupyter Notebook_CheatSheet.pdf
Jupyter Notebook_CheatSheet.pdf
 
Microsoft PowerPoint - Ch120886.PDF
Microsoft PowerPoint - Ch120886.PDFMicrosoft PowerPoint - Ch120886.PDF
Microsoft PowerPoint - Ch120886.PDF
 
Microsoft PowerPoint - Ch120884.PDF
Microsoft PowerPoint - Ch120884.PDFMicrosoft PowerPoint - Ch120884.PDF
Microsoft PowerPoint - Ch120884.PDF
 
Microsoft PowerPoint - Ch106606.PDF
Microsoft PowerPoint - Ch106606.PDFMicrosoft PowerPoint - Ch106606.PDF
Microsoft PowerPoint - Ch106606.PDF
 
Microsoft PowerPoint - Ch91092.PDF
Microsoft PowerPoint - Ch91092.PDFMicrosoft PowerPoint - Ch91092.PDF
Microsoft PowerPoint - Ch91092.PDF
 
Microsoft PowerPoint - Ch90279.PDF
Microsoft PowerPoint - Ch90279.PDFMicrosoft PowerPoint - Ch90279.PDF
Microsoft PowerPoint - Ch90279.PDF
 
Dr Omidkhah97676.PDF
Dr Omidkhah97676.PDFDr Omidkhah97676.PDF
Dr Omidkhah97676.PDF
 
Dr Omidkhah97677.PDF
Dr Omidkhah97677.PDFDr Omidkhah97677.PDF
Dr Omidkhah97677.PDF
 
Dr Omidkhah97678.PDF
Dr Omidkhah97678.PDFDr Omidkhah97678.PDF
Dr Omidkhah97678.PDF
 
Dr Omidkhah97679.PDF
Dr Omidkhah97679.PDFDr Omidkhah97679.PDF
Dr Omidkhah97679.PDF
 
01.introduction.ppt
01.introduction.ppt01.introduction.ppt
01.introduction.ppt
 
آشنایی_با_جعبه_ابزار_شبکه_عصبی_در.pdf
آشنایی_با_جعبه_ابزار_شبکه_عصبی_در.pdfآشنایی_با_جعبه_ابزار_شبکه_عصبی_در.pdf
آشنایی_با_جعبه_ابزار_شبکه_عصبی_در.pdf
 
5658 2018 10-22-13-55-26
5658 2018 10-22-13-55-265658 2018 10-22-13-55-26
5658 2018 10-22-13-55-26
 
Stock management in hospital pharmacy using chance constrained model predicti...
Stock management in hospital pharmacy using chance constrained model predicti...Stock management in hospital pharmacy using chance constrained model predicti...
Stock management in hospital pharmacy using chance constrained model predicti...
 

Recently uploaded

NPPE STUDY GUIDE - NOV2021_study_104040.pdf
NPPE STUDY GUIDE - NOV2021_study_104040.pdfNPPE STUDY GUIDE - NOV2021_study_104040.pdf
NPPE STUDY GUIDE - NOV2021_study_104040.pdfDivyeshPatel234692
 
办理(NUS毕业证书)新加坡国立大学毕业证成绩单原版一比一
办理(NUS毕业证书)新加坡国立大学毕业证成绩单原版一比一办理(NUS毕业证书)新加坡国立大学毕业证成绩单原版一比一
办理(NUS毕业证书)新加坡国立大学毕业证成绩单原版一比一F La
 
Issues in the Philippines (Unemployment and Underemployment).pptx
Issues in the Philippines (Unemployment and Underemployment).pptxIssues in the Philippines (Unemployment and Underemployment).pptx
Issues in the Philippines (Unemployment and Underemployment).pptxJenniferPeraro1
 
tools in IDTelated to first year vtu students is useful where they can refer ...
tools in IDTelated to first year vtu students is useful where they can refer ...tools in IDTelated to first year vtu students is useful where they can refer ...
tools in IDTelated to first year vtu students is useful where they can refer ...vinbld123
 
办理学位证(Massey证书)新西兰梅西大学毕业证成绩单原版一比一
办理学位证(Massey证书)新西兰梅西大学毕业证成绩单原版一比一办理学位证(Massey证书)新西兰梅西大学毕业证成绩单原版一比一
办理学位证(Massey证书)新西兰梅西大学毕业证成绩单原版一比一A SSS
 
定制(NYIT毕业证书)美国纽约理工学院毕业证成绩单原版一比一
定制(NYIT毕业证书)美国纽约理工学院毕业证成绩单原版一比一定制(NYIT毕业证书)美国纽约理工学院毕业证成绩单原版一比一
定制(NYIT毕业证书)美国纽约理工学院毕业证成绩单原版一比一2s3dgmej
 
Kindergarten-DLL-MELC-Q3-Week 2 asf.docx
Kindergarten-DLL-MELC-Q3-Week 2 asf.docxKindergarten-DLL-MELC-Q3-Week 2 asf.docx
Kindergarten-DLL-MELC-Q3-Week 2 asf.docxLesterJayAquino
 
MIdterm Review International Trade.pptx review
MIdterm Review International Trade.pptx reviewMIdterm Review International Trade.pptx review
MIdterm Review International Trade.pptx reviewSheldon Byron
 
Application deck- Cyril Caudroy-2024.pdf
Application deck- Cyril Caudroy-2024.pdfApplication deck- Cyril Caudroy-2024.pdf
Application deck- Cyril Caudroy-2024.pdfCyril CAUDROY
 
Preventing and ending sexual harassment in the workplace.pptx
Preventing and ending sexual harassment in the workplace.pptxPreventing and ending sexual harassment in the workplace.pptx
Preventing and ending sexual harassment in the workplace.pptxGry Tina Tinde
 
Call Girls In Bhikaji Cama Place 24/7✡️9711147426✡️ Escorts Service
Call Girls In Bhikaji Cama Place 24/7✡️9711147426✡️ Escorts ServiceCall Girls In Bhikaji Cama Place 24/7✡️9711147426✡️ Escorts Service
Call Girls In Bhikaji Cama Place 24/7✡️9711147426✡️ Escorts Servicejennyeacort
 
办理哈珀亚当斯大学学院毕业证书文凭学位证书
办理哈珀亚当斯大学学院毕业证书文凭学位证书办理哈珀亚当斯大学学院毕业证书文凭学位证书
办理哈珀亚当斯大学学院毕业证书文凭学位证书saphesg8
 
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...Suhani Kapoor
 
Black and White Minimalist Co Letter.pdf
Black and White Minimalist Co Letter.pdfBlack and White Minimalist Co Letter.pdf
Black and White Minimalist Co Letter.pdfpadillaangelina0023
 
原版快速办理MQU毕业证麦考瑞大学毕业证成绩单留信学历认证
原版快速办理MQU毕业证麦考瑞大学毕业证成绩单留信学历认证原版快速办理MQU毕业证麦考瑞大学毕业证成绩单留信学历认证
原版快速办理MQU毕业证麦考瑞大学毕业证成绩单留信学历认证nhjeo1gg
 
Gray Gold Clean CV Resume2024tod (1).pdf
Gray Gold Clean CV Resume2024tod (1).pdfGray Gold Clean CV Resume2024tod (1).pdf
Gray Gold Clean CV Resume2024tod (1).pdfpadillaangelina0023
 
定制英国克兰菲尔德大学毕业证成绩单原版一比一
定制英国克兰菲尔德大学毕业证成绩单原版一比一定制英国克兰菲尔德大学毕业证成绩单原版一比一
定制英国克兰菲尔德大学毕业证成绩单原版一比一z zzz
 
Protection of Children in context of IHL and Counter Terrorism
Protection of Children in context of IHL and  Counter TerrorismProtection of Children in context of IHL and  Counter Terrorism
Protection of Children in context of IHL and Counter TerrorismNilendra Kumar
 
Ch. 9- __Skin, hair and nail Assessment (1).pdf
Ch. 9- __Skin, hair and nail Assessment (1).pdfCh. 9- __Skin, hair and nail Assessment (1).pdf
Ch. 9- __Skin, hair and nail Assessment (1).pdfJamalYaseenJameelOde
 

Recently uploaded (20)

NPPE STUDY GUIDE - NOV2021_study_104040.pdf
NPPE STUDY GUIDE - NOV2021_study_104040.pdfNPPE STUDY GUIDE - NOV2021_study_104040.pdf
NPPE STUDY GUIDE - NOV2021_study_104040.pdf
 
办理(NUS毕业证书)新加坡国立大学毕业证成绩单原版一比一
办理(NUS毕业证书)新加坡国立大学毕业证成绩单原版一比一办理(NUS毕业证书)新加坡国立大学毕业证成绩单原版一比一
办理(NUS毕业证书)新加坡国立大学毕业证成绩单原版一比一
 
Issues in the Philippines (Unemployment and Underemployment).pptx
Issues in the Philippines (Unemployment and Underemployment).pptxIssues in the Philippines (Unemployment and Underemployment).pptx
Issues in the Philippines (Unemployment and Underemployment).pptx
 
tools in IDTelated to first year vtu students is useful where they can refer ...
tools in IDTelated to first year vtu students is useful where they can refer ...tools in IDTelated to first year vtu students is useful where they can refer ...
tools in IDTelated to first year vtu students is useful where they can refer ...
 
FULL ENJOY Call Girls In Gautam Nagar (Delhi) Call Us 9953056974
FULL ENJOY Call Girls In Gautam Nagar (Delhi) Call Us 9953056974FULL ENJOY Call Girls In Gautam Nagar (Delhi) Call Us 9953056974
FULL ENJOY Call Girls In Gautam Nagar (Delhi) Call Us 9953056974
 
办理学位证(Massey证书)新西兰梅西大学毕业证成绩单原版一比一
办理学位证(Massey证书)新西兰梅西大学毕业证成绩单原版一比一办理学位证(Massey证书)新西兰梅西大学毕业证成绩单原版一比一
办理学位证(Massey证书)新西兰梅西大学毕业证成绩单原版一比一
 
定制(NYIT毕业证书)美国纽约理工学院毕业证成绩单原版一比一
定制(NYIT毕业证书)美国纽约理工学院毕业证成绩单原版一比一定制(NYIT毕业证书)美国纽约理工学院毕业证成绩单原版一比一
定制(NYIT毕业证书)美国纽约理工学院毕业证成绩单原版一比一
 
Kindergarten-DLL-MELC-Q3-Week 2 asf.docx
Kindergarten-DLL-MELC-Q3-Week 2 asf.docxKindergarten-DLL-MELC-Q3-Week 2 asf.docx
Kindergarten-DLL-MELC-Q3-Week 2 asf.docx
 
MIdterm Review International Trade.pptx review
MIdterm Review International Trade.pptx reviewMIdterm Review International Trade.pptx review
MIdterm Review International Trade.pptx review
 
Application deck- Cyril Caudroy-2024.pdf
Application deck- Cyril Caudroy-2024.pdfApplication deck- Cyril Caudroy-2024.pdf
Application deck- Cyril Caudroy-2024.pdf
 
Preventing and ending sexual harassment in the workplace.pptx
Preventing and ending sexual harassment in the workplace.pptxPreventing and ending sexual harassment in the workplace.pptx
Preventing and ending sexual harassment in the workplace.pptx
 
Call Girls In Bhikaji Cama Place 24/7✡️9711147426✡️ Escorts Service
Call Girls In Bhikaji Cama Place 24/7✡️9711147426✡️ Escorts ServiceCall Girls In Bhikaji Cama Place 24/7✡️9711147426✡️ Escorts Service
Call Girls In Bhikaji Cama Place 24/7✡️9711147426✡️ Escorts Service
 
办理哈珀亚当斯大学学院毕业证书文凭学位证书
办理哈珀亚当斯大学学院毕业证书文凭学位证书办理哈珀亚当斯大学学院毕业证书文凭学位证书
办理哈珀亚当斯大学学院毕业证书文凭学位证书
 
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...
 
Black and White Minimalist Co Letter.pdf
Black and White Minimalist Co Letter.pdfBlack and White Minimalist Co Letter.pdf
Black and White Minimalist Co Letter.pdf
 
原版快速办理MQU毕业证麦考瑞大学毕业证成绩单留信学历认证
原版快速办理MQU毕业证麦考瑞大学毕业证成绩单留信学历认证原版快速办理MQU毕业证麦考瑞大学毕业证成绩单留信学历认证
原版快速办理MQU毕业证麦考瑞大学毕业证成绩单留信学历认证
 
Gray Gold Clean CV Resume2024tod (1).pdf
Gray Gold Clean CV Resume2024tod (1).pdfGray Gold Clean CV Resume2024tod (1).pdf
Gray Gold Clean CV Resume2024tod (1).pdf
 
定制英国克兰菲尔德大学毕业证成绩单原版一比一
定制英国克兰菲尔德大学毕业证成绩单原版一比一定制英国克兰菲尔德大学毕业证成绩单原版一比一
定制英国克兰菲尔德大学毕业证成绩单原版一比一
 
Protection of Children in context of IHL and Counter Terrorism
Protection of Children in context of IHL and  Counter TerrorismProtection of Children in context of IHL and  Counter Terrorism
Protection of Children in context of IHL and Counter Terrorism
 
Ch. 9- __Skin, hair and nail Assessment (1).pdf
Ch. 9- __Skin, hair and nail Assessment (1).pdfCh. 9- __Skin, hair and nail Assessment (1).pdf
Ch. 9- __Skin, hair and nail Assessment (1).pdf
 

02.softwareengr.ppt

  • 1. Programming and Problem Solving — Software Engineering (Read Chap. 2) 1
  • 2. Problem Solving A Temperature-conversion problem: Write a program that, given a temperature in Celsius, displays that temperature in Fahrenheit. • Implementation (Coding) • Testing, Execution and Debugging • Maintenance OCD (Object-Centered Design) 2 5 Phases of (Simplified) Software Life Cycle: • Problem Analysis and Specification • Design
  • 3. OCD (Object-Centered Design) 1. Describe the behavior of the program. 2. Identify the problem’s objects and make a table of information about them. 3. Identify the problem’s operations and make a table of information about them. 4. Organize the objects and operations into a sequence of steps, called an algorithm, to solve the problem. 3
  • 4. Behavior A. Describe the desired behavior of the program: Our program should display program information to the user and then a prompt for the Celsius temperature on the screen, read that temperature from the keyboard, compute the corresponding Fahrenheit temperature, and display the result, along with a descriptive label on the screen. 4 Using OCD
  • 5. Problem Objects B. Identify the nouns in the behavioral description (other than "non-behavioral" ones like "program" and "user"): Our program should display program information to the user and then a prompt for the Celsius temperature on the screen, read that temperature from the keyboard, compute the corresponding Fahrenheit temperature, and display that temperature, along with a descriptive label on the screen. These make up the objects in our problem. 5 Using OCD
  • 6. cout cin Information about Objects Determine a type and a name (if necessary) for each object and whether it is a constant or a variable. 6 Problem Object Type Kind Name program information text constant none prompt text constant none Celsius temperature real number variable celsius screen output variable keyboard input variable Fahrenheit temperature real number variable fahrenheit label text constant none Using OCD C++ Type ? ? double ? ? double ?
  • 7. Operations These make up the operations in our problem. C. Identify the verbs in the behavioral description: Our program should display program information to the user and then a prompt for the Celsius temperature on the screen, read that temperature from the keyboard, compute the corresponding Fahrenheit temperature, and display that temperature, along with a descriptive label on the screen. 7 Using OCD
  • 8. Information about Operations Identify the C++ operator to perform a given operation, if there is one. To compute the Fahrenheit temperature, we need to know/find the Celsius to Fahrenheit conversion formula. 8 Operation Pre- defined? C++ Operator Library Display yes << iostream Read yes >> iostream Compute the Fahrenheit temperature ?? ?? ?? Using OCD
  • 9. Celsius-to-Fahrenheit Formula for converting Celsius to Fahrenheit: fahrenheit = 1.8 × celsius + 32 Converting the temperature thus adds new objects and operations to our problem. 9 Using OCD
  • 10. Information about Objects (Revised) 10 Problem Object Type Kind C++ Type Name program information text constant ? none prompt text constant ? none Celsius temperature real number variable double celsius screen output variable ? cout keyboard input variable ? cin Fahrenheit temperature real number variable double fahrenheit label text constant ? none conversion factor 1.8 real number constant double none conversion factor 32 integer constant int none Using OCD
  • 11. Information about Operations (Revised) 11 Operation Pre- defined? C++ Operator Library Display yes << iostream Read yes >> iostream Compute the Fahrenheit temperature: Multiply two real values (1.8 and celsius) yes * built-in Add a real value (the result above) and an integer (32) yes + built-in Store a real value (the result above) in a variable yes = built-in Using OCD
  • 12. Algorithm D. Organize the objects and operations into a sequence of steps that solves the problem, called an algorithm. 1. Display via cout information about the program to the user. 2. Display via cout a prompt for the Celsius temperature. 3. Read the temperature from cin. 4. Compute the Fahrenheit temperature from the Celsius temperature. 5. Display via cout the Fahrenheit temperature and an informative label. 12 Using OCD
  • 13. Coding Once we have designed an algorithm, the next step is to translate that algorithm into a high level language like C++. This involves writing instructions to — represent the objects, and — perform the operations in C++. 13
  • 14. 14 The Code When learning to program, it is helpful to just start with the algorithm as comments in main() /* John Doe CS 104X Input: Output: -----------------------------------------------*/ #include <iostream> // cin, cout, <<, >> using namespace std; int main() { } /* temperature.cpp converts a Celsius temperature to Fahrenheit. John Doe Lab 1 Jan. 5, 2012 CS 104X Input: A Celsius temperature Output: Corresponding Fahrenheit temperature -----------------------------------------------*/ #include <iostream> // cin, cout, <<, >> using namespace std; int main() { // 1. Display via cout information about the // program to the user. // 2. Display via cout a prompt for the Celsius // temperature. // 3. Read the temperature from cin. // 4. Compute the Fahrenheit temperature from the // Celsius temperature. // 5. Display via cout the Fahrenheit temperature // and an informative label. }
  • 15. cout << "John Doe CS 104X -- Lab 1nn"; cout << "** Convert Celsius temps to Fahrenheit **n"; cout << "Please enter a temperature in Celsius: "; 15 /* temperature.cpp converts a Celsius temperature to Fahrenheit. John Doe Lab 1 Jan. 5, 2012 CS 104X Input: A Celsius temperature Output: Corresponding Fahrenheit temperature -----------------------------------------------*/ #include <iostream> // cin, cout, <<, >> using namespace std; int main() { // 1. Display via cout information about the // program to the user. // 2. Display via cout a prompt for the Celsius // temperature. The Code
  • 16. double celsius; cin >> celsius; double fahrenheit = 1.8 * celsius + 32; cout << celsius << " degrees Celsius is " << fahrenheit << " degrees Fahrenheit.n"; 16 // 3. Read the temperature from cin. // 4. Compute the Fahrenheit temperature from the // Celsius temperature. // 5. Display via cout the Fahrenheit temperature // and an informative label. } The Code It’s wise to echo input data to insure computer read what you intended.
  • 17. 17 Comments /* temperature.cpp converts a Celsius temperature to Fahrenheit. John Doe Lab 1 Jan. 5, 2012 CS 104X Input: A Celsius temperature Output: Corresponding Fahrenheit temperature -----------------------------------------------*/ #include <iostream> // cin, cout, <<, >> using namespace std; int main() { // 1. Display via cout information about the // program to the user. cout << "John Doe CS 104X -- Lab 1nn"; cout << "** Convert Celsius temps to Fahrenheit **n"; // 2. Display via cout a prompt for the Celsius // temperature. cout << "Please enter a temperature in Celsius: "; Always begin a program with opening documentation enclosed in /* and */.
  • 18. /* temperature.cpp converts a Celsius temperature to Fahrenheit. John Doe Lab 1 Jan. 5, 2012 CS 104X Input: A Celsius temperature Output: Corresponding Fahrenheit temperature -----------------------------------------------*/ #include <iostream> // cin, cout, <<, >> using namespace std; int main() { // 1. Display via cout information about the // program to the user. cout << "John Doe CS 104X -- Lab 1nn"; cout << "** Convert Celsius temps to Fahrenheit **n"; // 2. Display via cout a prompt for the Celsius // temperature. cout << "Please enter a temperature in Celsius: "; 18 Libraries This loads the C++ library that we need. Lab & Proj. 1: #include <cmath>
  • 19. 19 /* temperature.cpp converts a Celsius temperature to Fahrenheit. John Doe Lab 1 Jan. 5, 2012 CS 104X Input: A Celsius temperature Output: Corresponding Fahrenheit temperature -----------------------------------------------*/ #include <iostream> // cin, cout, <<, >> using namespace std; int main() { // 1. Display via cout information about the // program to the user. cout << "John Doe CS 104X -- Lab 1nn"; cout << "** Convert Celsius temps to Fahrenheit **n"; // 2. Display via cout a prompt for the Celsius // temperature. cout << "Please enter a temperature in Celsius: "; Each step of the algorithm is implemented by one or more C++ program statements inside main() function. Why no n ?
  • 20. 20 // 3. Read the temperature from cin. double celsius; cin >> celsius; // 4. Compute the Fahrenheit temperature from the // Celsius temperature. double fahrenheit = 1.8 * celsius + 32; // 5. Display via cout the Fahrenheit temperature // and an informative label. cout << celsius << " degrees Celsius is " << fahrenheit << " degrees Fahrenheit.n"; } Each step of the algorithm is implemented by one or more C++ program statements inside main() function. Note spacing, indentation, & alignment to make program “look nice” and easier to read. This will be one criterion used in grading. Always a good idea to echo input data
  • 21. Testing Run your program using sample data (whose correctness is easy to check): John Doe CS 104X -- Lab 1 ** Convert Celsius temps to Fahrenheit ** Please enter the temperature in Celsius: 0 0 degrees Celsius is 32 degrees Fahrenheit. 21 John Doe CS 104X -- Lab 1 ** Convert Celsius temps to Fahrenheit ** Please enter the temperature in Celsius: 100 100 degrees Celsius is 212 degrees Fahrenheit.
  • 22. When you are convinced that the program is correct, run it with the required data values. John Doe CS 104X -- Lab 1 ** Convert Celsius temps to Fahrenheit ** Please enter the temperature in Celsius: -17.78 -17.78 degrees Celsius is -0.004 degrees Fahrenheit. 22
  • 23. 23 For a programming assignment: Lose a few points or may be lucky and the grader doesn’t catch it. For a real-world problem: Much more may be at stake: money, jobs, and even lives. Why Testing is Important: • September,1999: Mars Climate Orbiter • June, 1996: Ariane 5 rocket • March,1991: DSC Communications • February 25, 1991(Gulf War): Patriot missile Testing is never finished; it is only stopped. Testing can only show the presence of errors, not their absence. See Other Course Information (CS 104 page): • Importance of Program Testing — Horror Stories
  • 24. Maintenance 24 • Large % of computer center budgets • Large % of programmer's time • Largest % of software development cost Why? Poor structure, poor documentation, poor style ⇒ less likely to catch bugs before release ⇒ fixing of bugs difficult and time-consuming ⇒ impede implementation of enhancements See Other Course Information (CS 104 page): • Time Spent on Program Maintenance