1. Create a function that would help you compute the average expense of car fueling in a month. It would take as an input number of times in a month that you have refueled. Create a dynamic array of the given size. Then you would be required to input that may times the amount used to refuel and store values in this dynamic array. Now compute the .using in c++.
a. average of these cost
b. most expensive refueling
c. Least expensive refueling.
2. Overload the function from 1 to read the number of entries in a file. Create a dynamic array of the given size. Then you would be required to input that may times the amount used to refuel and store values in this dynamic array. Now compute the
a. average of these cost
b. most expensive refueling
c. Least expensive refueling.
3. Write back results from 1 in the file “manual_input.txt”
4. Write back results from 2 in the file “automated_input.txt”
#include <iostream>
using namespace std;
int fuelRefill(int n, int k, int m, int compulsory[])
{
int cnt = 0;
int i = 0;
int distance = 0;
while (distance < n)
{
if (i < m && compulsory[i] <= (distance + k))
{
distance = compulsory[i];
i++;
}
else
distance += k;
if (distance < n)
cnt++;
}
return cnt;
}
int main()
{
int n = 21;
int k = 7;
int m = 5;
int required[] = {6, 7, 8};
cout << fuelRefill(n, k, m, required) << endl;
return 0;
}
Comments
Leave a comment