CS35: Data Structures and Algorithms

Monday | Wednesday | Friday
Week 01 Lecture Notes

Week 01 Tasks

Monday

Agenda

Who should take this course

Big course questions

Other course Goals

Student responsibilities

What is CS35

Why C++?

Exercise

Python seriesSum vs C++
Wednesday

Announcements

Questions before we begin

Do you have any questions you would like to address today?

Clicker Testing

You should have your clickers by the end of this week.

Sample Questions

Program Attritubutes

C++ code basics

I've added the program demo.cpp to your examples-<user> repo. Feel free to experiment with this code and practice C++. You can get the recent updates at any time by going into your ~/cs35/examples folder and running git pull

cd ~/cs35/examples
git pull
cd week-01
If you get some strange git error, try seeing if any of the messages at Understanding Git Status help. If your case is missing, feel free to post to Piazza
Friday

Please create an account through iClicker, register your remote, and add CS35 Data Structures and Algorithms as a course. (Search for Danner if you are in the MWF lecture)

208, 281, 38D, 481, 582, 819, 876, D9A

Demo

How do I compile/run this demo?

cd ~/cs35/examples
cd week-01
clang++ demo.cpp -o demo
./demo

Demo Topics:

Tracing Functions

Static Arrays in C++

Arrays in C++ can hold multiple items of the same type. For now, we will be declaring static arrays that have a fixed size known at compile time. Later in the course will see how to declare dynamic arrays.

C++ arrays do not have any methods like append, length, or sort. Once declared, you can index an individual item using the bracket notation a[i].

int main() {
  int a[10]; //Creates an int array of capacity 10

  //Proper use of the array
  for (int i=0; i<10; i++) {
    a[i] = 2*i + 1;
  }

  //What happens here?
  for (int i=0; i<=10; i++) {
    cout << i << " " << a[i] << endl;
  }
  return 0;
}