n Dist.txt it will add vaccine in storage like how many vaccines are needed and from where is coming and Add search function in which from user it will check how many vaccines are available in storage this will be done in Vaccine.txt somewhat like in image given

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

In Dist.txt it will add vaccine in storage like how many vaccines are needed and from where is coming and Add search function in which from user it will check how many vaccines are available in storage this will be done in Vaccine.txt somewhat like in image given

 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>


struct vacc{
    
char vaccName[15];

char vaccCode[2];

char country[15];

int qty;

float population;

}v[10];

// Function Declarations

void create_inventory();

void update_vacc_qty();

int search_vaccine();

void display_vaccine();

// Main Function starts here

 

int main()

{

//create_inventory();

//display_vaccine();

//search_vaccine();

update_vacc_qty();

return 0;

}

//Function to Create Vaccine.txt as per the given table

void create_inventory()

{

int option = 1;

// variables to collect data as per table given

char vaccName[15];

char vaccCode[2];

char country[15];

int qty;

float populaion;

//File definition

FILE *infile;

infile = fopen("Vaccine.txt","w"); // file opening for writing

if(infile == NULL) // Checking for the file creation
{
printf("Vaccine.txt file not found\n");
}

//Accepting data from user from keyboard till user enters 0 to close

while(option != 0)

{

printf("Enter Vaccine Name : ");

scanf("%s",vaccName);

printf("Enter Vaccine Code : ");

scanf("%s",vaccCode);

printf("Enter Counry : ");

scanf("%s",country);

printf("Enter Dosage Required : ");

scanf("%d",&qty);

printf("Enter Population Covered : ");

scanf("%f",&populaion);

//writing to the file using fprintf command

fprintf(infile,"%s %s %s %d %3.2f\n", vaccName,vaccCode,country,qty,populaion);

printf("\nEnter 1 to continue and 0 to exit : ");

scanf("%d",&option);

if(option == 0)

fclose(infile); // closing the file when user wants to exit

}

}

//Function to display the file contents in a formatted way

void display_vaccine()
{

// variables to collect data as per table given

char vaccName[15];

char vaccCode[2];

char country[15];

int qty;

float populaion;

FILE *infile;

infile = fopen("Vaccine.txt","r"); // file opening for reading

if(infile == NULL) //checking for file exists or not

{

printf("Vaccine.txt file not found\n");

}

//printing the header line

printf("%15s\t%2s\t%15s\t%6s\t%10s\n","Vaccine Name","Vaccine Code","Country","Dosage","Population");

// Reading the file

while(fscanf(infile,"%s %s %s %d %f\n",vaccName,vaccCode,country,&qty,&populaion) !=EOF)

{

//printing the read data in a formatted way

printf("%15s\t%13s\t%15s\t%d\t%3.2f\n",vaccName,vaccCode,country,qty,populaion);

}

fclose(infile); // closing the file

}


void update_vacc_qty()
{
int t, option;


char vaccName[15];

char vaccCode[2];

char country[15];

int qty;

float population;

//File definition

FILE *infile;

infile = fopen("dist.txt","w"); // file opening for writing

if(infile == NULL) // Checking for the file creation

{

printf("dist.txt file not found\n");

}

//Accepting data from user from keyboard till user enters 0 to close

while(option != 0)

{

printf("Enter Vaccine Name : ");

scanf("%s",vaccName);

printf("Enter Vaccine Code : ");

scanf("%s",vaccCode);

printf("Enter Counry : ");

scanf("%s",country);

printf("Enter Dosage Required : ");

scanf("%d",&qty);

printf("Enter Population Covered : ");

scanf("%f",&population);

//writing to the file using fprintf command

fprintf(infile,"%s %s %s %d %3.2f\n", vaccName,vaccCode,country,qty,population);

printf("\nEnter 1 to continue and 0 to exit : ");

scanf("%d",&option);

if(option == 0)

fclose(infile); // closing the file when user wants to exit

}

//struct vacc v[10];    

infile = fopen("dist.txt","r"); // file opening for reading

if(infile == NULL) //checking for file exists or not

{

printf("dist.txt file not found\n");

}

// Reading the file
t=0;
while(fscanf(infile,"%s %s %s %d %f\n",vaccName,vaccCode,country,&qty,&population) !=EOF)

{
    //printf("%s",vaccName);
strcpy(v[t].vaccName,vaccName);
strcpy(v[t].vaccCode,vaccCode);
strcpy(v[t].country,country);
v[t].qty=qty;
v[t].population=population;
t++;
}

struct vacc temp;
    
    for (int i = 0; i < t - 1; i++)
    {
        for (int j = 0; j < (t - 1-i); j++)
        {
            if (v[j].qty < v[j + 1].qty)
            {
                temp = v[j];
                v[j] = v[j + 1];
                v[j + 1] = temp;
            } 
        }
    }


//printing the header line

printf("%15s\t%2s\t%15s\t%6s\t%10s\n","Vaccine Name","Vaccine Code","Country","Dosage","Population");

for(int i=0;i<t; i++){
    printf("%15s\t%13s\t%15s\t%d\t%3.2f\n",v[i].vaccName,v[i].vaccCode,v[i].country,v[i].qty,v[i].population);
}

fclose(infile); // closing the file*/

}

 

int search_vaccine()

{

// variables to collect data as per table given

 

while(fscanf(infile,"%s %s %s %d %f\n",vaccName,vaccCode,country,&qty,&populaion) !=EOF)

{

//checking user entered vaccine code and available in the file is same

if(vaccCode[0] == temp[0] && vaccCode[1] == temp[1])

{

// Printing the matched record

printf("%15s\t%2s\t%15s\t%6s\t%10s\n","Vaccine Name"," Vaccine Code","Country","Dosage","Population");

printf("%15s\t%13s\t%15s\t%d\t%3.2f\n",vaccName,vaccCode,country,qty,populaion);

}

}

fclose(infile);// closing the file

}//end of Program

input
Enter Vaccine Code to Search : AZ
Vaccine Name Vaccine Code
Country Dosage Population
AstraZenea
AZ
UK 2
10.00
...Program finished with exit code 0
Press ENTER to exit console.
Transcribed Image Text:input Enter Vaccine Code to Search : AZ Vaccine Name Vaccine Code Country Dosage Population AstraZenea AZ UK 2 10.00 ...Program finished with exit code 0 Press ENTER to exit console.
Enter Vaccine Name
: I
Enter Vaccine Code
9
Enter Counry :
Enter Dosage Required : 4
Enter Population Covered :
РК
30000
Enter 1 to continue and 0 to exit : 1
Enter Vaccine Name
Enter Vaccine Code : PK
Enter Counry : 10
Enter Dosage Required :
Enter Population Covered :
PF
10
60000
Enter 1 to cor
ue and 0 to exit : 0
Vaccine Name Vaccine Code
Country Dosage Population
60000.00
PF
PK10
10 10
I
9
РК 4
30000.00
...Program finished with exit code 0
Press ENTER to exit console.
Transcribed Image Text:Enter Vaccine Name : I Enter Vaccine Code 9 Enter Counry : Enter Dosage Required : 4 Enter Population Covered : РК 30000 Enter 1 to continue and 0 to exit : 1 Enter Vaccine Name Enter Vaccine Code : PK Enter Counry : 10 Enter Dosage Required : Enter Population Covered : PF 10 60000 Enter 1 to cor ue and 0 to exit : 0 Vaccine Name Vaccine Code Country Dosage Population 60000.00 PF PK10 10 10 I 9 РК 4 30000.00 ...Program finished with exit code 0 Press ENTER to exit console.
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY