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

How would answer question #4 of this ? #1 and 2 #include<iostream> #include <fst

ID: 3830046 • Letter: H

Question

How would answer question #4 of this ?

#1 and 2

#include<iostream>
#include <fstream>

using namespace std;

void read(int arr[])
{
   string line;
   ifstream myfile("input.txt");
   int i = 0;
   if (myfile.is_open())
   {
       while (getline(myfile, line))
       {
           arr[i];
           i++;
       }
       myfile.close();
   }
}
void output(int arr[])
{
   ofstream myfile("output.txt");
   if (myfile.is_open())
   {
       int i = 0;
       int k = 0;
       while (i<10)
       {
           myfile << arr[k] << " ";
           k++;
           i++;
       }

       myfile.close();
   }
}
int main(int argc, char argv[])
{
   int arr[100];
   read(arr);
   output(arr);
   return 0;
}

#3

int indexLargestElement(int[] arr)
{

   int maxIndex = 0;

   for (int i = 1; i<arr.length; i++) {

       if (arr[maxIndex] < arr[i])

           maxIndex = i;

   }

   return maxIndex;

}

int indexSmallestElement(int[] arr)
{

   int minIndex = 0;

   for (int i = 1; i<arr.length; i++) {

       if (arr[minIndex] > arr[i])

           minIndex = i;

   }

   return minIndex;

}

Write a function to read into an array all the integers in an input file of unknown size. When the function ends, the calling program has the array filled with values and a variable whose value is the actual number of elements read in. Write a function to output all the integers in an array to an output file, with 10 values per line. Values on a line are separated by a single space. Write a function similar to the function indexLargestElement (page 535 in Example 8-6) except that this function is called indexSmallestElement and it returns the index of the minimum value found in an array. Write a complete C++ program which includes both functions 1, and 2, above, as well as indexLargestElement and indexSmallestElement The main program will declare variables and call functions to get array input, find and output to a file the maximum value in the array, find and output to the file the minimum value in the array, and output all the values in the array. Output will have appropriate labels.

Explanation / Answer

#include <iostream>

void read(int arr[]);

void output(int arr[]);

int indexLargestElement(int arr[]);

int indexSmallestElement(int arr[]);

int main()

{

int arr[100],n,choice;

cout<<"enter size of Array";

cin>>n;

do

{

cout<<" MENU";

cout<<" 1.Accept elements of array";

cout<< 2.output to a file

cout<< 3.output maximun element to a file

cout << 4.output mininum element to a file

cout<< 5.exit

cout<<" enter your choice 1-5:";

cin>>choice;

switch(choice)

{

case 1:read(arr);

break;

case 2:output(arr);

break;

case 3: int x;

x=indexLargestElement(arr);

ofstrean myfile2;

myfile2.open(outputmax.txt);

myfile2<<x;

myfile.close;

break;

case 4 :int x;

x=indexSmallestElement(arr);

ofstream myfile2

myfile2.open(outputmin.txt);

myfile2<<x;

myfile2.close;

break;

case 5:break.

defult:cout<<"invalid choice";

}

} while(choice!=5);

return 0;

}

// write your functions here.....

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