Question

In: Computer Science

USING C PROGRAMMING ***CODE MUST BE MODULARIZED** Instructions: Create a program that will collect multiple receipts...

USING C PROGRAMMING

***CODE MUST BE MODULARIZED**

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:

  1. The program requires parallel arrays to complete.
  2. 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.
  3. 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.  
  4. The cookies sold for each entry must be accumulated per classroom.
  5. Once all receipts have been processed, the winning classroom and total must be displayed.
  6. The program must be written in C….and it must be modularized.

Solutions

Expert Solution

C code:

#include <stdio.h>

#define SIZE 24

// Function to return index of maximum value in the array
int findMaxIndex(int arr[], int n) {
    int idx = 0;
    for (int i = 0; i < n; i++) {
        if (arr[idx] < arr[i]) {
            idx = i;
        }
    }
    return idx;
}

// Function to return index of given classroom
int findClassroomIndex(int arr[], int n, int classroom) {
    for (int i = 0; i < n; i++) {
        if (arr[i] == classroom) {
            return i;
        }
    }
    return -1;  // Classroom not found
}

int main() {
    // Hard coded parallel arrays
    int classrooms[SIZE] = {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 cookiesSold[SIZE] = {0};
    int classroom, classroomIdx, cookies;
    // Get the classroom number
    printf("Enter a classroom number or -1 to exit: ");
    scanf("%d", &classroom);
    // Keep asking for classroom number till user enters -1
    while (classroom != -1) {
        // Find the index of classroom number
        classroomIdx = findClassroomIndex(classrooms, SIZE, classroom);
        // Get the number of cookies sold
        printf("Enter the number of cookies sold: ");
        scanf("%d", &cookies);
        // Add cookies sold to the corresponding classroom
        cookiesSold[classroomIdx] += cookies;
        // Get the classroom number
        printf("Enter a classroom number or -1 to exit: ");
        scanf("%d", &classroom);
    }
    // Find the index of classroom that sold the maximum cookies
    int maxIdx = findMaxIndex(cookiesSold, SIZE);
    int winningClassroom = classrooms[maxIdx];
    int totalCookies = cookiesSold[maxIdx];
    // Display the winning classroom
    printf("Class number %d won and sold a total of %d cookies\n", winningClassroom, totalCookies);
    return 0;
}

Sample output:

Kindly rate the answer and for any help just drop a comment


Related Solutions

Code in C Instructions For this programming assignment you are going to implement a simulation of...
Code in C Instructions For this programming assignment you are going to implement a simulation of Dijkstra’s solution to the Dining Philosophers problem using threads, locks, and condition variables. Dijkstra’s Solution Edsgar Dijkstra’s original solution to the Dining Philosophers problem used semaphores, but it can be adapted to use similar mechanisms: • Each philosopher is in one of three states: THINKING, HUNGRY, or EATING. • Every philosopher starts out in the THINKING state. • When a philosopher is ready to...
Create a C++ program using native C++ (STL is acceptable) that produces Huffman code for a...
Create a C++ program using native C++ (STL is acceptable) that produces Huffman code for a string of text entered by the user. Must accept all ASCII characters. Provide an explanation for how you got frequencies of characters, how you sorted them, and how you got codes.
Using (C programming language) Create a health monitoring program, that will ask user for their name,...
Using (C programming language) Create a health monitoring program, that will ask user for their name, age, gender, weight, height and other health related questions like blood pressure and etc. Based on the provided information, program will tell user BMI, blood pressure numbers if they fall in healthy range or not and etc. Suggestions can be made as what should be calorie intake per day and the amount of exercise based on user input data. User should be able to...
MUST BE PYTHON 3 Instructions: The following programming problem can be solved by a program that...
MUST BE PYTHON 3 Instructions: The following programming problem can be solved by a program that performs three basic tasks (Input Data, Process Data, Output Results) along with selection and repetition coding techniques. Problem Statement A finance company provides loans for motorcycles at different rates depending on how much the total loan amount is and how many payments will be made on the loan. Using the information in the table below, write a program that will calculate the monthly payment...
C++ Programming Create a C++ program program that exhibits polymorphism. This file will have three class...
C++ Programming Create a C++ program program that exhibits polymorphism. This file will have three class definitions, one base class and three derived classes. The derived classes will have an inheritance relationship (the “is a” relationship) with the base class. You will use base and derived classes. The base class will have at least one constructor, functions as necessary, and at least one data field. At least one function will be made virtual. Class members will be declared public and...
Class Instructions You will create a password verification program using C-strings and character testing. The user...
Class Instructions You will create a password verification program using C-strings and character testing. The user will enter a password as a C-string. (Character array). You must test that the password contains at least: One lowercase letter One uppercase letter One number (0-9) The password can contain no spaces You are to add one more requirement to the password. I need help in setting this program up. #include <iostream> #include <cctype> using namespace std; int main() { char input; cout...
I need to complete this C++ program. The instructions are in the comments inside the code...
I need to complete this C++ program. The instructions are in the comments inside the code below: ------------------------------------------------------------------------- Original string is: this is a secret! Encypted string is: uijt!jt!b!tfdsfu" Decrypted string is: this is a secret! //Encoding program //Pre-_____? //other necessary stuff here int main() { //create a string to encrypt using a char array cout<< "Original string is: "<<string<<endl; encrypt(string); cout<< "Encrypted string is: "<<string<<endl; decrypt(string); cout<<"Decrypted string is: "<<string<<endl; return 0; } void encrypt(char e[]) { //Write implementation...
Please complete the following code in C using the comments as instructions. Further instructions are below...
Please complete the following code in C using the comments as instructions. Further instructions are below the code. challenge.c // goal: print the environment variables to the file "env.txt", one per line // (If envp is NULL, the file should be empty, opening in write mode will do that.) // example: // inputs: // envp/environ = {"E1=2","E2=7",NULL} // outputs: // env.txt as a string would be "E1=2\nE2=7\n" // example: // inputs: // envp/environ = {NULL} or NULL // outputs: //...
This programming assignment will consist of a C++ program. Your program must compile correctly and produce...
This programming assignment will consist of a C++ program. Your program must compile correctly and produce the specified output. Please note that your programs should comply with the commenting and formatting described in the Required Program Development Best Practices document that has been discussed in class and is posted to the eLearning system. Please see this descriptive file on the eLearning system for more details. The name to use in the main configuration screen text box Name: [ ] in...
Please write variables and program plan(pseudocode) of this C++ programming code: #include <iostream> using namespace std;...
Please write variables and program plan(pseudocode) of this C++ programming code: #include <iostream> using namespace std; void leapYear(int x); int main() { int x; cout << "Enter a year: "; cin >> x; leapYear (x);   return 0; } void leapYear(int x ) {    if (x % 400 == 0)    {    cout << "This is a leap Year";}    else if    ((x % 4 == 0) && (x % 100 != 0))    {    cout <<...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT