Scenario: You work at a local video store that rents movies in the format of dvds and vhs video tapes. Your manager, knowing that you have some programming experience, wants you to design a program to manage customer accounts, the dvd library, and the vhs movie library. Up to this point, the video store keeps all records of customers on paper (an index card for each listing their account number, their name, their address, their telephone number, their current rentals, the the due dates of their videos). When a customer rents one or more videos, the title, format, the rental price, and the due dates are written on their index card. This is a small shop -- the store only has one copy of each movie per format, so when a video or dvd is returned they know exactly who rented the video. Your manager wants you to design a program that will keep track of customer information and movie information. In this activity, please design some data structures that you would use to keep track of appropriate information. If you create a struct, please write the C code for the struct. You do not need to write any functions -- just the data structures. Try to incorporate nested data structures into your plan. (Hint: If you need some help, think of each vhs video or dvd being represented by a structure.)
typedef struct{
char first_name[MAX_NAME + 1]; /* lists first
name of customer */
char last_name[MAX_NAME + 1]; /* lists
last name of customer */
char street_address[MAX_ADDRESS + 1];
/* lists street address
of customer */
char city[MAX_CITY + 1];
/* lists city of address of customer */
char state[3];
/* use postal abbreviation for state */
int telephone_number[10];
/* telephone number -- (xxx) xxx-xxxx */
int account_id;
/* unique account id for customer */
movie movie_rentals[MAX_RENTAL + 1];/*
list of dvds currently rented by
customer */
double account_balance;
/* current account balance for customer */
} customer;
typedef struct{
char title[MAX_TITLE + 1]; /* movie
title */
int year;
/* year produced */
char director[MAX_DIRECTOR + 1]; /* last name
of director -- just
in case 2
movies have the same title */
int format;
/* 1 = dvd format, 2 = vhs format */
int is_available;
/* 0 means that it is currently rented,
1 means that it is available */
double rental_price;
/* price to rent this video */
date due_date;
/* if currently rented, this lists
the due date,
if not currently rented this lists the
due date of the previous renter */
int account_rented;
/* this is equal to the account number
of the current renter, 0 otherwise
(no person gets account id 0) */
} movie;
There would also be an array of movies containing every movie that the video store owns. This array might store the movies in alphabetical order by title so that we could perform binary search on the array to locate a particular movie.
There would also be an array of customers containing every customer
who has an account at the video store. This array might store customer
last names in alphabetical order so we could perform binary search on the
array to locate a particular customer. Or, one might want to store
the customers in order according to their account id so when a movie is
returned, the current id attached to the movie can be located quickly.