Programming Fundamentals

Vocabulary

Algorithm: An algorithm (pronounced AL-go-rith-um) is a procedure or formula for solving a problem. The word derives from the name of the mathematician, Mohammed ibn-Musa al-Khwarizmi, who was part of the royal court in Baghdad and who lived from about 780 to 850. Al-Khwarizmi's work is the likely source for the word algebra as well. http://computer.howstuffworks.com/ and specifically at: http://computer.howstuffworks.com/framed.htm?parent=question717.htm&url=http://searchvb.techtarget.com/sDefinition/0,,sid8_gci211545,00.html

A computer program can be viewed as an elaborate algorithm. In mathematics and computer science, an algorithm usually means a small procedure that solves a recurrent problem.

Array -In computer science, an array[1] is a data structure consisting of a group of elements that are accessed by indexing. In most programming languages each element has the same data type and the array occupies a contiguous area of storage. http://en.wikipedia.org/wiki/Array

Class- a Class is a kind of super data structure containing both variables and methods. It defines the characteristics of an object, including the object's characteristics / state (its attributes, fields or properties) and the objects's behaviors (the things it can do, or its methods, functions, or subroutines). One might say that a class is a blueprint that describes the nature of the object. It is said to contain the DNA of an object. The Class determines how the instance of the object will look and behave once the class is instantiated or created into an object.

Compiler- In Computer Science compile means to translate (a program) into machine language.

Machine Language: Sometimes referred to as machine code or object code, machine language is a collection of binary digits or bits that the computer reads and interprets. Machine language is the only language a computer is capable of understanding.

Runtime Error is an error that occurs during the execution of a program. In contrast, compile-time errors occur while a program is being compiled.

Data Structures: In computer science, a data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently. Data structures are generally based on the ability of a computer to fetch and store data at any place in its memory, specified by an address — a bit string that can be itself stored in memory and manipulated by the program. http://en.wikipedia.org/wiki/Data_structure Examples of data structures are arrays.

Iterate - repetition, repeating. In computer science a single execution of a set of instructions that are to be repeated; "the solution took hundreds of iterations" as in a loop. http://www.thefreedictionary.com/iteration

Inheritance - In Object Oriented Programming it is the method in which classes inherit attributes and behaviors from their parent classes, and can introduce their own. "Subclasses" are more specialized versions of a class, which inherit attributes and behaviors from their parent classes, and can introduce their own.

"For example, the class Dog might have sub-classes called Collie, Chihuahua, and GoldenRetriever. In this case, Lassie would be an instance of the Collie subclass. Suppose the Dog class defines a method called bark() and a property called furColor. Each of its sub-classes (Collie, Chihuahua, and GoldenRetriever) will inherit these members, meaning that the programmer only needs to write the code for them once.
Each subclass can alter its inherited traits. For example, the Collie class might specify that the default furColor for a collie is brown-and-white. The Chihuahua subclass might specify that the bark() method produces a high pitch by default. Subclasses can also add new members. The Chihuahua subclass could add a method called tremble(). So an individual chihuahua instance would use a high-pitched bark() from the Chihuahua subclass, which in turn inherited the usual bark() from Dog. The chihuahua object would also have the tremble() method, but Lassie would not, because she is a Collie, not a Chihuahua. In fact, inheritance is an "a... is a" relationship between classes, while instantiation is an "is a" relationship between an object and a class: a Collie is a Dog ("a... is a"), but Lassie is a Collie ("is a"). Thus, the object named Lassie has the methods from both classes Collie and Dog."
quoted from - http://en.wikipedia.org/wiki/Object_oriented

Example of Inheritance http://java.sun.com/docs/books/tutorial/java/concepts/inheritance.html

Bicycle->The Mountain, Road, Tandam Bikes all have a is-a relationship to their parent class Bicylce.

Question: Would a Car Door inherit from a Car Object? Does a Car Door have an is-a relationship with a Car?

 

Excerpts from REALbasic By Matt Neuburg (for educational purposes only)

Variables and Constants

In REALBasic, as in many computer languages, the association of a name with a value is performed in code by means of the = operator. For an assignment the name goes on the left side of the = and the value goes on the right side.

lvalue = rvalue

for example:

Dim StudentName as String

StudentName = "Jennifer"

Datatypes and Declarations

Datatypes and Declaration of Variables

In REALbasic, every value is of some one type, called its datatype. For instance, a value might be a whole number - an integer. Or, it might be text - a string. Before a name can be associated with a value by means of assignment, there has to be a declaration stating the datatype for any value that will be assigned to that name. So, before making any of the assignments in the preceding examples, we would have to declare the names myAge, thisYear, and myBirthYear are all destined to receive integer values.

It is an error to use an undeclared variable name, and it is an error to assign to a variable a value whose datatype is not the datatype for which the variable was declared. Therefore, you must remember to declare every variable before you use it, and you mustn't violate a variable's datatype once you've declared it. In a nutshell: you must say what you're planning to do, and you can do only what you said.

 

Methods, Subroutines, Procedure and Functions

Methods, subroutines, procedures and functions all serve the same purpose. They contain a block of code that can be called (told to execute) by some other piece of code, or by REALbasic itself.

For example when the following code executes, a call to val() is made. Val() contains a chunk of code that performs the conversion of a String to an Integer. The following line calls val twice. The first call translates an editfield1.text to a number and the second call translates editfield2.text to a number.

Dim num as Integer

num = val(editfield1.text) + val(editfield2.text)

Assignments

variable = expression

How to Declare Variable

Dim myNumber as Integer

Dim myString as String

Dim myFlag as Boolean

Data Types in Basic

Arrays

Type of Loops

  • Dim i as integer
  • For i = 1 to (a number or use ubound for arrays)
    • do something
  • next
  • While condition
    • do something
  • wend
  • do until condition
    • something
  • loop

Assignment

Exercise 1

You have the formula for an anti-virus vaccine that will save the people of planet Alpha-Neuron. You must send a message informing the President of Alpha-Neuron of this vaccine. The message must be SECRET and delivered by hand due to fear of evil doers. The secret code can contain alpha characters, whole numbers, and blanks. The rules state there is a limit of 30 characters and alpha-characters are to be in lower case. For example, a sample code would be to swap every other alpha-numeric character with its ascii decimal representation. http://www.asciitable.com/ i32104h97v101e20


Exercise 2

To answer these questions you may use the definitions on this page, your notes, search the web, REALBasic language reference or any books you find around the classroom. Although, don't forget to include your sources. The one caveat is you must rewrite the definitions in your own words. There is no credit for answers without sources, or if your answers are not written in your own words. Do not forget to try the extra credit.

Caveat usually a warning or a condition one should be aware of as in the Latin phrase caveat emptor which means buyer beware!!

Create this document in Word and save it as YourNameVoc. It should be placed in a new directory on the H Drive called Voc

The file should look like H:/REALbasic/Voc/joeStudentVoc.doc

  1. What are variables? What are they used for? Give an example.
  2. What are the data types that we most often use in REALBasic?
  3. What is the keyword that is used to declare a variable in REALbasic?
  4. In REALBasic write out three declaration statements for each kind of the following variables,
    1. a variable to display a string which will be ultimately used in an editfield,
    2. a variable whose value will be either true or false,
    3. a variable that will be used in a mathematical calculation.
  5. What is an array?
  6. In Tic Tac Toe why will use an array?
  7. What is a loop?
  8. Explain why we used inheritance to create a GameSquare.
  9. In Tic Tac Toe why will we use a loop?
  10. What is the core algorithm that needs to be solved for our Tic Tac Toe program? Note I am not asking you to solve the algorithm, but to describe the problem. Hint: we had talked about a generalized solution during summation.

Extra Credit

Describe a solution how to determine a winner in Tic Tac Toe.

Exercise 3

This is NOT a group project.


In your notebooks write a paragraph stating the theme of your final project's game. In addition, include whether it will be implemented in REALbasic or Game Maker. Explain what new challenges your proposed final project presents. For example, new coding skills, using new Events, new Drawing techniques, using Inheritance, etc.. How does it give you an opportunity to expand on your growing skill set? Note, this is just your first iteration (definition) in the creation of your design document.