Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C++, During November, certain WNY communities participated in a campaign redu

ID: 3574919 • Letter: I

Question

In C++,

During November, certain WNY communities participated in a campaign reduce the incidence of texting while driving.   During the month, public officials promoted the dangers of such texting. Furthermore, police departments of the communities vigilantly sought out drivers who were texting at the wheel and issued tickets.

To help state officials obtain and summarize the violation information, police departments documented their data over a 16 hour period, and they requested a program be developed to generate the following output :

                                           Summary report showing

                                                Texting violations

             

Start time -->

6:00 AM

10:00 AM

2:00 PM

6:00 PM

16 hr total

Lackawanna

0

2

2

2

6

West Senaca

1

2

3

4

10

Cowlesville

0

2

1

2

5

Hamburg

3

3

3

3

12

Orchard Park

2

2

2

3

9

Blasdell

1

2

2

3

8

Buffalo

1

2

2

3

8

Lancaster

2

3

3

5

13

Alden

1

1

3

3

8

East Aurora

1

1

1

1

4

Cheektowaga

2

2

3

4

11

Gardenville

2

2

3

3

10

Average

1.3

2.0

2.3

3.0

Highest : Lancaster with 13 violations

S         The program must contain a function called LoadData which reads and stores data in a two-dimensional

            array. The input records will contain the community name in the first positions. Also, note the community name does not contain any blank characters.

The rightmost column is the row sum of the values to the left. The average row at the bottom consists of column sums. The program must contain a function called OuputInfo which outputs data in a two-dimensional array.

Start time -->

6:00 AM

10:00 AM

2:00 PM

6:00 PM

16 hr total

Lackawanna

0

2

2

2

6

West Senaca

1

2

3

4

10

Cowlesville

0

2

1

2

5

Hamburg

3

3

3

3

12

Orchard Park

2

2

2

3

9

Blasdell

1

2

2

3

8

Buffalo

1

2

2

3

8

Lancaster

2

3

3

5

13

Alden

1

1

3

3

8

East Aurora

1

1

1

1

4

Cheektowaga

2

2

3

4

11

Gardenville

2

2

3

3

10

Average

1.3

2.0

2.3

3.0

Highest : Lancaster with 13 violations

Explanation / Answer

#include<iostream>
using namespace std;
void loadData(int a[][5],string b[][1])
{
   for(int i=0;i<12;i++) // used for loading the data
   {
       for(int j=0;j<4;j++)
       {
           cin>>b[i][0] >> a[i][j];
       }
   }
}


void average(int a[][5])
{ int sum=0;
   for(int i=0;i<4;i++) //calculating sum for bottom entry
   {
       for(int j=0;j<12;j++)
       {
           a[11][i]=a[11][i]+a[j][i];
          
       }
   }
}


void rightsum(int a[][5])
{
   for(int i=0;i<12;i++)
   { a[i][4]=0;
       for(int j=0;j<4;j++) //calculating right sum
       {
           a[i][4]=a[i][4]+a[i][j];
       }
   }
}

void display(string b[][1],int a[][5])
{
   for(int i=0;i<13;i++)
   { int count=0;
       for(int j=0;j<5;j++)
       {
           if(count==0)
           {
               cout << b[i][0] <<" ";
               count++;
           }
           cout << a[i][j]<<" ";
       }
       cout << endl;
   }
}
int main()
{
   int a[13][5];
   string b[13][1];
   loadData(a,b); //call loaddata
   average(a);
  
   rightsum(a);
  
  
   for(int i=0;i<4;i++)
   {
       a[12][i]=(float)a[12][i]/12;
   }
   b[12][0]="average;
   display(b,a);
  
}