CSCI 102 - Fall 2023 Fundamentals of Computation

Week 9 Lab

Q&A on Material

Sign in to lab!

Exercises

Walk through these exercises and complete them as a group (if time allows):

Tracing Exercise

Trace through the following code and determine what will be printed.

#include <iostream>
using namespace std;

int main()
{
  int data[8];

  int y = 1;
  data[0] = y;
  cout << data[0] << " ";
  for(int i=1; i < 8; i++){
    y += 2;
    data[i] = data[i-1] + y;
    cout << data[i] << " ";
  }
  cout << endl;

  int s = 0;
  for(int i=0; i < 5; i++){
    s += (data[i] + data[i+1])/2;
  }
  cout << s << endl;
  return 0;
}

Solution

Coding Exercises

cpp/cs102/practice10/netflixTimes
cpp/arrays/sumpairs

Open-ended Help

Any students with questions may stay after to get help. Anyone else may leave at this stage.