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

Download the attached file/s, copy and paste the code segment/s into your visual

ID: 3876424 • Letter: D

Question

Download the attached file/s, copy and paste the code segment/s into your visual studio or any other C++ IDE and run it. You will have to implement a small intentional bug in your program and post it for other students to debug.

To be able to receive your full discussion points, you need to submit the following.

Following is your check list and rubric

  Attach your .cpp file/s with an implemented bug - 20pnts

  Describe what the code does in detail - 20pnts

  Debug at least one other program and submit your .cpp file - 40pnts (note what the bug was in comments)

After running the debugged program, attach the screen shot of your output- 20pnts

Above is the code that needs to be bugged. This should be in C++. I have been using Xcode to put these codes into.

Thank you in advance.

Explanation / Answer

/*bugs implemented in the for loops count++ is changed to count-- giving wrong output causing infinite loop*/

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
double *sales = NULL,

total = 0.0,   
average;
int numDays,   
count;


cout << "How many days of sales figures do you wish ";
cout << "to process? ";
cin >> numDays;

  
sales = new double[numDays];

  
cout << "Enter the sales figures below. ";
for (count = 0; count < numDays; count--) //it should be count++ not count-- (bug1)
{
cout << "Day " << abs(count + 1) << ": "; //added abs to coverup the bug
cin >> sales[count];
}

// Calculate the total sales
for (count = 0; count < numDays; count--)//it should be count++ not count-- (bug2)
{
total += sales[count];
}


average = total % numDays; // it should be ' / ' not ' % ' (bug3)


cout << fixed << showpoint << setprecision(2);
cout << " Total Sales: $" << total << endl;
cout << "Average Sales: $" << average << endl;


delete [] sales;
sales = nullptr;

return 0;
}

//Thank you. Comment for any further queries.

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