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

MY QUESTION: In c++ programming can you edit this program to satisfy these requi

ID: 3732404 • Letter: M

Question

MY QUESTION: In c++ programming can you edit this program to satisfy these requirements:

THE PROGRAM THAT NEEDS EDITING:

CS1336: Programming Fundamentals Spring 2018 Assignment #7 This programming assignment consists of one C++ program. It should compile correctly and produce the specified output. Give meaningful name to the program and submit it to eLearning. Please note that the program should comply with the commenting and formatting rules we discussed in class. Program # 1 This assignment is similar to the assignment #6 with some modifications. Instead of calculating average, minimum, and maximum in the main0 function, you need write three separate functions to calculate them. The prototypes of the three function are as follows. int cale min(string file_name, int total num); /l returns min of integers in file _name int calc max(string file name, int total num); // returns max of integers in file name int calc avg(string file_name, int total _num); // returns average of integers in file_name The parameter file_name is the name of the file that contains the integers. The total_num contains the total number of integers in the file. In the main0 function, prompt the user to input both the file name containing the integers, and the total number of integers in the file. Then call the three functions (with appropriate arguments) to calculate average, min, and max and output the value returned by the function To open the file, use infile.open( file_name.c_strO) where infile is an object of type ifstream. Please submit your source code to eLearning.

Explanation / Answer

#include <iostream>
#include <fstream>

using namespace std;

int cal_min(char* filenumbers, int n){
   int number[100];
   int a = 0;
   ifstream filein(filenumbers);
    if (!filein) {
        cout << "Please enter a a correct file to read in the numbers from";
    }
    while (!filein.eof()) {
        filein >> number[a];
        a++;
    }
    int minimum = number[0];
    for (a = 0; a < n; a++) {
        if (minimum > number[a]) {
            minimum = number[a];
        }
    }
    return minimum;
}

int cal_max(char* filenumbers, int n){
   int number[100];
   int a = 0;
   ifstream filein(filenumbers);
    if (!filein) {
        cout << "Please enter a a correct file to read in the numbers from";
    }
    while (!filein.eof()) {
        filein >> number[a];
        a++;
    }
    int maximum = number[0];
    for (a = 0; a < n; a++) {
        if (maximum < number[a]) {
            maximum = number[a];
        }
    }
    return maximum;
}

int cal_avg(char* filenumbers, int n){
   int number[100];
   int a = 0;
   ifstream filein(filenumbers);
    if (!filein) {
        cout << "Please enter a a correct file to read in the numbers from";
    }
    while (!filein.eof()) {
        filein >> number[a];
        a++;
    }
    int total = number[0];
    for (a = 0; a < n; a++) {
        total = total + number[a];
    }
    return total/n;
}

int main()
{
    float average = 0;
    int total = 0;
    char filenumbers[100];
    int maximum;
    int minimum;
    cout << "Enter the name of the file that you will read the numbers from:" << endl;
    cin >> filenumbers;
    cout << "The average of the 100 numbers is " << cal_avg(filenumbers,100) << endl;
    cout << "The minimum of the 100 numbers is " << cal_min(filenumbers,100) << endl;
    cout << "The maximum of the 100 numbers is " << cal_max(filenumbers,100) << endl;
    return 0;
}

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