* i want to add update function .c and .h class  in that code  also in display vaccine it's not displaying anything Menu  1. Create inventory 2. Update inventory 3. Search vaccine 4. Display vaccine     Create.c : #include #include "Create.h" void create_inventory() {  int option;  char vaccName[15];  char vaccCode[2];  char country[15];  int qty;  float populaion;    FILE* infile;  infile = fopen("Vaccine.txt", "w");   if (infile == NULL)   {   printf("Vaccine.txt file not found\n");  }    option = 1;  while (option != 0)  {   printf("Enter Vaccine Name : ");   scanf("%s", vaccName);   printf("Enter Vaccine Code : ");   scanf("%s", vaccCode);   printf("Enter Country : ");   scanf("%s", country);   printf("Enter Dosage Required : ");   scanf("%d", &qty);   printf("Enter Population Covered : ");   scanf("%f", &populaion);     fprintf(infile, "%15s %2s %15s %d %3.2f\n", vaccName, vaccCode, country, qty, populaion);   printf("\nEnter 1 to continue and 0 to exit : ");   scanf("%d", &option);   if (option == 0)    break;     }  fclose(infile);  }   Display.c: #include "Display.h" #include   void display_vaccine() {    char vaccName[15];  char vaccCode[2];  char country[15];  int qty;  float populaion;  FILE* infile;  infile = fopen("dist.txt", "r");   if (infile == NULL)   {   printf("Vaccine.txt file not found\n");  }  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)  {   printf("%15s\t%2s\t%15s\t%d\t%3.2f\n", vaccName, vaccCode, country, qty, populaion);  }  fclose(infile);  } Search.c:   #include "Search.h" #include int search_vaccine() {  char vaccName[15];  char vaccCode[2];  char country[15];  int qty;  float populaion;  FILE* infile;  char vcode[2];  char temp[2];  int value;  infile = fopen("Vaccine.txt", "r");    printf("Enter Vaccine Code to Search : ");  scanf("%s", vcode);  if (infile == NULL) // checking for file existence  {   printf("Vaccine.txt file not found\n");  }  strcpy(temp, vcode);    while (fscanf(infile, "%s %s %s %d %f\n", vaccName, vaccCode, country, &qty, &populaion) != EOF)  {     if (vaccCode[0] == temp[0] && vaccCode[1] == temp[1])   {      printf("%15s\t%2s\t%15s\t%6s\t%10s\n", "Vaccine Name", " Vaccine Code", "Country", "Dosage", "Population");    printf("%15s\t%2s\t%15s\t%d\t%3.2f\n", vaccName, vaccCode, country, qty, populaion);   }  }  fclose(infile); } TestMain.c #include #include #include #include "Search.h" #include "Display.h" #include "Create.h" struct vacc {  char vaccName[15];  char vaccCode[2];  char country[15];  int qty;  float population; }v[10]; // Function Declarations void update_vacc_qty(); int main() {  int ch;  do {   printf("\n 1:create inventory");   printf("\n 2: display vaccine info ");   printf("\n 3: search vaccine");   printf("\n enter your choice (0 to exit):");   scanf("%d", &ch);   switch (ch)   {   case 1: create_inventory();    break;   case 2: display_vaccine();    break;   case 3: search_vaccine();    break;   default: break;   }  } while (ch != 0);  return 0; }   void update_vacc_qty() {  int t;  int option;  char vaccName[15];  char vaccCode[2];  char country[15];  int qty;  float population;  FILE* infile;  infile = fopen("Vaccine.txt", "w");  if (infile == NULL)  {   printf("dist.txt file not found\n");  }  option = 1;  while (option != 0)  {   printf("Enter Vaccine Name : ");   scanf("%s", vaccName);   printf("Enter Vaccine Code : ");   scanf("%s", vaccCode);   printf("Enter Country : ");   scanf("%s", country);   printf("Enter Dosage Required : ");   scanf("%d", &qty);   printf("Enter Population Covered : ");   scanf("%f", &population);     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);  }  {   printf("dist.txt file not found\n");  }  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.qty = v[j].qty;     v[j].qty = v[j + 1].qty;     v[j + 1].qty = temp.qty;    }   }  }  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);  }

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

* i want to add update function .c and .h class  in that code 

also in display vaccine it's not displaying anything

Menu 
1. Create inventory
2. Update inventory
3. Search vaccine
4. Display vaccine

 

 

Create.c :


#include<stdio.h>
#include "Create.h"


void create_inventory()

{

 int option;

 char vaccName[15];

 char vaccCode[2];

 char country[15];

 int qty;

 float populaion;

 

 FILE* infile;

 infile = fopen("Vaccine.txt", "w"); 

 if (infile == NULL) 
 {
  printf("Vaccine.txt file not found\n");
 }

 

 option = 1;
 while (option != 0)

 {

  printf("Enter Vaccine Name : ");

  scanf("%s", vaccName);

  printf("Enter Vaccine Code : ");

  scanf("%s", vaccCode);

  printf("Enter Country : ");

  scanf("%s", country);

  printf("Enter Dosage Required : ");

  scanf("%d", &qty);

  printf("Enter Population Covered : ");

  scanf("%f", &populaion);

 

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

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

  scanf("%d", &option);

  if (option == 0)
   break;   

 }

 fclose(infile); 

}

 

Display.c:

#include "Display.h"
#include<stdio.h>

 

void display_vaccine()
{

 

 char vaccName[15];

 char vaccCode[2];

 char country[15];

 int qty;

 float populaion;

 FILE* infile;

 infile = fopen("dist.txt", "r"); 

 if (infile == NULL) 

 {

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

 }

 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)

 {

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

 }

 fclose(infile); 

}

Search.c:  

#include "Search.h"
#include<stdio.h>


int search_vaccine()

{

 char vaccName[15];

 char vaccCode[2];

 char country[15];

 int qty;

 float populaion;

 FILE* infile;

 char vcode[2];

 char temp[2];

 int value;

 infile = fopen("Vaccine.txt", "r");

 

 printf("Enter Vaccine Code to Search : ");

 scanf("%s", vcode);

 if (infile == NULL) // checking for file existence

 {

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

 }

 strcpy(temp, vcode);

 

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

 {

 

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

  {

 

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

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

  }

 }

 fclose(infile);

}

TestMain.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Search.h"
#include "Display.h"
#include "Create.h"

struct vacc {

 char vaccName[15];

 char vaccCode[2];

 char country[15];

 int qty;

 float population;

}v[10];

// Function Declarations
void update_vacc_qty();


int main()

{

 int ch;

 do {
  printf("\n 1:create inventory");
  printf("\n 2: display vaccine info ");
  printf("\n 3: search vaccine");
  printf("\n enter your choice (0 to exit):");
  scanf("%d", &ch);


  switch (ch)
  {
  case 1: create_inventory();
   break;
  case 2: display_vaccine();
   break;
  case 3: search_vaccine();
   break;
  default: break;
  }

 } while (ch != 0);
 return 0;

}

 

void update_vacc_qty()
{
 int t;
 int option;


 char vaccName[15];

 char vaccCode[2];

 char country[15];

 int qty;

 float population;

 FILE* infile;

 infile = fopen("Vaccine.txt", "w");

 if (infile == NULL)

 {

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

 }


 option = 1;
 while (option != 0)

 {

  printf("Enter Vaccine Name : ");

  scanf("%s", vaccName);

  printf("Enter Vaccine Code : ");

  scanf("%s", vaccCode);

  printf("Enter Country : ");

  scanf("%s", country);

  printf("Enter Dosage Required : ");

  scanf("%d", &qty);

  printf("Enter Population Covered : ");

  scanf("%f", &population);

 

  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);

 }

 {

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

 }


 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.qty = v[j].qty;
    v[j].qty = v[j + 1].qty;
    v[j + 1].qty = temp.qty;
   }
  }
 }


 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); 

}

Update vaccine quantities. The system should allow the employees to select a
particular vaccine and indicate either received or distributed quantity. In either case,
the quantity of the selected vaccine needs to be updated accordingly in the vaccine.txt
file.
E.g. Assume that the initial quantity of Pfizer vaccine in vaccine.txt file is 1 million.
When the company receives a new stock, this quantity has to be added to the existing
quantity of 1 million in the vaccine.txt file. In the case where the vaccines are distributed
to hospitals for vaccination, the distributed quantity has to be subtracted from the
quantity available in the vaccine.txt file.
Note: Whenever a vaccine is distributed to hospitals, its code and the quantity
distributed need to be recorded into a text file named as dist.txt. Each vaccine is
expected to be distributed more than once. Hence, while testing the program, there
should be at least 10 records created in the dist.txt file.
Transcribed Image Text:Update vaccine quantities. The system should allow the employees to select a particular vaccine and indicate either received or distributed quantity. In either case, the quantity of the selected vaccine needs to be updated accordingly in the vaccine.txt file. E.g. Assume that the initial quantity of Pfizer vaccine in vaccine.txt file is 1 million. When the company receives a new stock, this quantity has to be added to the existing quantity of 1 million in the vaccine.txt file. In the case where the vaccines are distributed to hospitals for vaccination, the distributed quantity has to be subtracted from the quantity available in the vaccine.txt file. Note: Whenever a vaccine is distributed to hospitals, its code and the quantity distributed need to be recorded into a text file named as dist.txt. Each vaccine is expected to be distributed more than once. Hence, while testing the program, there should be at least 10 records created in the dist.txt file.
Expert Solution
steps

Step by step

Solved in 4 steps with 9 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