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

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...
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...
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...
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...
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 <<...
In C Programming Create a payroll program to store and calculate the payroll for a small...
In C Programming Create a payroll program to store and calculate the payroll for a small company as follows: Ask the user for the number of employees and only accept the number if it is between 5 and 40 employees, otherwise prompt the user again and test the input, keep repeating until the user enters an acceptable number. Create an array of floats that is 4 rows and an number of columns equal to the number of employees in the...
MUST BE DONE IN C (NOT C++) Your create a program that can implement the cases...
MUST BE DONE IN C (NOT C++) Your create a program that can implement the cases in which the initial unit is Fahrenheit or something not recognizable. Your program should incorporate Fahrenheit to Celsius, Fahrenheit to Kelvin and unknown initial units (display an error message for this last one). You must use functions to calculate Fahrenheit degrees.
Programming language: C++   suggested software: Code::Blocks Develop an algorithm and write a C++ program that computes...
Programming language: C++   suggested software: Code::Blocks Develop an algorithm and write a C++ program that computes the final score of a baseball game. Use a loop to read the number of runs scored by both teams during each of nine innings. Display the final score afterward. Submit your design, code, and execution result via file, if possible
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT