Back to Challenge Set 12

Code Challenge: Seat Swap

Difficulty  

divider

The Brief

What they asked for
Two kids in my row need to switch seats. Let me type the two
seat numbers and swap them. At the end, show me the old row
and the new row together, so I can write both down and put
everyone back tomorrow if it goes badly.

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


Notes

  • Start from the same row as Seat Finder: Avery, Blake, Casey, Dakota, Emery, in seat order.
  • Both seat numbers are typed the way people count, from 1.
  • The old row is printed at the end, after the swap. So by the time you print it, the program has to still have it somewhere. Activity 1.23's dealer is the warning: make sure your old row really is a different array.
  • Swapping someone with themselves — the same seat twice — should change nothing.

Sample Output

Sample Output
First seat to swap? (1-5) 2
Second seat to swap? (1-5) 4
Before: Avery, Blake, Casey, Dakota, Emery
After: Avery, Dakota, Casey, Blake, Emery

Verified in a real run — seats 2 and 4 swapped, and the old row still shows Blake in seat 2.


Submit

Your requirements list and your program file, named cc-seat-swap.

Commence Challenge