Week 10 Lab
Q&A on Material
- Arrays: accessing, setting, declaration
- Fixed-size arrays (limitations)
- Character Arrays
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;
}
Coding Exercises
cpp/cs102/practice10/netflixTimes
cpp/arrays/sumpairs
Character Array Exercises
cpp/cs102/practice11/arraysTF
cpp/cs102/practice11/reversal
Challenge exercise (2D arrays)
cpp/cs102/practice10/saleGrid
Open-ended Help
Any students with questions may stay after to get help. Anyone else may leave at this stage.