Lab Assignment April 28
In USA, each state has different rules for license plates. In this program we will assume
that NJ and NC has 6 digit numbers, with the following conditions, NJ starts with 1-5 and NC
starts with 6-9, NY and MA has 7 digit number, with the following conditions NY ends with
1-5 and MA ends with 6-9, RI and DE has 4
or
5 digit
number, with the following condition RI starts with even number and DE starts with odd number.
Your program will read a number of cars in the parking lot, store license plates in
the array, and finds the number of cars from each of the 6 states listed above (NJ, NC, NY, MA, RI, DE).
Write the following functions:
- int count_digit(int num) - finds and returns the number of digits of parameter num
- void make_array(int array[], int size) - makes an array of size integers. Make it USER
INPUT for testing purposes. This function will be used to create an array of license plates
that are currently in the parking lot
- void print_array(int array[], int size) - prints arrayof size elements
- void process_plates(int array[], int
size)
that has 2 parameters, array of plates and size. This function will create a new array
states with initial value 0 for all items. You can assume
that array of states has size 6 since you are taking care of 6 states and you can assume that
the first element is for NJ, second for NC, third for NY, forth for MA, fifth for RI and sixth
for DE. This function will count the number of plates for each state and store the counters in
the appropriate location of array states. THIS FUNCTION MUST CALL FUNCTION count_digit to find
the number of digits in the license plate. This function will PRINT array states at the end of
the function. You don't need to give special treatment to the case that NO CARS from specific
state in the parking lot, just print 0 at this case.
- Write main to test your program. Enter number of cars in the parking lot, call function
make array to enter license plate for each state. Print the array of plates, and then call
function process_plates to get a result.
Pay attention: your input for license plate number could be ANY POSITIVE INTEGER up to
2147483647. And your program will ignore any numbers that are shorter than 4 digits and longer
than 7 digits since they don't belong to any state
Example:
- Input: 10 cars in the parking lot
- license plates (I added state indication BUT IT IS NOT PART OF THE INPUT):
- 12345 (DE)
- 2111 (RI)
- 77373777 (no state)
- 345678 (NJ)
- 956567 (NC)
- 1231231 (NY)
- 1111113 (NY)
- 111 (no state)
- 3444 (DE)
- 55555 (DE)
- Output:
1 1 2 0 1 3