00:01
In this question, we have to find out the total sales, that is the program output for total sales, then average sales, then lowest and highest sales.
00:27
So, these outputs we have to find out and the algorithm or the steps that are there, that are mentioned to us in the question mostly, that we have to read data from file into an array and then we have to process the data partially, filled array via functions.
00:55
So, we will follow those steps and we will see how to write this code in c+ + in a basic compiler.
01:04
For that, let us move to a basic compiler and begin the code.
01:09
The first thing that we are going to do is we are going to include the header files that are there, as you can see.
01:16
So, these files, that is iostream library, is used for input and output operations.
01:22
Then fstream is used for file handling and iomanip, as you can see, that is the third header file, it is used for formatting output.
01:31
So, now let us define a constant for the maximum number of locations.
01:36
So, for that, we will include a constant like this for maximum number of locations, as you can see.
01:44
So, it represents the maximum capacity of the sales data array, that is 20, as you can see.
01:49
So, now let us find some function prototypes.
01:54
For that, we will write certain lines like this.
02:01
So, these are the function prototypes that we have added.
02:04
So, these are for the functions that will be defined later in the code.
02:09
So, we will see that.
02:11
So, functions to read the sales from sales data, that is there from a file, we have to initiate such a readsaledata function also.
02:21
So, we did the same here.
02:25
So, this function takes array scales and a file name as input.
02:31
It opens the file, reads the number of location from the file and fills the array with the sales data.
02:37
So, it returns the number of locations that are there, that are locations read from the file.
02:43
So, now we have to write a function to calculate the total sales.
02:47
So, for that, we will write this function.
02:53
So, this function will calculate the total sales, as you can see.
02:58
So, it takes the array of scales and the number of locations as input.
03:03
It iterates over the sales data and calculates the total sales.
03:08
So, it then returns the total sales amount, as you can see.
03:12
So, now what we have to do, we have to function, we have to write a function to calculate the average sales that are there.
03:20
So, in the same way, the way we calculated the total sales, we will calculate the average sales.
03:28
So, this function takes the array of scales and number of locations as input.
03:33
Then it calls the calculate total sales function that we have defined earlier over here to get the total sales and then calculates the average sales by dividing the total sales by the number of locations.
03:45
So, it returns the average sales amount in the end.
03:48
Now, function to find the highest sales is given over here, as you can see.
03:55
So, this is for finding highest sales.
03:57
Now, here, this function takes the array of scales and the number of locations as input.
04:03
Then it initializes the highest sales variable with the first sales value.
04:08
And then it rates over the sales data to find the highest sales amount.
04:12
So, it returns the highest sales amount in the end.
04:16
Then we have to find the lowest sales.
04:18
For that, we'll take find lowest sales function.
04:24
So, this function takes the array of scales and number of locations as input.
04:29
Then it initializes the lowest sales available with the first sales value.
04:34
And it rates over the sales data to find the lowest sales amount.
04:38
So, then it returns the lowest sales amount in the end.
04:42
So, function to sort the sales data in ascending order, for that, we have to use bubble sort...