Question

In: Computer Science

Provide the code segment need to DECLARE an array of structures that could store information about a group of US Passports.

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.


Solutions

Expert Solution

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:


Related Solutions

Declare and initialize an array to store the course name or code.
Declare and initialize an array to store the course name or code.
Write a java code segment to declare an array of size 10 of type String and...
Write a java code segment to declare an array of size 10 of type String and read data for them from a file, prompt user for the file name. Data is stored in a file with 1 string per line.
Provide code samples for the following in C#a. Declare a two-dimensional array of integers names...
Provide code samples for the following in C#a. Declare a two-dimensional array of integers names intArray17.b. Create a loop to calculate the sum of every element in the first column.c. Create a loop to calculate the sum of every element in the array.
In C# - Provide code samples for the following: Declare a two-dimensional array of integers names...
In C# - Provide code samples for the following: Declare a two-dimensional array of integers names intArray17. Create a loop to calculate the sum of every element in the first column. Create a loop to calculate the sum of every element in the array.
c++ I need a code that will fill an array size of 1000, an array of...
c++ I need a code that will fill an array size of 1000, an array of size 2000, and an array size of 10000, with random int values. Basically like this: array1[1000] = filled all with random numbers array2[2000] = filled all with random numbers array3[10000] = filled all with random numbers C++ no need for print
no need to explain 11. What is output by the following code segment? boolean isHighTemp =...
no need to explain 11. What is output by the following code segment? boolean isHighTemp = true; double degree = 100.01; if (isHighTemp) if(degree >= 110) System.out.print(“Extremely Hot”); else System.out.println(“Not Hot”); A) Extremely Hot B) Not Hot C) Hot D) Extremely Hot Not Hot 12. To produce the output 2 4 6 8 10, what is the loop condition for the following loop? int n = 0; Page 3 do { n = n + 2; System.out.print(n + “ ”);...
This is the question from US History 1 ( DISCUSSION) need about 250-300 words 1. Could...
This is the question from US History 1 ( DISCUSSION) need about 250-300 words 1. Could the Civil War have been avoided? Was western expansion inevitable? How did one event contribute to the other?
Could you provide some information about the impact of electric cars on the global economy and...
Could you provide some information about the impact of electric cars on the global economy and the environment? Emissions on producing the batteries compared to the combustion engines.
I need to be able to store 5000 names into an array. I currently have a...
I need to be able to store 5000 names into an array. I currently have a code that generates one random name. I just need to generate an array of 5000 the same way. #include <cstdlib> #include <ctime> #include <iostream> #include <iomanip> using namespace std; string RandomFirstGen(int namelength); int main(){ srand(time(NULL)); int namelength = rand()%(16-8+1)+8; cout<<"name is: "<<RandomFirstGen(namelength)<<endl; return 0; } string RandomFirstGen(int namelength){ for (int i=0; i<=5000 ; i++){ const int MAX = 26; char alphabet[MAX] = { 'a',...
Provide detailed information about the function structures of regression models. (model structure, interpretation of coefficients, graph...
Provide detailed information about the function structures of regression models. (model structure, interpretation of coefficients, graph for the relationship between variables, if any, etc.)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT