Question

In: Computer Science

C++ language There are 100 integers in the inputfile.txt. Read each integer in the inputfile.txt and...

C++ language

There are 100 integers in the inputfile.txt. Read each integer in the inputfile.txt and store each one in the array named myArray. After that, complete the code in the function printArray(...) to output the elements in the array with the following format:

  • - Each output line should consist of 10 integers

  • - Each integer should be separated by | The output should be exactly as shown

  • Array contains the following elements 12 | 32 | 34 | 56 | 78 | 21 | 14 | 19 | 92 | 14 | 67 | 83 | 95 | 70 | 24 | 29 | 58 | 34 | 69 | 32 | 42 | 73 | 24 | 26 | 32 | 90 | 32 | 37 | 19 | 77 | 26 | 62 | 31 | 84 | 51 | 54 | 19 | 33 | 59 | 31 | 86 | 54 | 93 | 46 | 52 | 44 | 79 | 69 | 42 | 64 | 14 | 34 | 15 | 89 | 34 | 76 | 10 | 44 | 53 | 81 | 16 | 83 | 85 | 77 | 56 | 10 | 43 | 11 | 88 | 15 | 67 | 94 | 61 | 26 | 95 | 41 | 28 | 91 | 31 | 94 | 29 | 77 | 32 | 58 | 32 | 35 | 72 | 69 | 75 | 56 | 12 | 99 | 59 | 71 | 90 | 47 | 70 | 71 | 16 | 64 |

then find the minimum and the maximum elements in the array

Complete the code to find the min and max values of all the integers in myArray. The output should look exactly as shown:

The min value of the elements in the array is : 10
The max value of the elements in the array is : 99

Solutions

Expert Solution

Code:

#include<iostream>
#include<fstream>

using namespace std;
void printarray(int a[]){
   for (int i = 0; i < 100; i++){
       cout << a[i]<<"|" ;
       if((i+1)%10==0)                 //printing array
           cout<<endl;
   }
}

int main() {
   ifstream j;
   j.open("list.txt");       //you give your file name here with 100 numbers by space or newline
   int arr[100],k=0,i;
   while (j >> arr[k]){
       k=k+1;                       //reading integers from file.
   }
   j.close();
   printarray(arr);             //calling function printarray
   int max=-1,min=1000000000;
   for(i=0;i<100;i++){
       if(min>=arr[i]){            //finding minmum element in array.
           min=arr[i];
       }
   }
   for(i=0;i<100;i++){
       if(max<=arr[i]){           //finding maximum element in array.
           max=arr[i];
       }
   }
cout<<"The min value of the elements in the array is :"<<min<<endl;
cout<<"The max value of the elements in the array is :"<<max;

}

Output:

12 32 34 56 78 21 141992 14 67|83|95|70|24|29|58|34|69|32| 42|73|24|26|32|90|32|37|19|77| 26|62|31|84|51|54|19|33|59|31| 86|5493|46|52|44|79|69|42|64| 14|34|15|89|34|76|10|44|53|81| 16|83|85|77|56|10|43|11|88|15|| 67|94|61|26|95|41|28|91|31|94|| 29|77|32|58|32|35|72|69|75|56|| 12|99|59|71|90|47|70|71|16|64|| The min value of the elements in the array is :10 The max value of the elements in the array is :99


Related Solutions

Write a program that uses a loop to read 10 integers from the user. Each integer...
Write a program that uses a loop to read 10 integers from the user. Each integer will be in the range from -100 to 100. After all 10 integers have been read, output the largest and smallest values that were entered, each on its own line in that order. Avoiding using the max or min functions from Python, and definitely use a loop to read the integers instead of 10 input statements.
Use MIPS assembly language program to swap two of the integers in an integer array. The...
Use MIPS assembly language program to swap two of the integers in an integer array. The program should include the Swap function to swap the integers and the main function to call the Swap function. The main function should: • Pass the starting address of the array in $a0. • Pass the indices of the two elements to swap in $a1 and $a2. • Preserve (i.e. push onto the stack) any T registers that it uses. • Call the Swap...
IN C LANGUAGE This program reads a threshold, a size, and an array of integers. The...
IN C LANGUAGE This program reads a threshold, a size, and an array of integers. The program then calls the foo function. The function will modify the array x of size n by doubling any values in x that are less than the threshold. The function will count how many values were changed and how many were not changed via two reference parameters. The function signature is: void foo(int n, int x[], int threshold, int *pChanged, int *pUnchanged); The function...
Write a MIPS assembly language program to read an arbitrary number of integer pairs from a...
Write a MIPS assembly language program to read an arbitrary number of integer pairs from a file. Each pair will then be multiplied together with the results being accumulated (added together) forming a sum-of-products operation. Submit your report and code here.
in C++ programing language Write a program that prompts the user for an integer, then prints...
in C++ programing language Write a program that prompts the user for an integer, then prints all of the numbers from one to that integer, separated by spaces. Use a loop to print the numbers. But for multiples of three, print "Fizz" instead of the number, and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz". Drop to a new line after printing each 20 numbers. If the user typed...
Write a code fragment in C language that tests the value of an integer num1. If...
Write a code fragment in C language that tests the value of an integer num1. If the value is 10, square num1. If it is 9, read a new value into num1. If it is 2 or 3, multiply num1 by 99 and print out the result. Implement your code using SWITCH statements
Write a MIPS Assembly Language program to perform the following operations: Request and read two integers...
Write a MIPS Assembly Language program to perform the following operations: Request and read two integers from the console (Dn and Up), Call a recursive function to compute the result int RecurseFunc( int Dn, int Up ) { if( Dn < 1 ) return 0; return Dn * Up + RecurseFunc( Dn - 1, Up + 1 ); } Print out the results
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product and quotient without using the multiplication and division instructions. Each input number will be entered on a separate line. Your program will terminate when two zeroes are entered by the user. If only the second number in a pair is zero, then a divide-by-zero error message should be printed for the division operation. Use comments generously in your program. Test your program with the...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product and quotient without using the multiplication and division instructions. Each input number will be entered on a separate line. Your program will terminate when two zeroes are entered by the user. If only the second number in a pair is zero, then a divide-by-zero error message should be printed for the division operation. Use comments generously in your program. Test your program with the...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product and quotient without using the multiplication and division instructions. Each input number will be entered on a separate line. Your program will terminate when two zeroes are entered by the user. If only the second number in a pair is zero, then a divide-by-zero error message should be printed for the division operation. Use comments generously in your program. Test your program with the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT