this code is not reading the input in doing 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. #include "Update.h" #include struct vacc { char vaccName[15]; char vaccCode[2]; char country[15]; int qty; float population; }v[10]; 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("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", &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("Vaccine.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++;
this code is not reading the input in doing
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.
#include "Update.h"
#include<stdio.h>
struct vacc {
char vaccName[15];
char vaccCode[2];
char country[15];
int qty;
float population;
}v[10];
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("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", &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("Vaccine.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);
}
Step by step
Solved in 2 steps with 2 images