CS151 -- Administration
 
 

Midterm -- Well... handed back today.


 
 
 

CS151 -- Shawn Stoffer



 
 
 
 
 
 

CS151 -- Administration
 
 
 

Project 3 due, Yesterday... July 8.

Project 1 - handed back.


 
 
 

CS151 -- Shawn Stoffer



 
 
 
 
 

CS151 -- Administration
 
 
 

Project 4, due July 17 (Wednesday)
CS151 -- Shawn Stoffer

 
 
 
 
 
 
CS151 -- Administration
Project 5, due July 24 (Teusday). Don't sweat it, there will be lots of in class examples... Just pay attention.
 
 

CS151 -- Shawn Stoffer


Computers

What computers do for you

Algorithms
 


CS151 -- Shawn Stoffer



 

Input and Output

Thinking about what it is

char cin.get(void);  -- a primitive!

>> uses cin.get()
istream& operator>>(istream& in,
                                  string out);

int getline(istream& in, string out);


CS151 -- Shawn Stoffer



 
 
 

Input and Output

Thinking about what it is

char cin.get(void);

-- a primitive!

-- REMOVE one character from the input stream, and return it.


CS151 -- Shawn Stoffer



 
 

Input and Output

Thinking about what it is

>> uses cin.get()
istream& operator>>(istream& in,
                    string out)
{
  while (in.available() == true) {
      char ch = in.get();
      if (ch != '\n' && ch != ' ' &&
          ch != '\t')
      {
         out += ch;
      } else {
         in.putback(ch);
         return in;
      }
  }
  return in;
}


CS151 -- Shawn Stoffer



 
 
 

Input and Output

Thinking about what it is

int getline(istream& in, string out) {
  while (in.available() == true) {
      char ch = in.get();
      if (ch != '\n')
      {
         out += ch;
      } else {
         return in;
      }
  }
  return in;
}


CS151 -- Shawn Stoffer



 
 
 
 
 

Input and Output

So, what?
 
CS151 -- Shawn Stoffer


 
 
 
 
 
 
 
 
 
 
 

Arrays

char ch[10];
 
CS151 -- Shawn Stoffer


 
 

Arrays

char ch[10];
ch[3] = 'a';
CS151 -- Shawn Stoffer


 
 
 
 
 
 
 
 
 
 

Arrays

char ch[10];
ch[3] = 'a';
CS151 -- Shawn Stoffer


 
 
 
 

Looping

CS151 -- Shawn Stoffer


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Searching

Sequential Search (naive)

Binary Search (really smart...but has constraints)

CS151 -- Shawn Stoffer


 
 
 
 
 
 
 
 
 
 
 

Searching

Sequential Search (naive)
CS151 -- Shawn Stoffer


 
 
 
 

Searching

Sequential Search (naive)

element seqSearch(element array[],
                  int size,
                  element find)
{
  for (int i = 0; i < size; i++) {
    if (array[i] == find) {

      return find;
    }
  }
}

CS151 -- Shawn Stoffer


 
 
 
 
 
 
 
 
 
 
 

Searching

Binary Search
CS151 -- Shawn Stoffer


 
 
 
 
 

Searching

Binary Search
CS151 -- Shawn Stoffer


 
 

Searching

Binary Search
CS151 -- Shawn Stoffer


 
 
 
 
 
 
 
 
 

Searching

Binary Search
CS151 -- Shawn Stoffer


 
 

Searching

Binary Search element search(element array[], int size,
               element find)

{
   int high = size, low = 0;
   int middle = (high+low) / 2;

   while (high > low) {
     if (array[middle] < find) {
       low = middle;
     } else if (array[middle] > find) {
       high = middle;
     } else {
       return element;
     }
     middle = (high+low)/2;
   }
   throw notFound;
}

CS151 -- Shawn Stoffer