Answer to Question #256039 in C++ for zain

Question #256039

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”




1
Expert's answer
2021-10-24T13:53:29-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS