Introduction

This lab will have you use some C++ features and things from the STL. Do not forget to compile with g++ -std=c++11 if you are using a C++ 11 feature!

Problem 0: Clean up after yourself

You know the drill.

Create a .gitignore file and add stuff you want to ignore.

You will lose points…

  1. If you don’t have a .gitignore.
  2. If you commit compiled files, editor droppings, data files, or other junk.

Problem 1: Phonebook Lookup

For this problem, you will create a C++ source file called lookup.cpp.

Write a program that takes up to two command line arguments. The first argument is a filename for a telephone book (use phonebook.txt as an example). The second argument is a name to look up the number of; if no second argument is given, list the entire phonebook.

Download phonebook.txt here.

Your program should do a bit of error handling to ensure the user is using the program properly. If the user provides too many or two few command line arguments, your program should print out a helpful usage message. If the user provided an OK number of arguments, your program should check that the file opened properly, etc. It’s good practice.

Use a map<string, tuple<int, int, int> > to store the contents of the phonebook as you read it from the file. You can use make_tuple to, well, make a tuple.

You may assume that the phonebook file will be formatted properly. There’s no need to check for a bunch of error conditions related to the structure of the phonebook file.

You may also assume that the names in the phonebook are all unique.

If the requested name is not present in the phonebook file, then act like we didn’t search for a name at all. Just print out the contents of the phonebook.

Problem 1 hints

Problem 2: Area Codes

For this problem, you will create a C++ source file called area_codes.cpp.

Write a program that takes one command line argument: the filename for a telephone book (see phonebook.txt for an example). The program will output a list of unique telephone area codes from the numbers in the file.

Again, your program should do a bit of error handling to ensure the user is using the program properly. If the user provides too many or two few command line arguments, your program should print out a helpful usage message. If the user provided an OK number of arguments, your program should check that the file opened properly, etc.

Use a set to store the area codes.

You can borrow the same phonebook-loading logic you wrote for Problem 1.

Problem 2 hints

Epilogue

Grading

You will be graded on:

  • The layout of your project. You will lose points if…
    • …files are not named as specified.
    • …files or directories are not present in the expected locations documented at the bottom of this write-up.
  • The presence of a useful .gitignore and absence of junk files.
  • Problem 1
    • The quality / style of your C++ code
      • Be sure to comment your code!
    • Error handling for bad command line arguments
    • The usage of a map<string, tuple<int, int, int> >
    • The compile-ability / functionality of your program
      • It’s gotta compile
      • It’s gotta work
      • The output’s gotta be clear and make sense
  • Problem 2
    • The quality / style of your C++ code
      • Be sure to comment your code!
    • Error handling for bad command line arguments
    • The usage of a set
    • The compile-ability / functionality of your program
      • It’s gotta compile
      • It’s gotta work
      • The output’s gotta be clear and make sense
  • In your solution for either (or both) Problem 1 and Problem 2, you must…
    • Use auto somewhere
    • Use a for-each loop somewhere

Submissions

As always, your git repo on http://git-classes.mst.edu is your submission. Don’t forget to commit and push all relevant files. Make sure you see everything you expect on GitLab!

We expect to see the following files on your master branch:

  • .gitignore
  • README.md
  • area_codes.cpp
  • lookup.cpp