Abstract programming concepts, including: the four basic control structures, plus interaction; Combining them to make an algorithm; Variables; Two basic data types
Determining if a year is a leap year
1. Ask the person for a four-digit year
2. Write the Year in your notebook
3. Decide whether or not YearIsLeapYear
4. If YearIsLeapYear, say "Year is a leap year"
5. Otherwise, say "Year is not a leap year"
Leap year computer algorithm
1. Prompt user for four-digit year
2. Input Year
3. Compute YearIsLeapYear
4. If YearIsLeapYear is true, write "Year is a leap year"
5. Otherwise, write "Year is not a leap year"
Variable declaration
Tells the computer what the variable will be called and what type of data the variable will store
Data types
int (integers)
string (sequences of characters)
Code editors
Lightweight and fast
Free or very affordable
Easy to learn
Can be extended to have IDE-like features with plug-ins
IDEs
Ready to use "out of the box"
Works particularly well for large projects
Popular free IDEs
Visual Studio Code
MS Visual Studio Community
Code Blocks
Repl.it
Programming errors
Syntax Errors
Runtime Errors
Logic Errors
Syntax Errors
Typos in your code that the compiler detects, preventing the code from compiling
Runtime Errors
Bugs that aren't detected by the compiler and cause the program to terminate while running
Logic Errors
Flaws in the logic underlying the algorithm, resulting in unexpected results
Programming style and documentation
Appropriate Comments
Proper Indentation and Spacing Lines
Block Styles
Programming life cycle
1. Problem-solving
2. Implementation
3. Maintenance
Problem-solving phase
1. Analyze the problem and specify what the solution must do
2. Develop a general solution (algorithm) to solve the problem
3. Verify that your solution really solves the problem
Input data
Data from outside the program
Formula constants
Values used in the program
Computed values
Values produced by the program
Output results
Results written to a file or screen by the program
Implementation phase: Write code
1. Translating your algorithm into a programming language (coding)
2. Using code, documentation, and a compiler to translate the program into machine language
Implementation phase: Test
1. Running the program to see if it produces correct results
2. Debugging to find and fix errors
Maintenance phase
1. Using and modifying the program to meet changing requirements or correct errors
2. Rewriting code if necessary
The programming life cycle has three main phases: problem-solving, implementation, and maintenance
Algorithm to determine an employee's weekly wages
1. Get the employee's hourly payRate
2. Get the hours worked this week
3. Calculate regular wages
4. Calculate overtime wages (if any)
5. Add regular wages to overtime wages (if any) to determine total wages for the week
Formula constants
Normal work hours (40.0)
Overtime pay rate factor (1.5)
Input data
Hourly payRate
Hours worked
Computed values
Overtime hours worked
Wages
Problem-solving techniques include asking questions, looking for familiar things, solving by analogy, and using means-ends analysis