Answer:
see explaination
Step-by-step explanation:
#include<iostream>
using namespace std;
#define MAXDAS 100
int main()
{
//int MAXADS = 100;
int adcatcode[MAXDAS];
int adwords[MAXDAS];
int curCode;
int numads;
int i,j,k;
int subtotal;
int temp;
cout<<"Please enter the number of ads: ";
cin>>numads;
if((numads > 0) and (numads <= MAXDAS))
{
for (i = 0;i<numads;i++)
{
cout<<"Please enter Advertisement Category Code (1 - 15): ";
cin>>adcatcode[i];
cout<<"Please enter number of words for the advertisement: ";
cin>>adwords[i];
}
for (i=0;i<numads-1;i++)
{
for (j = 0;j<numads-1;j++)
{
if (adcatcode[j] > adcatcode[j+1])
{
temp = adcatcode[j];
adcatcode[j] = adcatcode[j+1];
adcatcode[j+1] = temp;
temp = adwords[j];
adwords[j] = adwords[j+1];
adwords[j+1] = temp;
}
}
}
cout<<"Total Word Counts Sorted By Category Code"<<endl;
cout<<"========================================="<<endl;
k = 0;
while(k<=numads-1)
{
subtotal = 0;
curCode = adcatcode[k];
while ( (curCode == adcatcode[k])&& (k <= numads - 1) )
{
subtotal = subtotal + adwords[k];
k = k + 1;
}
cout<<"Category: "<<adcatcode[k - 1]<<" "<<"Word Count: "<<subtotal<<endl;
}
}
else
{
cout<<"Number adds requested less than 1 or is too large; ad limit is :"<<MAXDAS;
}
return 0;
}
See attachment for output