Courses/Computer Science/CPSC 203/CPSC 203 Template/Labs Template/Week 1 - Lab 1: Introduction to Programming: Solving Problems with Heuristics and Algorithms, and Pseudocode

Skills
After completing this module, you should be conformable in demonstrating the following skills:
 * Defining how you may solve a problem (heuristic and algorithm)
 * Link these (above) ideas back to spreadsheets and databases

Introduction to Programming

 * Concepts to be introduced (reviewed):
 * Logic (AND, OR, and NEGATION)

Solving Problems with Algorithms
We solve problems and how to write solutions (algorithms). An algorithm is a step by step procedure for accomplishing some particular problem.

Computers are often used to solve problems, a person with knowledge of the problem must analyze the problem first, develop the instructions for solving the problem, and then have the computer carry out those instructions.

Computers can repeat the solution very quickly and consistently for different situations and data. The major advantage is that it frees people from repetitive and boring tasks.

The following will familiarize you with the fundamental operations (input/output, assignment, repetition, and selection) of programming.

Concepts Linked with Spreadsheets and Databases

 * Defining a solution to a problem.
 * Data representation
 * Data assignment
 * Data storage and retrieval
 * Data manipulation
 * Data organization

Introduction to JES
JES is a tool for teaching introductory programming, and we are going to use it to do some fun stuﬀ with graphics.

FIrst open the JES application it should look something like the figure below:

Jython is an implementation of the python language written in the java programming language. So the real name of the programming language we are using is python.

JES has two main ways of writing code (we call instructions for the computer “source code” or just “code” for short). If you are just trying stuﬀ out, trying to see what things do, you can use the interactive window. The interactive window is the black box at the bottom of the JES window see Figure below:

If you are writing code that you want to keep, then you want to write it in the upper window see Figure below:

The upper window lets you store your code to a ﬁle, or load it from a ﬁle later on. A good rule of thumb is that if you are writing a function you should write it in this upper window.

Otherwise, just use the interactive window.

Variables and Arithmetic
Historically, the ﬁrst program that you should write in any language is what we call the “Hello World” program, a simple program that prints out the friendly message “Hello World!”

Type in the interactive window (the bottom window) see Figure below:

print "Hello World!"

When you hit Enter, JES goes oﬀ to interpret what commands you gave it.

JES interprets your command as an instruction to print5 the message in quotes. In JES a bit of text in quotes is called a “string”. You can do things with strings other than just print them. For example, you can add two strings together (concatenation) using the “+” sign.

Look at this and guess what it does before you run it, then see the Figure below for comparison:

print "Hello" + "World!"

What if we want to put together two strings and save the results for later? Instead of printing the results to the screen, we can just assign the result of mashing those strings together to a variable, like so (see figure below):

x = "Hello " + "World!" print x

JES also supports numeric calculations: print 5 * 10 print 3 / 2 print 3.0 / 2 print 10 + 5 print 32 % 3 print 5 % 2 print 3 - 1 total = 5 + 3 print total

Variables are also useful as place holders.

total = 5 + 3 total = total * 4 print total