In: Computer Science
Provide the code segment need to DECLARE an array of structures that could store information about a group of US Passports. Do not write a program or worry about initializing the structure, all I am looking for is a set of structure types whose combined members would hold all the information found in a password, AND any supporting structures. Be careful on how you declare the members of a structure. Grading will be based on the flexibility of your design (i.e., define many structures and have structures within structures if necessary).
To figure out what information you need to collect, search on line for sample images of US Passports or descriptions of them.
Please find the structure definition in C that variables to store complete details of passport and also i have given a sample C program that uses structure variable in it.
Structure definition:
#include
#include
struct info {
char surname[50];
char givenname[50];
char nationality[50];
};
struct date {
short month;
short day;
int year;
};
struct POB {
char province[50];
char country[50];
};
//typedef to denote as a datatype, so struct keyword is not required
typedef struct {
unsigned long int Id; //passport unique Id
struct info personalDetails; //surname, givenname,
nationality
char passPortType; //type of passport
struct date dob; //date of birth in month, day, year
struct POB pob; //place of birth in month day year
struct date expire; //same as above
struct date validFrom; //same as above
char Authority[50]; //PASSPORT Authority
char code[25]; //code for US PASSPORTs
}PASSPORT;
//We can increase the size of PASSPORT array based on
requirement
#define MAX_PASSPORTS 100
PASSPORT passPortArray[MAX_PASSPORTS];
Sample Program:
#include
#include
struct info {
char surname[50];
char givenname[50];
char nationality[50];
};
struct date {
short month;
short day;
int year;
};
struct POB {
char province[50];
char country[50];
};
//typedef to denote as a datatype, so struct keyword is not required
typedef struct {
unsigned long int Id; //passport unique Id
struct info personalDetails; //surname, givenname,
nationality
char passPortType; //type of passport
struct date dob; //date of birth in month, day, year
struct POB pob; //place of birth in month day year
struct date expire; //same as above
struct date validFrom; //same as above
char Authority[50]; //PASSPORT Authority
char code[25]; //code for US PASSPORTs
}PASSPORT;
//We can increase the size of PASSPORT array based on
requirement
#define MAX_PASSPORTS 1
//sample program uses 1 as array length
int main()
{
PASSPORT passPortArray[MAX_PASSPORTS];
memset(&passPortArray, 0, sizeof(PASSPORT)* 1);
passPortArray[0].Id = 45365435;
strncpy(passPortArray[0].personalDetails.surname, "MARK",
50);
strncpy(passPortArray[0].personalDetails.givenname, "ANTONY",
50);
strncpy(passPortArray[0].personalDetails.nationality, "UNITED
STATES OF AMERICA", 50);
passPortArray[0].passPortType='P';
passPortArray[0].dob.day=1;
passPortArray[0].dob.month=12;
passPortArray[0].dob.year=1987;
strncpy(passPortArray[0].pob.province, "OHIO", 50);
strncpy(passPortArray[0].pob.country, "UNITED STATES OF AMERICA",
50);
passPortArray[0].validFrom.day=30;
passPortArray[0].validFrom.month=11;
passPortArray[0].validFrom.year=2029;
passPortArray[0].expire.day=30;
passPortArray[0].expire.month=11;
passPortArray[0].expire.year=2049;
strncpy(passPortArray[0].Authority, "UNITED STATES OF AMERICA",
50);
strncpy(passPortArray[0].code, "USA", 25);
//for the passPortArray based on requirement
printf("Pass Port Id: %d\nName: %s\nDOB : %d-%d-%d\n",
passPortArray[0].Id,
passPortArray[0].personalDetails.givenname,
passPortArray[0].dob.day,
passPortArray[0].dob.month,
passPortArray[0].dob.year);
return 0;
}
Output:
Pass Port Id: 45365435
Name: ANTONY
DOB : 1-12-1987
Screen Shot: