New User Special Price Expires in

Let's log you in.

Sign in with Facebook


Don't have a StudySoup account? Create one here!


Create a StudySoup account

Be part of our community, it's free to join!

Sign up with Facebook


Create your account
By creating an account you agree to StudySoup's terms and conditions and privacy policy

Already have a StudySoup account? Login here


by: clu2 Notetaker
clu2 Notetaker

Preview These Notes for FREE

Get a free preview of these Notes, just enter your email below.

Unlock Preview
Unlock Preview

Preview these materials now for free

Why put in your email? Get access to more of this material and other relevant free materials for your school

View Preview

About this Document

First week notes
Programming Abstractions
Keith Schwartz
Class Notes
Computer Science CS106B Stanford
25 ?




Popular in Programming Abstractions

Popular in ComputerScienence

This 7 page Class Notes was uploaded by clu2 Notetaker on Thursday January 14, 2016. The Class Notes belongs to CS106A at Stanford University taught by Keith Schwartz in Winter 2015. Since its upload, it has received 20 views. For similar materials see Programming Abstractions in ComputerScienence at Stanford University.


Reviews for CS106B


Report this Material


What is Karma?


Karma is the currency of StudySoup.

You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 01/14/16
1/6/16    Assignment 1:   Extra office hours with Megan @ Gate 104, 10am­11am    Life simulation:   4 basic rules    Functions    Hello World Program:   ­Top level comments  ­Include libraries (#include and using)   ­Main program (int main())    Most primitives are same   ● int ­> int  ● double ­> double  ● float ­> float  ● boolean ­> bool    Most operators and control flow is the same     Differences:   ● Strings are different  ● Need to #include <string> … string s = “hello”;  ● A string is a possibly empty sequence of characters.   ● Strings in C++ are conceptually similar to Java strings     String operators:   ­You can concatenate strings using + or +=  ­Unlike Java, you can compare strings using relational operators    string s2 = “Megan”;   if (s2 >s1 && s2 != “Keith”){  …  }    ­Unlike Java, strings are mutable  s1.append(“ Piech”)  s1.erase(3, 2)      Two kinds of strings:   ­C++ strings  ­C strings (any string literal such as “hi there” is a C string  ­Need to assign to string type before     Bug:   ● string s = “hi”+”there”; (Does not compile)    Fixes:  ● string s = string(“hi”) + “there”;   ● string s = “hi”;   ● s+=”there”;    Bug:   ● int n = (int) “42”;  ● n is now memory address of C string    Fix:   ● int n = stringToInteger(“42”);    Concatenation bugs:   ● string s = “hi” + ‘?’;   string s = “hi” + 41 (Produces garbage)  ● string s = “hi”;   s+=41; (Adds ASCII value of 41)    Fix:   ● s+= integerToString(“42”)    Eliza program:     while(true){ // prompt indefinitely  string prompt = getLine(“> “);  int length = prompt.length();    if (prompt == “hello”) {  cout << “hi” << endl;  } else if (prompt[length­1] == ‘?’) {  cout << “why do you ask” + prompt << endl;   } else {  cout << “are you sure” << endl;  }  }    Points  ­Basics of C++ and Java are very similar   ­Prototype functions    Note: c string + c++ string works    Part 2: Functions (the toaster)   ­Similar declaration as Java  ­But you need to add function prototype at very beginning (underneath the include libraries and  above main)     int absolute Value(int n);  int main() {  cout << “...” << absoluteValue(5)<< endl;  }    int absoluteValue( int n){  if(n>0) {  return ­n;  }  return n;  }    Example: Neuron Function    double sigmoid(double x);    double output = neuron(x1, x2){  double inputSum = 0;  inputSum+= x1*WEIGHT1  inputSum+=x2*WEIGHT2;  return sigmoid(inputSum);  }    double sigmoid(double x){  return 1/(1+xp(­x));  }    Pass by Value  ­Values copied when variables passed as parameters    Example:  void grow(int age){  age = age+1;  }    int main(){  int age = 20;  grow(age);  return 0;  }    We can actually change the variable by passing by reference  ● void grow(int & age)       1/4/2016    Welcome to CS106B!     Pair programming: must be in same section  Sign up on Piazza    Breakdown of Grades:     ● 50% is assignments  ● 15% 1st midterm   ● 25% class final  ● 10% section participation    Same Grading scale as CS106A     Office hours: TBD         1/8/2016    Vectors and Grids    Announcements:   ­YEAH hours: Monday 5­6pm @ Bishop Auditorium  ­Megan special OH on Monday 10­11am    3 Door Game    Welcome Message in a file   void setUpGame(){  ifstream filestream;  openFile(filestream, “welcome.txt”);  // get first line  string numLinesStr;  getline(filStream, numLinesStr);  int numLines = stringToInteger(numLinesStr);  }    1. Vector:   ● ArrayList<type>  ● List of elements that can grow and shrink  ● Constructor creates empty list  ● Indexed by 0  ● Bounds checks  ● Knows size    Declaration: Vector<int> vec; or Vector<int> vec();    Vector methods ­ see slides    2. Grid<type>   ● Fixed size of rows and columns, like matrix  ● Advanced 2d array  ● Board games  ● Default constructor creates sie 0, 0  ● Bounds check  ● Does not support ragged right  ● Knows size    Declaration: Grid <string> grid; or Grid<string> grid(3, 4);    Collections:  ­Defined as Classes  ­Templatized: mechanism for collecting different variable types  ­Deep copy assignment, passed by reference    Example: Velociraptor problem (queens problem) ­ see handouts  


Buy Material

Are you sure you want to buy this material for

25 Karma

Buy Material

BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.


You're already Subscribed!

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

Why people love StudySoup

Steve Martinelli UC Los Angeles

"There's no way I would have passed my Organic Chemistry class this semester without the notes and study guides I got from StudySoup."

Allison Fischer University of Alabama

"I signed up to be an Elite Notetaker with 2 of my sorority sisters this semester. We just posted our notes weekly and were each making over $600 per month. I LOVE StudySoup!"

Jim McGreen Ohio University

"Knowing I can count on the Elite Notetaker in my class allows me to focus on what the professor is saying instead of just scribbling notes the whole time and falling behind."


"Their 'Elite Notetakers' are making over $1,200/month in sales by creating high quality content that helps their classmates in a time of need."

Become an Elite Notetaker and start selling your notes online!

Refund Policy


All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email


StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here:

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.