02VariablesAndExpressions

# 02VariablesAndExpressions - CSE 114 Computer Science I...

This preview shows pages 1–12. Sign up to view the full content.

CSE 114 – Computer Science I Variables & Expressions Niagara Falls, Ontario/New York

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Algorithms & Software Engineering What is an algorithm? a sequential set of steps used to solve a problem
Design, then code Generalized steps of software engineering: 1. Understand and define the problem 2. Determine the required input and output 3. Design an algorithm to solve the problem by computer 4. Implement (code) the solution 5. Debug and test the software 6. Maintain and update the software Which is the most challenging step?

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Designing a Program Example Problem: you have to give someone change what coins do you give that person? Requirements: make a program to do this takes user input displays the change breakdown as output
1. Understand and Define the Problem What are the needs of the program? ask user for input US coins (quarter, dime, nickel, penny) max change: 99¢ display coin output Typically done through Requirements Analysis

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Who performs a Requirements Analysis? IT people What’s involved? interview users What are their expectations? What data do they need to access? Etc. write a requirements analysis report
2. Determine Input and Output Typed input by user: Amount of change requested (an integer between 1 and 99) Printed output: Number of quarters given Number of dimes given Number of nickels given Number of pennies given

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
3. Design an algorithm A. How many quarters? subtract the number of quarters X 25 from the total A. How many dimes? subtract the number of dimes X 10 from remaining total A. How many nickels? subtract the number of nickels X 5 from remaining total A. How many pennies? the remaining total
3. Design an algorithm (continued) Pseudocode: User Input originalAmount numQuarters originalAmount div 25 remainder originalAmount mod 25 numDimes remainder div 10 remainder remainder mod 10 numNickels remainder div 5 remainder remainder mod 5 numPennies remainder Output numQuarters Output numDimes Output numNickels Output numPennies

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
4. Code your solution import java.util.Scanner; public class ChangeMaker { public static void main(String[] args) { int change, rem, qs, ds, ns, ps; System. out.print("Input change amount (1-99): "); Scanner input = new Scanner(System. in); change = input.nextInt(); qs = change / 25; rem = change % 25; ds = rem / 10; rem = rem % 10; ns = rem / 5; rem = rem % 5; ps = rem; System. out.println(qs + " quarters"); System. out.println(ds + " dimes"); System. out.println(ns + " nickels"); System. out.println(ps + " pennies"); } // main } // class ChangeMaker
5. Debugging and Testing What’s the difference? What’s a bug? Note, this step may lead to a feedback loop To step 4 to fix bugs, improve performance, etc.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern