Monday
Agenda
- Sign in - Please include your preferred name
- Introduction, Syllabus
- Course Goals
Who should take this course
- Took CS21 or placement exam
- Potential CS major/minors
- Pre-req for upper level CS
- Interested in solving complex problems with algorithms and data structures
Big course questions
- Given a problem
- how do we solve it computationally
- what method is best
- is our method correct
- How do we compare methods?
- What is the best way to organize and store data
- may depend on application
- Abstract Data Type (ADT):
- describes operations to support on data but not how to implement
- What are best ways to implement ADTs?
Other course Goals
- Understand principles of OOP - expand on CS21
- Implement OOP in C++
- C++ is huge, evolving. We’ll pick a subset suitable for this course
- Learn common and powerful DS and common Operations
- Learn how to apply DS & A to solve problems of moderate complexity
Student responsibilities
- Attend and participate (labs and lecture)
- start labs early
- seek help early and Often
- maintain integrity
What is CS35
- CS35: Data Structures and Algorithms
- Algorithm: A step-by-step description of how to solve a problem
- sort a list of numbers
- find cheapest flight from PHL to YVR
- Data Structure: Specification for storage, organization of data
- examples from cs21?
- Missing
- give directions
- rank restaurants
- CS35 as core CS
- Often several ways to do things
- Common patterns
- Faster ways save money, do more
- All of CS builds off DS & A
- Algorithms are program building blocks
- All programs use, need to structure data
Why C++?
- Good to know multiple languages
- each has benefits, drawbacks, common applications
- expand problem solving skils
- learn which programming elements are shared/unique
- Python may not be very efficient for large tasks
- good for beginners
- can do simple things fast
- C++ allows more low level accesses and more power/control to programmer regarding how to:
- store data
- manage memory
- pass information/data
- downside: more responsibility
Exercise
Python seriesSum vs C++
Wednesday
Announcements
- WICS
- Ninja sessions Thursday and Saturday
- Read C++ for Python programmers PDF if applicable
- Lab 00 due Sunday night
- Many lab section, lecture section requests will go unmatched.
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
- Translator
- Python - Interpreted
- C++ - Compiled
- Types
- Python - Dynamic typing
- C++ - Static Typing
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:
- Types
- Arithmetic ops
- Terminal I/O: cout, cin
- Branching and Decision structures
- Loops
- Functions
Tracing Functions
- Call stack
- Argument Passing
- Scope
- Return
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;
}