81.5k views
5 votes
Your friend is an intern at the local Department of Health and needs to prepare a report about the recent activity of the influenza virus. She has recorded the number of cases of each type of flu (A, B, and C) over the last several weeks. Write a C program that will calculate the total cases for each week, determine the level of activity for the week (low, moderate, or widespread) and print a report to a file, including a small bar chart for the weekly cases.

User SJoshi
by
4.4k points

2 Answers

5 votes

Answer:

C code explained below

Step-by-step explanation:

I have provided the proper commented code below.

I hope that you find the answer helpful.

CODE:

-------------------------------------------------------------------------------------------------------------

#include<bits/stdc++.h>

using namespace std;

int main(){

// Defining Variables

int no_of_weeks;

int total_cases = 0;

//Declaring Vector of Pair of Integer and string

std::vector<pair<int,string>> data;

// Taking Input for the Number of Weeks

cout<<"Enter No. of Weeks\\";

cin >> no_of_weeks;

// Running the Loop for no_of_weeks times

for(int i = 0; i < no_of_weeks ; i++){

int A,B,C;

// Taking Input for different types of flus

cout<<"Enter No. of Cases of Flu A, B, C for week" << i + 1 << " seperated by space : \\";

cin >> A >> B >>C;

// Adding all the cases in a week

int cases_in_a_week = A + B + C;

// Updating total cases

total_cases += cases_in_a_week;

// Declaring the level variable

string level;

// Updating the level of the week corresponding to each case

if(cases_in_a_week < 500) level = "Low";

else if(cases_in_a_week >= 500 && cases_in_a_week < 2000) level = "Moderate";

else level = "Widespread";

// Storing the Week's information by using a vector of pairs

// in which pair's first is the number of cases which is of type int

// while the second is the level of the flu which is of the type string

data.push_back(make_pair(cases_in_a_week,level));

}

// Linking the stdoutput to the flu_report.txt file

// this also creates the file with the same name if it doesn't exists

freopen("flu_report.txt", "w", stdout);

// Printing the respective output data with Bar Chart of stars for each level

for(int i = 0;i < no_of_weeks ; i++)

//printing the week no. and number of cases

cout<<i+1<<" "<<data[i].first<<" "<<data[i].second<<"

//printing the total number of cases

cout<<total_cases;

}

User Adim
by
4.6k points
4 votes

Answer:

#include<bits/stdc++.h>

using namespace std;

int main(){

// Defining Variables

int no_of_weeks;

int total_cases = 0;

//Declaring Vector of Pair of Integer and string

std::vector<pair<int,string>> data;

// Taking Input for the Number of Weeks

cout<<"Enter No. of Weeks\\";

cin >> no_of_weeks;

// Running the Loop for no_of_weeks times

for(int i = 0; i < no_of_weeks ; i++){

int A,B,C;

// Taking Input for different types of flus

cout<<"Enter No. of Cases of Flu A, B, C for week" << i + 1 << " seperated by space : \\";

cin >> A >> B >>C;

// Adding all the cases in a week

int cases_in_a_week = A + B + C;

// Updating total cases

total_cases += cases_in_a_week;

// Declaring the level variable

string level;

// Updating the level of the week corresponding to each case

if(cases_in_a_week < 500) level = "Low";

else if(cases_in_a_week >= 500 && cases_in_a_week < 2000) level = "Moderate";

else level = "Widespread";

// Storing the Week's information by using a vector of pairs

// in which pair's first is the number of cases which is of type int

// while the second is the level of the flu which is of the type string

data.push_back(make_pair(cases_in_a_week,level));

}

// Linking the stdoutput to the flu_report.txt file

// this also creates the file with the same name if it doesn't exists

freopen("flu_report.txt", "w", stdout);

// Printing the respective output data with Bar Chart of stars for each level

for(int i = 0;i < no_of_weeks ; i++)

//printing the week no. and number of cases

cout<<i+1<<" "<<data[i].first<<" "<<data[i].second<<"

//printing the total number of cases

cout<<total_cases;

}

Step-by-step explanation:

User MHibbin
by
4.2k points