Computer Science, asked by progx, 11 months ago


Suppose you are given some n observations regarding infection from some disease. Each observation consists of two parts: (a) the date on which the observation was made, (b) the number of patients who tested positive. For simplicity we assume that the dates are positive integers. Also assume that any patient is tested at most once. A number D, the maximum number of days that the infection persists, is also given.

A main program that gives information about the disease is already typed in (and also visible to you). It first takes as input D, the expected disease duration. Then it takes as input n, the number of observations, then n pairs that give the date (integer), and the number of patients testing positive (integer). This information is to be stored in a struct "Observation" which you are to define. The information is to be read using a member function "read" of Observation struct, which also you must define. Next you are to write a function "uncured" which says how many patients will be uncured on a given date. For simplicity assume that if a group of patients test positive on date i, then they will be reported as uncured only between the dates i (inclusive) and i+D (exclusive).

What you write is to be used with the main program which is already typed in.

int main(){
int D; cin >> D;
int n; cin >> n;
Observation observations[n];
for(int i=0; i while(true){
int date; cin >> date;
if(date == -1) break;
cout << date << " " << uncured(observations, n, D, date) << endl;
}
}

Answers

Answered by ankitmca4u
0

Answer:

#include <iostream>

#define repeat(x) for(int _iterator_i = 0, _iterator_limit = x; _iterator_i < _iterator_limit; _iterator_i ++)

#define main_program int main()

#include <cmath>

using namespace std;

struct Observation{

       int date;

       int num;

       void read(){

               cin >> date >> num;

       }

};

int uncured( Observation o[], int size, int D, int dt){

 int estimate = 0;

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

   if(o[i].date +D > dt && o[i].date <= dt)

     estimate = estimate + o[i].num;

 return estimate;

}

int main(){

       int D; cin >> D;

       int n; cin >> n;

       Observation observations[n];

       for(int i=0; i<n; i++) observations[i].read();

       while(true){

               int date; cin >> date;

               if(date == -1) break;

                    cout << date << " " << uncured(observations, n, D, date) << endl;

       }

}

Explanation:

week 9 assignment -1

Similar questions