Back to Challenge Set 18

Code Challenge: Roll Call

Difficulty  

divider

The Brief

What they asked for
I read out the register every morning and I keep losing my
place. I have the class list, and I have the names of the
kids who answered. Just tell me who is missing.

Write your requirements list before you write any code. Input, calculate, output, and anything you had to decide for yourself.


Notes

  • The class list and the answered list are two separate arrays. They are not the same length and they are not in the same order.
  • For each name on the register you have to look through the whole other array. That is a linear search, and here it is the only option.
  • Say how many are absent at the end. Do not make the teacher count.

Where to Start

Only one-star challenges have this section. If you already know how to begin, skip it — and when you move up to two stars, working out the order yourself is part of the job.

  1. Write a method that takes one name and returns true if it is in the answered array — Activity 2.9's search, returning a bool instead of an index.
  2. Loop over the register and call it for each name, printing here or ABSENT.
  3. Count the absent ones as you go, and print the count after the loop.
  4. Test a day when everyone answered and a day when nobody did.

Sample Output

Sample Output
Ines - here
Ravi - here
Nadia - ABSENT
Owen - ABSENT
Priya - here
2 absent out of 5

Nadia and Owen are on the register but not in the answered array.


Submit

Your requirements list and your program file, named cc-roll-call.

Commence Challenge