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

A company with three stores, A, B, and C,has collected the total dollar amount o

ID: 3547960 • Letter: A

Question

A company with three stores, A, B, and C,has collected the total dollar amount of sales each store for each

month of the year. These numbers are stored in a file, sales.txt, that has the information for January, then

February, and so on.

Within each month, the sales amount for store A is first, then store B, then store C. The company pays each

store a $1,000 bonus if its sales exceed $30,000 in any particular month.

a. Write a function, bonus(), that has one parameter, a matrix (2-D array) of float values. It returns an

integer to the caller. In this function, search through the sales matrix, starting at the first month for the

first store. Test each value in the matrix to see if the sales amount qualifies for a bonus. If it does, print

the store name and month corresponding to the row and column, as well as the sales amount. Count

and return the number of bonuses given. If no amount qualifies for a bonus, return 0.

b. Write another function, read_file(), that will read in the data from the sales file and store the amount in

a matrix where each row represents a store the amounts in a matrix where each row represents a store

and each column represents a month.

c. Finally, write a main function that first calls read_file() to reads in all the data, then prints the sales

amounts and total sales for each store in a neat table, with all of store A's sales first, followed by those

store B, and finally those of store C.

Last, call the bonus() function to determine the bonuses for the year. Write the total sales amount, the number

of bonuses awarded, and the amount of bonuses money that the company will give out to a file, bonus.txt.

For example,

Total Sales Amount = $10,000,000

Total Number of Bonus Awarded = 2

The Amount of Bonuses = $2,000

Explanation / Answer

#include<stdio.h>
char *month_names[] = {"January","February","March","April","May","June","July","August","September","October","November","December"};
int    bonus(float sales_array[12][3])
{
int month_index;
int store_index;
int no_of_bonuses = 0;
for(month_index = 0; month_index<12; month_index++)
{
for(store_index = 0; store_index<3; store_index++)
{
if(sales_array[month_index][store_index]>30000)
{
no_of_bonuses++;
printf(" Store Name is %c got bonus in month %s and its sales amount is %f",(char)(store_index+'A'),month_names[month_index],sales_array[month_index][store_index]-1000);
}
} //end store index loop
} //end month index loop
return no_of_bonuses;
} // end bonus file.
void read_file(float sales_array[12][3])
{
FILE *fp= NULL;
fp = fopen("input.txt", "r");
int month_index=0;
int store_index=0;
if( fp != NULL )
{
while ( !feof(fp ) )
{
    fscanf(fp,"%f %f %f",&sales_array[month_index][0],&sales_array[month_index][1],&sales_array[month_index][2]);
    for(store_index=0; store_index<3; store_index++)
    {
    if(sales_array[month_index][store_index]>30000)
    sales_array[month_index][store_index] = sales_array[month_index][store_index] + 1000;
    }
    month_index++;
}
fclose(fp);
}
}
int main()
{
float sales_array[12][3];
FILE* foutp = fopen("bonus.txt","w");
float total_sales[3];
int month_index = 0;
int store_index = 0;
int no_of_bonuses = 0;
read_file(sales_array);
for(store_index = 0; store_index<3; store_index++)
{
printf(" Store %c information is ",(char)(store_index+'A'));
for(month_index = 0; month_index<12; month_index++)
{
total_sales[store_index] = total_sales[store_index] + sales_array[month_index][store_index];
printf(" Sales for month %s is %f",month_names[month_index],sales_array[month_index][store_index]);
}
printf(" Store %c total Sales is %f",(char)(store_index+'A'),total_sales[store_index]);
}
no_of_bonuses = bonus(sales_array);
fprintf(foutp,"Total Sales Amount = $ %f",total_sales[0]+total_sales[1]+total_sales[2]);
fprintf(foutp,"Total Number of Bonus Awarded = %d",no_of_bonuses);
fprintf(foutp,"The Amount of Bonuses = $ %d",no_of_bonuses*1000);
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote