Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
the output should display the maximum number of cases in each districts and the total positive cases, but im not getting it

the expected output is:
*****************************************************************************************
ANALYSIS OF POSITIVE AND NEGATIVE CASES FOR 2 DAYS
*****************************************************************************************
District with the highest number of positive cases in a day : B (22) Day 1
District with the highest number of negative cases in a day : A (15) Day 2
Total number of cases in A : 30 positives // 23 negatives ##
Total number of cases in B : 34 positives // 20 negatives ##
Total number of cases in C : 25 positives // 22 negatives ##
Total number of cases in D : 26 positives // 19 negatives ##
Average number of cases in A : 15.0 positives // 11.5 negatives ##
Average number of cases in B : 17.0 positives // 10.0 negatives ##
Average number of cases in C : 12.5 positives // 11.0 negatives ##
Average number of cases in D : 13.0 positives // 9.5 negatives ##
*****************************************************************************************


What I have tried:

#include <iostream>
#include <fstream>
#include <string>
#include <sstream> 
#include<cmath>
using namespace std;

int main()

{
	fstream dataFile;
	string title;
	int row = 56;
	int column = 4;
	string data[row][column];
	int district, calculateMaxMin, cases, day, MaxPos, MinPos;

void calculateMaxMin()
{

	int max=0;
	for()
	{
	  for()
	  {
	   if(data>max)
	   max=data
      }
   } 
   cout<<district<<cases<<day;
Posted
Updated 6-Jun-20 6:15am
v4
Comments
Patrice T 6-Jun-20 4:15am    
Show sample input and expected out and actual output.
wrtjs 6-Jun-20 4:31am    
this is the expected output:
*****************************************************************************************
ANALYSIS OF POSITIVE AND NEGATIVE CASES FOR 2 DAYS
*****************************************************************************************
District with the highest number of positive cases in a day : B (22) Day 1
District with the highest number of negative cases in a day : A (15) Day 2
Total number of cases in A : 30 positives // 23 negatives ##
Total number of cases in B : 34 positives // 20 negatives ##
Total number of cases in C : 25 positives // 22 negatives ##
Total number of cases in D : 26 positives // 19 negatives ##
Average number of cases in A : 15.0 positives // 11.5 negatives ##
Average number of cases in B : 17.0 positives // 10.0 negatives ##
Average number of cases in C : 12.5 positives // 11.0 negatives ##
Average number of cases in D : 13.0 positives // 9.5 negatives ##
*****************************************************************************************
Patrice T 6-Jun-20 4:35am    
Use Improve question to update your question.
So that everyone can pay attention to this information.
wrtjs 6-Jun-20 4:33am    
this is the datafile:
Title: disease_num
1 A 12 8
1 B 22 10
1 C 15 12
1 D 14 9
2 A 12 8
2 B 21 10
2 C 15 12
2 D 14 9
3 A 12 8
3 B 20 10
3 C 15 12
3 D 14 9
4 A 12 8
4 B 17 10
4 C 15 12
4 D 14 9
5 A 12 8
5 B 20 10
5 C 15 12
5 D 14 9
6 A 12 8
6 B 15 10
6 C 15 12
6 D 14 9
7 A 12 8
7 B 17 10
7 C 27 12
7 D 12 18
8 A 12 8
8 B 20 10
8 C 15 12
8 D 14 9
9 A 12 8
9 B 12 10
9 C 15 12
9 D 13 9
10 A 12 8
10 B 14 10
10 C 15 12
10 D 14 9
11 A 12 8
11 B 20 10
11 C 15 12
11 D 14 9
12 A 12 20
12 B 21 10
12 C 15 12
12 D 14 9
13 A 12 8
13 B 17 10
13 C 15 12
13 D 14 9
14 A 12 8
14 B 16 10
14 C 15 12
14 D 14 9
Patrice T 6-Jun-20 4:51am    
Use Improve question to update your question.
So that everyone can pay attention to this information.
input too

It's going to depend on your inputs to a large extent, and we don't have any access to that file.

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. How you use it depends on your compiler system, but a quick Google for the name of your IDE and "debugger" should give you the info you need.


Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
 
Share this answer
 
The following code:
C++
for(int ro=0; ro<row;ro++)
{
    for(int col=0; col<column; col++)
    {
        if(col==2)
        {
            stringstream pos(data[ro][col]);
            int posCase = 0;
            pos >> posCase;
            totalPos += posCase;
        }
    }
}

could be simplified to:
C++
for(int ro=0; ro<row;ro++)
{
    stringstream pos(data[ro][2]); // only column 2 value is needed
    int posCase;
    pos >> posCase;
    totalPos += posCase;
}

However, that is only the one total. You need to add the total calculations for all the other cases.
 
Share this answer
 
Quote:
I'm not getting the output that I wanted, help me please

As far as I can see, your program do not try to calculate wanted values, or output them.
The help you want is us doing your homework.
When you have code trying to do the work, show the code and explain specific problems you encounter, then you will get help fixing the code.
 
Share this answer
 
What I would do is first define a structure to hold your data. It seems the data on each line is a day, district, positives, negatives but I am not sure about the first field since it's not used. One possible arrangement is
C++
struct Cases
{
    int positives;
    int negatives;
};
Then declare an array of them to use for each district. I would use a vector for this but I get the feeling you don't know about those yet. If you do then use one. If not then declare a size for this array also. Here is what that might look like :
C++
const int CaseArraySize = 31;  // one for each day of a month

typedef Cases MonthCases[ CaseArraySize ];  // array of data for each day

const int DistrictCount = 4;   // number of districts

// declare an array of data for each district

MonthCases   cases[ DistrictCount ] = { 0 };
Now you have an array of cases for each district over a month's time with one item per day. You can store district A's data in slot 0, district B's data in slot 1, etc... Assuming the first field is a day, it will be used as the index in each district's array. Days start at 1 but array indexes start at 0 so an offset of one will have to be applied to the day.

Now you have all the data you need defined. Next you need to read the file, line by line. For each line in the file you need to obtain the day, district, positive count, and negative count. I will NOT do this for you - you need to figure this out. There are lots of ways to do it and many sample of each on the internet. It involves parsing tokens so that is a helpful search phrase to use. Here is how you can save the data :
C++
districtCases[ district ][ day - 1 ].positives = positiveCount;
districtCases[ district ][ day - 1 ].negatives = negativeCount;
Now that all your data is defined and the data from the file is being stored, your next task is to analyze it. You have the logic for determining the maximum value and you will need something similar to get the negative. You might also want to define a structure to store the statistics for each district. It seems you need a count of positives, count of negatives, minimum number, maximum number, and average so declare a structure that holds all of those values and any other items you will need. It could be called DistrictData. Then write a function to traverse the data array for each district and analyze its data. Here's what a prototype for that might look like :
C++
void AnalyzeDistrictData( MonthCases cases[], DistrictData & distData )
{
}
and the logic to call it will look like this :
C++
DistrictData  data[ DistrictCount ] = { 0 };

for( int n = 0; n < DistrictCount; ++n )
{
    AnalyzeDistrictData( cases[ n ], data[ n ] );
}
The last thing to do will be to output the data in format specified. This will be a matter of displaying the data you obtained in AnalyzeDistrictData for each district in a loop that will be similar to the previous loop.

These are the steps I go through all the time. I find that if you first define all of the data needed it makes your job much easier. Then you can define the functions you need to process all the data and write the logic to do the processing. This is your homework so I am not going to do any more than this. I hope you have enough hints to finish the work. I recommend that you give all of this stuff a try. If you get stuck then ask another question and be sure to show all the code you are working with. Good luck.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900