Question

Problem: The spread of disease through a community has been determined to follow the formula Current_Infected...

Problem: The spread of disease through a community has been determined to follow the formula Current_Infected = Initial_Infected * e^0.8t where t is the time in days

. Prompt the user to enter the initial (day 0) number of infected people and number of days to considered. The number of infected should be a floating point number and the number of days should be a whole number. Use while loops to confirm robustly that the initial number of infected and the number of days are positive number, you should assume the user enters values of appropriate data types. Create a table from day 0 to entered days and current infected using a for loop. Use formatting to line up the columns and to output the number of infected to 5 significant figures. Make sure that you include column headings. Do not create a variable or constant for e, instead use the appropriate built-in function to calculate the current infected.

using: C++ visual studio

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The program plan:

  • Ask the user for the correct input of infections and number of days using a while loop
  • Assign memories for days and infections
  • Calculate infection on each day using the given equation
  • Display the table at last.

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

The c++ code:

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
   double initialCount;
   int i, d;
   while (true) //loop till correct input is given
   {
       cout << "Enter the number of infected people : ";
       cin >> initialCount; //take input of infected people
       if (initialCount > 0)
           break;
       else
           cout << "\t||Error : Number of people are not positive.\n";
   }

   while (true) //loop till correct input is given
   {
       cout << "Enter the number of days : ";
       cin >> d; //take input of number of days
       if (d > 0)
           break;
       else
           cout << "\t||Error : Number of days are not positive.\n";
   }

   int* days = new int[d + 1]; //assign memory for day 0 to d
   double* counts = new double[d + 1]; //assign memory for infection count

   for (i = 0; i <= d; i++)
   {
       days[i] = i;
       counts[i] = initialCount * exp(0.8 * i); //calculate the infections for day i
   }

   //display the table below
   cout << "\nDays\tInfection Count\n";
   cout.precision(5); //sets maximum precision to 5 significant digits
   for (i = 0; i <= d; i++)
   {
       cout << days[i] << "\t" << counts[i] << "\n";
   }

   return 0;
}

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

Code Screenshot:

#include <iostream> [#include <cmath> using namespace std; int main() { 1 2 3 4 5 6 7 8 9 10 11 12 13 14 double initialCount;while (true) //loop till correct input is given cout << Enter the number of days : ; cin >> d; //take input of number of da//display the table below cout << \nDays\tInfection Count\n; cout.precision (5); for (i = 0; i <= d; i++) { 38 39 40 41 42

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

Output:

Microsoft Visual Studio Debug Console Enter the number of infected people : 10 Enter the number of days : 10 Days 0 1 2 3 4 5

======= THE END =======

Stay safe. Stay immune.

Add a comment
Know the answer?
Add Answer to:
Problem: The spread of disease through a community has been determined to follow the formula Current_Infected...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Part A - SIR model for the spread of disease Overview. This part of the assignment...

    Part A - SIR model for the spread of disease Overview. This part of the assignment uses a mix of theory and data to estimate the contact number c=b/k of an epidemic and hence to estimate the infection-spreading parameter b. The point is that once you know the value of b for a certain disease and population, you can use it in your model the next time there is an cpidemic, thus cnabling you to make predictions about the demand...

  • Problem 1 - Print positive message Create a new project named whatever you want in Visual...

    Problem 1 - Print positive message Create a new project named whatever you want in Visual Studio using the Windows Desktop Wizard or in Xcode. If you're using Visual Studio, add a main.c file to your project; you can use the main.c template I provided on Canvas if you'd like. If you're using Xcode, Xcode automatically generates a main.c file for you. Read in an integer from the user; don't prompt for the user input, because that will confuse the...

  • Problem: Create a program that will ask scientist in tracking the resistances of products from various...

    Problem: Create a program that will ask scientist in tracking the resistances of products from various batches. The resistances of good resistors should be between 3 and 3.5 inclusive. Your program will need to track the number of resistances that are too high (>3.5 ohms), the number of resistances that are too low (<3.0ohms) and calculate the average of the resistances that fall in the proper range (>=3 and <= 3.5). Your program should prompt the user to enter name...

  • If you’re using Visual Studio Community 2015, as requested, the instructions below should be exact but...

    If you’re using Visual Studio Community 2015, as requested, the instructions below should be exact but minor discrepancies may require you to adjust. If you are attempting this assignment using another version of Visual Studio, you can expect differences in the look, feel, and/or step-by-step instructions below and you’ll have to determine the equivalent actions or operations for your version on your own. INTRODUCTION: In this assignment, you will develop some of the logic for, and then work with, the...

  • Create a NOTEPAD or PDF file that restates the problem in your own words, specifies what input is needed, w...

    Create a NOTEPAD or PDF file that restates the problem in your own words, specifies what input is needed, what output is expected, the step by step process (algorithm) to get the output from the input, and test data (input for which you know the expected output) for each of the 3 problems given below. You should not write any actual C++ code. Make sure the problem statement is in your own words and is descriptive enough so someone not...

  • Need some help I am not understanding this programming class at all. We are using Microsoft...

    Need some help I am not understanding this programming class at all. We are using Microsoft visual studio with python in console mode to complete these labs. Double-click to hide white space CIS115 Week 4 Lab Overview Title of Lab: Multiplication Table in Python Summary This week's lab is to create a simple multiplication table using nested loops and if statements. Prompt the user for the size of the multiplication table (from 2x2 to 10x10). Use a validation loop to...

  • III. Overview & Requirements: The following description has been adopted from Deitel & Deitel. One of...

    III. Overview & Requirements: The following description has been adopted from Deitel & Deitel. One of the most popular games of chance is a dice game called "craps," which is played in casinos and back alleys throughout the world. The rules of the game are straightforward: A player rolls two dice. Each die has six faces. These faces contain 1, 2, 3, 4, 5, and 6 spots. After the dice have come to rest, the sum of the spots on...

  • A company has received an order to manufacture 75 customized units of an entertainment cabinet. The...

    A company has received an order to manufacture 75 customized units of an entertainment cabinet. The company is being offered $960 per cabinet and the CEO must decide whether or not to accept the order. An analysis of the production process for the cabinet reveals that a new, special-purpose lathe will be required. The estimated cost of the lathe is $14,400, although there is some uncertainty due to new tariffs. The variable cost is more difficult to estimate because the...

  • C LANGUAGE. PLEASE INCLUDE COMMENTS :) >>>>TheCafe V2.c<<<< #include ...

    C LANGUAGE. PLEASE INCLUDE COMMENTS :) >>>>TheCafe V2.c<<<< #include <stdio.h> int main() { int fries; // A flag denoting whether they want fries or not. char bacon; // A character for storing their bacon preference. double cost = 0.0; // The total cost of their meal, initialized to start at 0.0 int choice; // A variable new to version 2, choice is an int that will store the // user's menu choice. It will also serve as our loop control...

  • Project 4: Month-end Sales Report with array and validation Input dialog box for initial user prompt...

    Project 4: Month-end Sales Report with array and validation Input dialog box for initial user prompt with good data and after invalid data Input OK Cancel Input dialog boxes with sample input for Property 1 Ingut X Input Enter the address for Property 1 Enter the value of Property 1: OK Cancel Input dialog boxes after invalid data entered for Property 1 Error Please enter anmumber greater than D Ester the walue of Peoperty t Console output END SALES REPORT...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT