Question

Instructions: Create a program that will collect multiple receipts from multiple classrooms to accumulate total cookie...

Instructions: Create a program that will collect multiple receipts from multiple classrooms to accumulate total cookie sales.   Once all receipts have been processed, the program must show what classroom is won and the total amount of cookies they sold.

The classrooms that are participating are from the:

                2nd Floor: 201, 202, 203, 204, 205, 206, 207, 208

                3rd Floor: 301,302, 303, 304, 305, 306, 307, 308, 309

                4th Floor: 401, 402, 403, 404, 408, 409, 410

In total 24 classrooms.

Instructions for writing the program:

  • The program requires parallel arrays to complete.
  • You can populate the array either by allowing the user to enter the classroom numbers or by hard coding the classroom numbers in your array.
  • The program will then take in each receipt that was submitted by each classroom. Each classroom can have 1 or more receipt. Each receipt represent a cookie sale. For example, in classroom 401 a student sold 10 boxes of cookies.    The program should ask for the classroom and then the cookie sold per receipt. Remember, there can be many receipts by classroom and they can be entered any combination.
  • The cookies sold for each entry must be accumulated per classroom.
  • Once all receipts have been processed, the winning classroom and total must be displayed.
  • The program must be written in C….and it must be modularized. There should only be 2 parallel arrays.

MUST BE 2 arrays only

Homework Answers

Answer #1

C program for the problem is as follows:

#include<stdio.h>

int binarySearch(int arr[], int l, int r, int x) 
{ 
    if (r >= l) { 
        int mid = l + (r - l) / 2;
        if (arr[mid] == x) 
            return mid; 
        if (arr[mid] > x) 
            return binarySearch(arr, l, mid - 1, x); 
        return binarySearch(arr, mid + 1, r, x); 
    } 
    return -1; 
} 

int main()
{
    int hardArr[24]={201, 202, 203, 204, 205, 206, 207, 208, 301,302, 303, 304, 305, 306, 307, 308, 309, 401, 402, 403, 404, 408, 409, 410};
    int candies[24]={0};
    int classNo;
    while(1)
    {
        printf("Enter classroom number. (OR Enter -1 to exit.)");
        scanf("%d",&classNo);
        if(classNo==-1)
            break;
        int ind=binarySearch(hardArr,0,23,classNo);
        printf("Enter the number of cookies sold.");
        int cookies;
        scanf("%d",&cookies);
        candies[ind]+=cookies;
    }
    int maxCandy=0;
    int ind;
    for(int i=0;i<23;i++)
    {
        if(candies[i]>maxCandy)
        {    
            maxCandy=candies[i];
            ind=i;
        }
    }
    printf("Class Number %d has maximum number of Candies: %d",hardArr[ind],maxCandy);
    return 0;
}

Screenshots of a test input are:

Know the answer?
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
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT