I have a c code I need to write comments for the code */ #include #include foc_sp20.h
Question:
I have a c code I need to write comments for the code
*/
#include
#include "foc_sp20.h"
int list(void);
double task3(void);
void task4(double probability);
void task5(void);
int main()
{
//_____________________________________task 2
int number;
double probability;
for(int se =2;se>1;se++)
{
number=list();
if(number==1)
{
probability=task3();
}
else if(number==2)
{
task4(probability);
}
else if(number==3)
{
task5();
}
else if(number==4)
{
printf("\nThank you.\n");
se=0;
}
else
{
printf("\nYou have entered a wrong number\n");
}
}
return 0;
}
int list(void)
//_____________________________________task 3
{
int number;
printf("1.Create Record\n2.Required Actions\n3.Status\n4.Exit\nPlease enter your number\n");
scanf("%d",&number);
return number;
}
double task3(void)
{
char name[50];
int id;
int age;
int history;
double temperature;
int breathing;
int ap[100][500];
double probability;
FILE *information1;
printf("\nName >");
scanf("%s",name);
printf("\nID >");
scanf("%d",&id);
printf("\nAge >");
scanf("%d",&age);
printf("\nDid you have any chronic diseases before ? (yes=1,no=0) >");
scanf("%d",&history);
printf("\nTemperature >");
scanf("%lf",&temperature);
printf("\nDo you have breathing difficultie ? (yes=1,no=0) >");
scanf("%d",&breathing);
for(int row =0;row<100;row++)
{
for(int column=0;column<500;column++)
{
if((row>30&&column>50)&&(row<70&&column<450))
{
ap[row][column]=255;
}
else
{
ap[row][column]=100;
}
}
}
if(((age>60)||(age<16))&&(history==1)&&(temperature>37)&&(breathing==1))
{
probability = 0.75;
for(int row =30;row<70;row++)
{
for(int column=50;column<450;column++)
{
if((row>30&&column>50)&&(row<70&&column<350))
{
ap[row][column]=1;
}
}
}
}
else if(((age>60)||(age<16))&&(history==0)&&(temperature>37)&&(breathing==1))
{
probability = 0.50;
for(int row =30;row<70;row++)
{
for(int column=50;column<450;column++)
{
if((row>30&&column>50)&&(row<70&&column<250))
{
ap[row][column]=1;
}
}
}
}
else if(((age<60)||(age>16))&&(history==0)&&(temperature>37)&&(breathing==1))
{
probability = 0.25;
for(int row =30;row<70;row++)
{
for(int column=50;column<450;column++)
{
if((row>30&&column>50)&&(row<70&&column<150))
{
ap[row][column]=1;
}
}
}
}
else if((history==1)&&(temperature==37)&&(breathing==0))
{
probability = 0.05;
for(int row =30;row<70;row++)
{
for(int column=50;column<450;column++)
{
if((row>30&&column>50)&&(row<70&&column<70))
{
ap[row][column]=1;
}
}
}
}
information1=fopen("information.txt","a");
fprintf(information1,"%s %d %lf %d %d %d %lf \n",name,id,temperature,age,history,breathing,probability);
fclose(information1);
showArray(100,500,ap);
return probability;
}
void task4(double probability)
//_____________________________________task 4
{
FILE *hospitalBeds1;
int totalbeds;
int usedbeds;
if(probability==0.75)
{
printf("\nThis person must be moved to isolation hospitals for coronavirus cases.\nYour diagnosis will be passed to the Ministry of Health\n");
}
else if(probability==0.50)
{
hospitalBeds1=fopen ("hospitalBeds.txt","r");
fscanf(hospitalBeds1,"%d %d",&totalbeds,&usedbeds);
if(usedbeds>=100)
{
printf("\nThere is no avaliable beds in the hospital\n");
fclose(hospitalBeds1);
}
else
{
fclose(hospitalBeds1);
hospitalBeds1=fopen("hospitalBeds.txt","w");
usedbeds++;
fprintf(hospitalBeds1,"%d %d",totalbeds,usedbeds);
printf("\nYou need to move to the hospital to isolate yourself\n");
}
}
else if((probability==0.25)||(probability==0.05))
{
printf("\nYou must be isolated in your home and you must call the hospital if you feel the symptoms of the virus\n");
}
}
void task5(void)
//_____________________________________task 5
{
char name[50];
int a;
double average75;
double average50;
double average25;
double average05;
int averageage;
double averagetemp;
double totalusers75;
double totalusers50;
double totalusers25;
double totalusers05;
int totalage=0;
double totaltemp=0;
int id;
int age;
int history;
double temperature;
int breathing;
FILE *information1;
double probability;
int users;
information1=fopen("information.txt","r");
a=fscanf(information1,"%s %d %lf %d %d %d %lf",name,&id,&temperature,&age,&history,&breathing,&probability);
for( users=0;users<=a;users++)
{
if(probability==0.75)
{
totalusers75++;
}
else if(probability==0.50)
{
totalusers50++;
}
else if(probability==0.25)
{
totalusers25++;
}
else if(probability==0.05)
{
totalusers05++;
}
totalage=age+totalage;
totaltemp=temperature+totaltemp;
a=fscanf(information1,"%s %d %lf %d %d %d %lf",name,&id,&temperature,&age,&history,&breathing,&probability);
}
average75=totalusers75/users;
average50=totalusers50/users;
average25=totalusers25/users;
average05=totalusers05/users;
averageage=totalage/users;
averagetemp=totaltemp/users;
printf("Total vistors = %d \nThe percentage of 75 = %lf\nThe percentage of 50 = %lf\nThe percentage of 25 = %lf\nThe percentage of 5 = %lf\nThe average of ages = %d\nThe average of temperatures = %lf\n",users,average75,average50,average25,average05,averageage,averagetemp);
}
Systems analysis and design
ISBN: 978-0136089162
8th Edition
Authors: kenneth e. kendall, julie e. kendall