C Structures and Arrays Develop a structure declaration (see template below) tha
ID: 3594714 • Letter: C
Question
C Structures and Arrays
Develop a structure declaration (see template below) that will model the attributes you see on your
drivers license. You do not have to populate it with actual information, just provide a set of structures that could be use to model and capture the driver
license data. Think of what type each member of the structure should be, for example
int (whole numbers)
float (floating point)
double (floating point with many decimal places)
char (single character)
char name[x] (character string ... x is the size, name is variable, what is a worst case size to handle your information on anyone?)
struct name (a structure with one or more members)
You will probably note that many of your members in the struct license item will probably be structures themselves. Look at each item on your license
and think if there is a group of data that belongs together. For example, when I see DOB on my license, its contains a date value that has month, day, and
year. You will also see other things, for example, license number, that probably make more sense just being a simple member that is itself not a structure
type.
Do research your home state's driver's license on their web sites if you are unsure of particular fields and usage. I know each state's drivers license has
its own unique qualities, but most have have basically the same information.
/* add structures */
#define SIZE 5
/* add supporting structures */
struct date
{
int month;
int day;
int year;
};
/* add other supporting structures */
/* the actual license structure that will contain all needed members */
struct license
{
char number [25]; /* alpha numeric license number - combo of letters and numbers, 25 should be enough */
struct date birthDate; /* the date the driver was born, note that its a structure member within the license structure */
/* add other members - some will be structure types, */
/* others will be one of the types mentioned above */
};
/* declare an array of SIZE number of drivers */
struct license drivers [SIZE];
Explanation / Answer
#include <stdio.h>
#define SIZE 5
struct date {
int month;
int day;
int year;
};
struct name {
char firstname[50];
char lastname[50];
char middlename[50];
};
struct height {
int feets;
int inches;
};
struct license {
char id[25]; // id
struct name n; // name struct which contains first name, last name, middle name
struct height h; // height struct which records both feets and inches
struct date dob; // date struct for date of birth
struct date expires; // date struct for expire date
struct date issued; // date struct for issued date
char sex; // char for sex 'M' or 'F'
char class_type; // license type. for example 'C'
char eyes_type[10]; // eye_color. for example "Blue"
};
int main() {
struct license drivers[SIZE]; // declaring license array
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.