HW20: Where Am I?

Problem statement

Implement a smart contract for location tracking.

Example scenario

BME wants a tracking system for the location of its professors so that each of them can be found easily when they are needed. For this, the administration creates an instance of this contract and registers all the professors. The administration also creates a list of all the rooms they want to keep track of together with the corresponding identifiers, which they publish on their website.

There is a large meeting in room IE007 (let's say the id of this room is 192). Each professor entering the room registers this event on the contract. 10 professors attend the meeting. When someone queries the number of participant in room IE007, they get 10. When someone queries the current location of Professor Bob (who attends the meeting), they will get 192 (i.e. room IE007).

Note that the registering process could be automated. E.g. to open a classroom, the professor has to scan the QR code of their Ethereum address. After this, the scanner at the door could automatically register the new location for the professor. For now, however, let's assume that participants register this for themselves.

Contract interface

Contract skeleton

pragma solidity ^0.4.21;

contract WhereAmI {

    // <contract_variables>

    // </contract_variables>

    function WhereAmI() public {
        // TODO
    }

    function registerPerson(address person) public {
        // TODO
    }

    function removePerson(address person) public {
        // TODO
    }

    function changeLocation(uint16 newLocation) public {
        // TODO
    }

    function locationOf(address person) public view returns (uint16) {
        // TODO
    }

    function numPeopleAtLocation(uint16 id) public view returns (uint16) {
        // TODO
    }

}