lab09 : Putting What You Learned into Practice

num ready? description assigned due
lab09 true Putting What You Learned into Practice Wed 06/05 08:00AM Thu 06/13 11:00PM

Goals for this lab

By the time you have completed this lab, you should be able to

This lab has no starter code. The goal is for you to use what you have learned throughout the course to design and implement a solution to a given problem. Feel free to discuss your approaches with the tutors and the instructor.

The exercises below are based on the programming projects listed in the book. For this lab, choose one of the programming projects below and implement it using the test-driven approach that we have used this quarter (e.g., create a header and the cpp file together with the test program that uses asserts; include a Makefile that runs all tests).

Step 0: Find your partner

Step 1: Create a new repo, add your partner as collaborator on GitHub and Gradescope

Step 2a: Clone the repo in the pilot’s account and update the README

     |   Assignment:  ASSIGNMENT NUMBER AND TITLE
     |
     |       Author:  STUDENT1 and STUDENT2 NAME(s) HERE
     |
     |        Class:  NAME AND QUARTER OF THE CLASS FOR WHICH THIS CODE WAS WRITTEN
     |                      
     |      Program:  THE NAME OF THE PROGRAM THAT YOU CHOSE TO IMPLEMENT
     |
     |   To Compile:  EXPLAIN HOW TO COMPILE THIS PROGRAM
     |

Step 2b: Commit the repo

Make sure that before the lab is over, you commit your README with the updated information.

git add .
git commit -m "Initial version of lab09 README"
git push origin master

Step 3: Select a project and create the necessary files




It’s time to select and implement your project!


Project 1: Race results

In many races competitors wear an RFID tag on their shoe or bib. When the racer crosses a sensor a computer logs the racer’s number along with the current time. Sensors can be placed along the course to accurately calculate the racer’s finish time or pace and also to verify that the racer crossed key checkpoints. Consider such a system in use for a half marathon running race, which is 13.1 miles. In this problem there are only three sensors: at the start, at the 7 mile point, and at the finish line.

Below is sample data for three racers.

All timestamps are in the 24 hour time format (HH MM SS).

08 00 00
0,100,08 00 00
0,132,08 00 03
0,182,08 00 15
1,100,08 50 46
1,182,08 51 15
1,132,08 51 18
2,132,09 34 16
2,100,09 35 10
2,182,09 45 15

Create a text file with a sample race log called "race.log". Write a program that reads the log data from a file into array(s) or vector(s). The program should then call functions, which given a racer’s number output the racer’s overall finish place, race split times in minutes/mile for each split (i.e. the time between sensors), and the overall race time and overall race pace.


Project 2: Encryption

You and your friends decided to use a secret code to communicate with each other. You implemented a basic encryption method based on the ASCII code. (Appendix 3 in the book shows the ASCII character set.) Individual characters in a string are encoded using this system. For example, the letter “A” is encoded using the number 65 and “B” is encoded using the number 66.

Your secret code takes each letter of the message and encrypts it as follows:

if (OriginalChar + Key > 126) then
    EncryptedChar = 32 + ((OriginalChar + Key)  127)
else
    EncryptedChar = (OriginalChar + Key)

For example, if the Key = 10 then the message “Hey” would be encrypted as:

Encrypted H = (72 + 10) = 82 = R in ASCII
Encrypted e = (101 + 10) = 111 = o in ASCII
Encrypted y = 32 + ((121 + 10) – 127) = 36 = $ in ASCII

Consequently, “Hey” would be transmitted as “Ro$.”

Write a program that decrypts the encrypted message. You might want to create a function, which will take an encoded string and a key as an input and return the decoded string. You might want a separate function that checks whether the decoded string is valid.

The ASCII codes for the unencrypted message are limited to the visible ASCII characters. For simplicity, assume that the key is a number between 1 and 100. Your program should try to decode the message using all possible keys between 1 and 100. When you try the valid key, the message will make sense. For all other keys, the message will appear as gibberish.

In order to not have to look at the output of the 100 attempts, to assess whether the decoded message makes sense, you can check that the resulting output string contains a “keyword”: i.e., a word that you include in your message, specifically for this check (this is, for instance, how Alan Turing was able to crack the Enigma code). For example, if your keyword is “Hey”, then you know whether you encoded a given string “Ro$” correctly, if “Hey” appears in the resulting string.


Project 3: Time conversion

Write a function that takes a string parameter containing the time. This function should convert the time into a four-digit military time based on a 24-hour clock. For example,”1:10 AM” would output “0110 hours”, “11:30 PM” would output “2330 hours”, and “12:15 AM” would output “0015 hours”. Adding a period inside AM or PM (e.g., “9 A.M.”) should also be accepted. The function should return the resulting time as a string. Be sure to not include any whitespace in the resulting string.

Update: Since the instructions specify that there shouldn’t be any whitespace in the resulting string **do not include ` hours** in the resulting string. Also, "9:30 A.M." and "09:30 A.M.`” should result in the same output (what other equivalences would you need?).


Step 4: Submit

Push all your code to github. Then submit your repo on gradescope.

Step 5: Done!

Remember to check your code for appropriate comments, formatting, tests.

If you are in the Phelps lab or in CSIL, make sure to log out of the machine before you leave. Also, make sure to close all open programs before you log out. Some programs will not work next time if they are not closed. Remember to save all your open files before you close your text editor.

If you are logged in remotely, you can log out using the exit command:

$ exit

Evaluation and Grading