Software Design
Life Cycle
Essential Standard
•
1.04- Understand program design, analysis, andPurpose
•
This lesson will review the Software Design Life Cycle and introduce debugging techniques used in C#. Many ofSoftware Design Life Cycle
•
A set of guidelines for writing software that satisfies the needs of others.Step 1
Analyze requirements
• Programmer meets with the client to talk about the requirements for the software
• Discuss the functionality and the user’s interface. • Discuss the goals of the project and timeline for
completed product or achieving other results.. • Reflect on the cultural needs of your environment
and identify means of helping.
Design and Evaluation
• Programmer creates a conceptual design of the software
• Programmer makes sure that the design meets all the requirements determined by the client
Step
2
Flowcharts
•
As you learned in Programming I- flowcharts are used to produce a visual representation of your program.Start/
End Decisio
Flowchart Assignment
•
Create a flowchart for the Tic-Tac-Toe program used in1.02. Remember there are processes and decisions in this program.
•
You can use:•
Visio- great diagramming tool from Microsoft.•
Word and PowerPoint also have flowcharting shapes built inSample
Implementation and Integration
• Programmer through the use of the IDE
(integrated development environment) codes the application or service.
• The IDE used in this course is Visual Studio.
Step
3
Testing
• Client and programmer test the software to make sure that it operates without any bugs.
• This is a thorough test of the software. Testing will continue once the end user takes delivery of the product.
• Ensures that bugs or defects do not remain in the final product.
Step
4
Debugging
Techniques
Types of Errors
•
Syntax•
Run Time (Exceptions)•
LogicSyntax Error
•
A programming language speaks a “language” of its own using reserved words called keywords.•
A syntax error is an error in the use of a keyword, control character or other language function. The program will not run (compile) with a syntax error. Visual Studio calls syntax errors a “build error.”Left: a common error for new C#
programmers
Syntax Error Examples using
Variables
•
integer x = 7;•
sting name = “John”;•
string age = 14;Syntax Error Examples using
Variables
•
integer x = 7;• Invalid keyword- use int in C#
•
sting name = “John”;• Mispelled string- sting is not a data type
•
string age = 14;• A numerical value cannot be placed in a string without placing it in quotes.
•
int num = “apple”;Error List
•
The Error List is a very useful in Visual Studio. All current syntax errors are listed.•
All errors listed must be corrected before the program can compile. Double click on an error to go to that line incode.
Run Time Errors
•
Run time errors occur when the program encounters an exception it does not know how to handle.•
This will cause the program to crash (stop working).Run Time Error Examples
• Attempting to divide by zero (num1 / num2 where num2 is still set to its default value of 0 or otherwise assigned a value of 0)
• A user enters a string into a textbox meant for a numeric value. The run time error will occur when the program attempts to convert the bad data.
• The program attempts to assign a value to an array index value that does not exist.
Logic Errors
•
A logic error is an error is the thinking or logic of the coder. The program runs normally, but produces results different from the expected output.Logic Error Examples
• Endless loops- A loop whose run condition is always true
Example: while(x < 4) {
some code but forgetting to add x++
} //x will never be greater than 4 and this loop with run forever
• A loop or if statement using an improper comparison
Logic Error Example
•
int howMany = 12;•
for(i=0; i>howMany; i++)Handling Errors
•
Syntax errors are fatal errors. The program will not compile and run until they are corrected. There is nomethod for handling them in a running program because they will not occur.
•
Using features of the code and IDE we can debug for logic errors and prevent run time errors from crashing ourHandling Exceptions
•
Just like in VB we can use Try/Catch to handle exceptions in our program.•
Instead of the exception causing a crash- the try/catch block “catches” the “thrown” exception and runs some code instead.Try Catch Syntax
•
try•
{•
Code to try for possible exceptions•
}•
catch•
{•
Code to run if the try code throws an exceptionExample Using Try/Catch
• try
• {
• intAge = Convert.ToInt32(strTempAge); //or txtAge.Text
• }
• catch
• {
• MessageBox.Show(“Enter a number. The value you entered is invalid. ” + strTempAge)
Handled vs Unhandled
Exception
Left: Try/Catch block was used Above: No try/catch block-
Debugging Logic Errors
•
IDE features such as breakpoints and the Locals window can help debug logic errors in your program. Below is an example of a breakpoint.Line Numbers
•
Line numbers make debugging easier by allowing you to quickly reference what line of code you are working on.Turn on Locals Window
•
When a program is running (Pressed F5 or clicked the Green Triangle) visit the Debug menu and the Windows submenu. The Locals Window is one of the options you can select.Locals Window
Our Breakpoint
•
New options exist when the program is paused at a breakpoint.Options
•
Continue- Run the program as normal from where the program paused•
Step Into- Move the program one line forward into a coding block•
Step Out- Move the program out of the current coding block•
Step Over- skip the next coding blockPractice
•
Practice using breakpoints and the Locals window using one of the programs you wrote in 1.01 or 1.02- especially ones with an if statement or loop.Deployment
• Programmer delivers the product to the client. • This could include installation and/or
customization.
• Client continues testing the software and reports issues to the programmer.
Step
5
Documentation and Maintenance
• Programmer creates… • Help documents
• User manuals • Tutorials
• Programmer provides maintenance for the
software as agreed upon by the client. This could include fixing bugs, adding new features, or
implementing on new or updated platforms.
Step 6
Comments in C#
•
Just like in Visual Basic it is extremely important to comment your code.•
This is especially true in team environments where more than one coder will be working on a project.•
C# provides 2 ways to comment:• // can be used for a single line comment or in line after a coding statement
Comment Examples
age = Convert.ToInt32(tempAge); //convert the string data to integer Inline comment after a coding statement
// This program will check an age. This is a single line comment
/* This is a multi-line comment * J. Crompton
* Computer Programming II * August 4, 2015