Programming Fundamentals
Tutorial Overview:
- Part 1: Calculating Values in Programs
- Topics Covered: Arithmetic, Logic, Comparitive operators
- Part 2: Weird Data Types and Arithmetic
- Topics Covered: Complex Arithmetic expressions, order of operations.
- Part 3: Diagramming
- Topics Covered: Flow charts, If statements
- Part 4: Practical Programming Exercise
- Topics Covered: If statements, scanf, procedures.
Part 1: Calculating Values in Programs (5 mins)
Objectives: Understand the different types of operators, and how to use them.
In this short section, we will review what tools we have for doing mathematics in our programs. This section will be completed quickly, to make sure we have time for the rest of the tutorial.
Part 2: Weird Data Types and Arithmetic (10 mins)
In this short section, we will review how you can store values in programs.
These are short arithmetic expressions we will use during this tutorial:
(7 / 2)
(3.0 / 2) + 1
'a' + 5
'F' - 'A' + 'a'
Part 3: Diagramming (20 mins)
Objectives: Understand Flowcharts, and how to use them to break down a problem.
In this section, we'll work on diagramming a small program.
Flow Charts:
We'll start by discussing the following flowchart:
Leap Years:
The three rules of a leap year may help with this activity:
- Years divisible by 4 are leap years. (e.g. 1904 was a leap year)
- Except, years divisible by 100 are not leap years. (e.g 1900 was NOT a leap year)
- Except, years divisible by 400 are always leap years. (e.g. 2000 was a leap year)
Part 4: Practical Programming Exercise (rest of tutorial)
Objectives: Utilising Flowcharts and pseudocode to plan a program.
In this activity, you'll be writing the following program.
It should:
- Scan in two integers (
a
andb
).- If the first integer is less than the second, print out a short error message using a procedure.
- If the second integer is 0, print out a different short error message.
- If the first integer is larger than the second, prints
a / b
and(a * 1.0) / (b * 1.0)
.
The following (unrelated) example of "pseudocode" might be useful for this activity:
// C style pseudocode example.
// Prints out "Hurrah!" if the entered number is 5
int n = 0
print "Enter a number"
scan a number into n
if (n == 5) {
print "Hurrah!"
}