EECS168:Lab7

From ITTC
Jump to: navigation, search
Navigation
Home
Information

Syllabus
Schedule
Exam Reviews

Classwork

Labs
Submitting Work

Due Time

  • The lab is due Friday July 24th by 11:59pm

Lab conduct

  • Do not use any unauthorized aid, such sites like rentacoder or chegg to obtain answers
  • Do not use code provided by another student
  • Do not reuse code (by you or anyone) from prior semesters
  • If you need help, seek it from:
    • Your lab TA.
    • Me, Dr. Gibbons, my email is jwgibbo@ku.edu / jwgibbo@gmail.com
  • If equipment you don't own (e.g. cycle servers) needs attention or you're having account issues put in a ticket!

Topics

  • Designing classes
  • Arrays of Objects
  • File I/O
  • Command line arguments
  • Input validation

Validating input from Terminal

In this lab we will examine the input from terminal. Read THIS TUTORIAL on how to handle bad input from terminal.

What you are responsible for:

  • Validating all iterations with the user that involve obtaining an int
    • Menu selections
    • Ages
    • Drivers license numbers

What you are NOT responsible for:

  • Validating any of the input from file
  • Validating strings or any other type but int


Destructors

Destructors are a special kind of method that has the following characteristics:

  • name is always ~ClassName()
  • cannot take parameters
  • are NEVER explicitly called, instead are automatically called with the object is dealloacted
    • If the object is stack allocated, then the destructor is called when it is popped off the call stack
    • If it is a heap allocated then the destructor is called when the delete is used on a pointer to the object
  • They are typically used to deallocate anything that the class allocated in other methods
    • In this lab, you can use a destructor in your DMV class to delete[] the array of driver license records allocated in the constructor


Requirements

What's the most exciting thing you can think of? Exactly! The DMV! Today we're going to write a program that reads in Drivers License Records from file and then let's the user interact with the data.

Data File

Here is the data file you will read from: link.

It is formatted in the following way:

<number of entries>
<first name> <last name> <age> <registered voter?> <drivers license number>
<first name> <last name> <age> <registered voter?> <drivers license number>
<first name> <last name> <age> <registered voter?> <drivers license number>
<first name> <last name> <age> <registered voter?> <drivers license number>

Sample from file:

55
Francine Palau  23 N 381043
Kam Swindler  57 Y 449122
Migdalia Constable  21 Y 401934

Classes

DriversLicenseRecord Class

  • Design a DriversLicenseRecord class
    • Note that a Driver has a first name, last name, age, voter status, and license number
    • All member variables should be private
    • Create getters and setters as they are needed
  • NOTE: This class only contains data, it doesn't not interact with the user!

DMV Class

The DMV class will be in charge of...

  • Constructor
    • Reading and storing the drivers license records
    • Make sure the file exist!
  • Destructor
    • Can be used to delete the array of drivers license records
  • Interacting with the user
    • Print menus
    • Validate user input!
  • All I/O to the terminal

Here's the menu for the user:

Select an option:
1) Print all Drivers Info
2) Print all voters
3) Print drivers by last initial
4) Print drivers in age range
5) Quit
Enter your choice: 
Option Description
Print all Driver Info Prints all drivers and all their information in the following format:
<last name>, <first name> (<age>): <drivers license number>

Example of a single entry (you'll print all entries)

Johnson, Larry (67): 301288
Print all voters Prints the driver information in the same format as the previous option, but only prints those registered to vote.
Print drivers by last initial Asks the user for single character, and print the information for all drivers that have a last name starting with that letter (case-insensitive) OR print "No record found." if no drivers have a last name starting with that character.
  • Hint: For case-insensitive comparision you can utilize the ASCII values remembering that the ASCII value of any lower-case letter is exactly 32 more than the upper-case version of that letter
  • OR, you can use the tolower(char) function. Source
Print drivers in age range Prompts the user for two ints that represent an age range. Print all drivers (following the same format as when printing 1 driver) within this age range
Quit Exits the program.

main

Main will make sure that a file name was passed in, then hand control over to the DMV class.

Here's a skeleton of main:


int main(int argc, char** argv)
{
    //Do a check to make sure we have the right number of arguments, 
    //exit if there aren't enough arguments

    std::string fileName = ???;//get the file name from argv
    DMV myDMV(fileName);
    myDMV.run();
    
}

Rubric

  • [0pts] Submission email and tarball are properly formatted
    • Still required
  • [20pts] Stability
    • [5pts] Memory leaks
    • [5pts] Segfaults
    • [5pts] Type validation on user input
    • [5pts] Checks for valid file
  • [10pts] DriversLicenseRecord
    • All member variables private
    • Public methods to get values of member variables
  • [65pts] DMV
    • [5pts]Properly formatted output of records
    • [8pts]Print all Drivers Info
    • [15pts]Print all voters
    • [15pts]Print drivers by last initial
    • [20pts]Print drivers in age range
    • [2pts] Quit
  • [5pts] main
    • Checks parameter count, exits if there's a problem
    • Hands control over to DMV class