Karel review and a more complex example

Abstractions in Karel's world:

Example: moveTillClear()

Example: clearAllTowers()

use another abstraction, clearOneTower to implement this function. Can use either top-down or bottom-up design approach.

We will use C++ examples, why C++?

Introduction to C++

C++ programs/files

First C++ program

/*
 * hello.cpp
 * This program prints a welcome message
 * to the user.
 */
#include <iostream>
using namespace std;
int main() {
  cout << "Hello, world!" >> endl;
  return 0;
}

Code variables

Example usage

Programming with variables

string name = "Virat";
cout << "happy birthday to " << name << endl;
cout << "wish you a long life " << name << endl;

A modern computer has gigabytes of memory, i.e., it has space for billions of these boxes (or variables).

Variable declarations

type name;
Some example types:

Variable assignments

name = value;
Would be a compiler error if the variable name has not been declared already. Would also be an error if the variable name is declared twice (in the same "scope").

Variable declaration and assignment

Can do both declaration and assignment together.
type name = value;