Question

In: Computer Science

The U-Mart Supermarket is a convenience store company that has five store located in different location...

The U-Mart Supermarket is a convenience store company that has five store located in different location at UTM Skudai. At the end of each year, the management of the UTM wants to know the performance of the company. They have decided to use a computer program to help them in analyzing the company performance based on the total sales of each quarter in all stores. Develop a C program to perform this task using array and function based one following requirements.

Input:

The program should read in sales data from a text file.
The format of the input file for each line/record is as follows:
first number is for the store branch code,

second number is the sales of the first quarter ,

third number is the sales of the second quarter,

fourth number is the sales of the o third quarter,

fifth number is the sales of the fourth quarter.

The following is an example of input file named “sales2015.txt” containing sales data for the year 2019 for five stores.
11 940.80 490.10 960.60 670.50

12 710.90 570.30 170.60 310.60

13 360.70 160.30 300.60 870.60

14 480.50 490.40 910.70 720.55

15 340.30 320.30 140.60 570.70

Arrays:

The program should use array(s) to store the sales data

Functions:

The program should have the following functions:

float highest_Sale(). This function should accept arrays (representing sales) as one of its parameters. It should determine the indices of row and column of a cell in the array
which has the highest sales.
void grandTotal_each_store(). This function should return the grand total of sales for each stores throughout the year. It should accept array (representing sales) as its parameters.
void Total_each_quarter(). This function should accept arrays and the index of a column in the array (representing a quarter) as its parameters. The function should return the total sales for the each quarter.

Output:

The program should print out a report into a text file named “report.txt”.
The report should include:
- The grand total of sales, over all stores sales, throughout the year.

- The highest sales of all quarter. Print the store code and the highest sales.

- The total sales for each quarter of all store.

The following diagram is example of output file based on the input given.
EXPECTED OUTPUT

Grand total of sales over all stores: RM xxxxx.xx

The highest quarter sales:

Store Code: 11

Quarter : 3

Sales: RM 960.60

Total sales by quarter:

Quarter Sales

----------- --------------

Quarter 1 RM 4474.10

Quarter 2 RM xxxx.xx

Quarter 3 RM xxxx.xx

Quarter 4 RM xxxx.xx

Solutions

Expert Solution

#include<stdio.h>
#define MAX 100

int read_detail (float details[][5])
{
   FILE *f1;
   f1= fopen("sales2015.txt","r");
   if(f1==NULL)
   {
       printf("Error!");
   }
   int i=0;
   while(!feof(f1))
   {
       fscanf(f1,"%f",&details[i][0]);
       fscanf(f1,"%f",&details[i][1]);
       fscanf(f1,"%f",&details[i][2]);
       fscanf(f1,"%f",&details[i][3]);
       fscanf(f1,"%f",&details[i][4]);
       printf("%f %f %f %f %f\n",details[i][0],details[i][1],details[i][2],details[i][3],details[i][4]);
       i++;
   }
   return i;
}

float highest_Sale(float details[][5],int size,int *row, int *column)
{
   float max = details[0][1];
   *row = 0;
   *column = 1;
   int i;
   for(i=0;i<size;i++)
   {
       int j;
       for(j=1;j<5;j++)
       {
           if(details[i][j]>max)
           {
               max =details[i][j];
               *row = i;
               *column = j;
           }
       }
   }
   return max;
}

void Total_each_quarter(float details[][5],float tot[],int size,int column)
{
   int i;
   tot[column]=0;
   for(i=0;i<size;i++)
   {
       tot[column]+=details[i][column+1];
   }
}

float tot_sale(float tot[],int size)
{
   float total = 0;
   int i;
   for(i=0;i<size;i++)
   {
       total+= tot[i];  
   }
   return total;
}

void Output(float details[][5],float tot[],int size,int row,int col)
{
   FILE *f1;
   f1= fopen("report.txt","w");
   fprintf(f1,"Grand total of sales over all stores: RM %.2f\n", tot_sale(tot,size));
   fprintf(f1,"The highest quarter sales:\n");
   fprintf(f1,"Store Code: %.0f\n",details[0][row] );
   fprintf(f1,"Quarter : %d\n",col);
   fprintf(f1,"Sales: RM %.2f\n",details[row][col]);

   fprintf(f1,"Total sales by quarter:\n");
   fprintf(f1,"Quarter Sales\n");
   fprintf(f1,"----------- --------------\n");
   int i;
   for(i=0;i<4;i++)
   {
       fprintf(f1,"Quarter %d RM %.2f\n",i+1,tot[i]);
   }
   fclose(f1);
}

int main()
{
   float details[MAX][5],tot[MAX];
   int size,row,column;
   size = read_detail(details);
   highest_Sale(details,size,&row,&column);
   int i;
   for(i=0;i<4;i++)
   {
       Total_each_quarter(details,tot,size,i);
   }
   Output(details,tot,size,row,column);
}

//Output


Related Solutions

GoGo Juice is a combination gas station and convenience store located at a busy intersection. Recently,...
GoGo Juice is a combination gas station and convenience store located at a busy intersection. Recently, a national chain opened a similar store only a block away; consequently, sales have decreased for GoGo. In an effort to reclaim lost sales, GoGo has implemented a promotional effort; for every $10 purchase at GoGo, the customer receives a $1 coupon that can be redeemed toward the purchase of gasoline. The average gasoline customer purchases 15 gallons of gasoline at $2.50 per gallon....
A man sued a supermarket because he fell in the store. The supermarket company used its...
A man sued a supermarket because he fell in the store. The supermarket company used its customer database to show that the man regularly bought a lot of alcoholic beverages. 1. What is the term that describes this kind of use of information? How likely is it that supermarket lawyers would have gotten this information before supermarket cards were used to record purchases? (Why?)
This problem has parts a) - d). a) A convenience store recently started to carry a...
This problem has parts a) - d). a) A convenience store recently started to carry a new brand of soft drink. Management is interested in estimating future sales volume to determine whether it should continue to carry the new brand or replace it with another brand. The following table provides the number of cans sold per week. Use both the trend projection with regression and the exponential smoothing​ (let alpha α equals=0.40.4 with an initial forecast for week 1 of...
A store sells three different clothing designs and has recorded sales of each over five different...
A store sells three different clothing designs and has recorded sales of each over five different 24-hour periods: Design A         Design B         Design C      16                    33                    23      18                    31                    27      19                    37                    21      17                    29                    28      13                    34                    25 Use the Kruskal-Wallis H test and the Chi-Square table at the 0.05 level to compare the three designs.
A store sells three different clothing designs and has recorded sales of each over five different...
A store sells three different clothing designs and has recorded sales of each over five different 24-hour periods: Design A         Design B            Design C      16                    33                    23      18                    31                    27      19                    37                    21      17                    29                    28      13                    34                    25 Use the Kruskal-Wallis H test and the Chi-Square table at the 0.05 level to compare the three designs.
Part B: New Location Rhonda has found a location for the next store she plans to...
Part B: New Location Rhonda has found a location for the next store she plans to open. The store front will require $30,000 in renovations before it is ready to open. She would like the initial investment to be paid off in 5 years. Assuming a discount rate of 4.5%, what will her annual profits for the store need to be if she wishes to recover the $30,000 in 5 years (assuming equal profits each year)? What if the discount...
The retailing manager of a supermarket chain wants to determine whether product location has any effect...
The retailing manager of a supermarket chain wants to determine whether product location has any effect on the sale of pet toys. Three different aisle locations are considered: front, middle, and rear. A random sample of 18 stores is selected with 6 stores randomly assigned to each aisle location. The size of the display area and price of the product are constant for all stores. At the end of a 1-month trial period, the sales volumes (in thousands of dollars)...
The StamfordStamford store of Gabriel's CornerGabriel's Corner , a chain of small neighborhood convenience stores, has...
The StamfordStamford store of Gabriel's CornerGabriel's Corner , a chain of small neighborhood convenience stores, has a Kaizen (continuous improvement) approach to budgeting monthly activity costs for each month of 20152015. Gabriel's CornerGabriel's Corner has three product categories: soft drinks (35% of cost of goods sold [COGS]), fresh snacks (25% of COGS), and packaged food (40% of COGS). The following table shows the four activities that consume indirect resources at the StamfordStamford store, the cost drivers and their rates, and...
Determine the treatment of each of the following items: Y-Mart Store has a policy of refunding...
Determine the treatment of each of the following items: Y-Mart Store has a policy of refunding purchases by dissatisfied customers, even though it is under no legal obligation to do so. Its policy of making refunds is generally known. Fly With Me Ltd commenced operating a low budget airline two years ago. The law requires airlines to overhaul its aircraft once every three years. At the end of the reporting period, a number of the airlines planes have been in...
Impairment Dexter Company purchased four convenience store buildings on January 1, 2011, for a total of...
Impairment Dexter Company purchased four convenience store buildings on January 1, 2011, for a total of $26,000,000. The buildings have been depreciated using the straight- line method with a 20-year useful life and 5% residual value. As of January 1, 2017, Dexter has converted the buildings into Internet Learning Centers where classes on Internet usage will be conducted six days a week. Because of the change in the use of the buildings, Dexter is evaluating the buildings for possible impairment....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT