How many passports will we be creating today? 2 Please input ID of passport 1: 15625 What is the gender? M First Name? (end with a dot)Kyle. Last Name? (end with a dot)Smith. Address? (end with a dot)123 Lead Ave SE. Please input ID of passport 2: 15626 What is the gender? F First Name? (end with a dot)Clair. Last Name? (end with a dot)Smith. Address? (end with a dot)1059 Dr MLK Jr NE. Info of User 1: ID: 15625 Gender: M First Name: Kyle Last Name: Smith Address: 123LeadAveSE Info of User 2: ID: 15626 Gender: F First Name: Clair Last Name: Smith Address: 1059DrMLKJrNE

Np Ms Office 365/Excel 2016 I Ntermed
1st Edition
ISBN:9781337508841
Author:Carey
Publisher:Carey
Chapter7: Developing An Excel Application
Section: Chapter Questions
Problem 3.6CP
icon
Related questions
Question

Programing C

First, you should ask how many passports will be issued.
Then, ask for the first name, last name, address, passport ID and gender of each passport.
Lastly, print out the information.

Follow some guidelines when writing your code: You should have one structure definition with the following members:

· FirstName: should be a character array, accepting at most 100 characters
· LastName: should be a character array, accepting at most 100 characters
· Address: should also be a char array, accepting at most 100 characters
· PassportID: should be an integer
· Gender: should be a single character

Please without using #include<stdlib.h>
Just with #include<stdio.h> please

The code has to have at least one structure definition and five different functions (including main).

Example of the output:

How many passports will we be creating today? 2
Please input ID of passport 1: 15625
What is the gender? M
First Name? (end with a dot)Kyle.
Last Name? (end with a dot)Smith.
Address? (end with a dot)123 Lead Ave SE.
Please input ID of passport 2: 15626
What is the gender? F
First Name? (end with a dot)Clair.
Last Name? (end with a dot)Smith.
Address? (end with a dot)1059 Dr MLK Jr NE.
Info of User 1:
ID: 15625
Gender: M
First Name: Kyle
Last Name: Smith
Address: 123LeadAveSE
Info of User 2:
ID: 15626
Gender: F
First Name: Clair
Last Name: Smith
Address: 1059DrMLKJrNE
Transcribed Image Text:How many passports will we be creating today? 2 Please input ID of passport 1: 15625 What is the gender? M First Name? (end with a dot)Kyle. Last Name? (end with a dot)Smith. Address? (end with a dot)123 Lead Ave SE. Please input ID of passport 2: 15626 What is the gender? F First Name? (end with a dot)Clair. Last Name? (end with a dot)Smith. Address? (end with a dot)1059 Dr MLK Jr NE. Info of User 1: ID: 15625 Gender: M First Name: Kyle Last Name: Smith Address: 123LeadAveSE Info of User 2: ID: 15626 Gender: F First Name: Clair Last Name: Smith Address: 1059DrMLKJrNE
Expert Solution
Step 1

The program requires to ask user for their information to create the passports. The program uses structure to store the information of each person.

The following points are important to be able to write this program:

  • Include header file stdio.h for using scanf() and printf() functions.
  • In this program, two functions have been defined:
    • Function getinformation() is used to ask the user for the number of passports to be entered. The user then enters value for the passport.
    • Function print() is used to print all the information stored in the array of the structure.
  • The main() function , creates a pointer to the structure, and then calls the function getinformation() and print().
  • In the structure Person, there are following entities:
    • FirstName
    • LastName
    • Address
    • PassportID
    • Gender
Step 2

Program:

#include <stdio.h>

//structure Person
struct Person
{   
    //char array for storing firstname
    char firstname[100];
    //char array for storing lastname
    char lastname[100];
    //char array for storing address
    char address[100];
    //int variable to store passport ID
    int passID;
    //char variable to store gender
    char gender;
}; 

//function that inputs values of the persons
//return pointer to the array of persons
struct Person * getinformation(int *size)
{
    int num;
    //memory buffer
    char fname[100],lastname[100],add[100];
    int ID;
    char g;
    
    //iterator variable
    int i=0;
    
    //ask user to input number of passports
    printf("How many passports will we be creating today?\n");
    //input number of passports
    scanf("%d",&num);
    
    //pointer to structure of Person
    struct Person * info;
    
    //loop until number of passports
    for(i=0;i<num;i++)
    {
     //input passport ID
        printf("Please input ID of passport %d ",i+1);
        scanf(" %d",&info[i].passID);
        
        //input gender
        printf("What is the gender? ");
        scanf(" %c",&info[i].gender);
        
        //input first name
        printf("First Name? (end with a dot) ");
        scanf(" %[^.]%*c",info[i].firstname);
        
        //input last name
        printf("Last Name? (end with a dot) ");
        scanf(" %[^.]%*c",info[i].lastname);
        
        //input address
        printf("Address? (end with a dot) ");
        scanf(" %[^.\n]%*c",info[i].lastname);
    }
    //size of array referenced 
    *size = num;
    
    //return pointer to the array of structure
    return info;
}

//function to print the information
void print(struct Person * p,int len)
{
 //iterator variable
    int i;
    
    //loop until length of passport array
    for(i=0;i<len;i++){
     
     //print all info
     
     printf("Info of user %d",i+1);
        printf("ID of passport : ");
        printf("%d\n",p[i].passID);
        
        printf(" Gender: ");
        printf(" %c\n",p[i].gender);
        
        printf(" First Name: ");
        printf(" %s\n",p[i].firstname);
        
        printf(" Last Name: ");
        printf(" %s\n",p[i].lastname);
        
        printf(" Address: ");
        printf(" %s\n",p[i].address);
    }
}

//main() function
int main()

    //variable to store size
    int size=0;
    //pointer to 
    struct Person *A;
    A = getinformation(&size);
    print(A,size);
}

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Oracle 12c: SQL
Oracle 12c: SQL
Computer Science
ISBN:
9781305251038
Author:
Joan Casteel
Publisher:
Cengage Learning
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:
9780357392676
Author:
FREUND, Steven
Publisher:
CENGAGE L