In: Computer Science
Need in C# with the exact style of output listed.
Assignment7A: A new field of computer science: Small Data. Big Data is a really hot area in computing right now and there are tons of jobs in it. Here in FYE, we care more about the field of Small Data, because if you can work with small data, you can extend that to working with big data. For this assignment, you’re going to implement the most common operations on arrays. Specifically, initializing them, printing them, finding the min, finding the max, and finding the sum. These are used all the time, so our recommendation is to understand how to solve the underlying problem and use that as a model for solving harder problems. Write a program that creates an array of 100 integers. I would recommend “pre-initializing” each cell to either 0 or -1 before doing anything else because it will make things easier later. After that, you should write separate (static) functions for initializing the array (from user input - according to the behavior below), printing the array (according to the behavior below – only values that have been entered by the user), finding the minimum element of the array, finding the maximum element of the array, and finding the sum of all elements of the array. Assume that the values the user enters are between 0 – 99. Hint: a very convenient thing would be if your initialization function returned the number of elements the user typed in.
Sample Output #1:
Enter a number or -1 to finish: 6
Enter a number or -1 to finish: 9
Enter a number or -1 to finish: 3
Enter a number or -1 to finish: 1
Enter a number or -1 to finish: 9
Enter a number or -1 to finish: 76
Enter a number or -1 to finish: 42
Enter a number or -1 to finish: 1
Enter a number or -1 to finish: -1
|6|9|3|1|9|76|42|1|
Min is: 1
Max is: 76
Sum is: 147
Explanation:
Code in C#:
using System;
class FYEArray {
public static void Main (string[] args) {
/**
* Creating an integer type array named data[]
* of size 100
*/
int[] data = new int[100];
/**
* Initializing the array data[] with -1 value
*/
for(int i=0;i<data.Length;i++){
data[i] = -1;
}
/**
* Now we will call the initializeArray() method and pass array data[]
* as parameter. The function returns the number of values entered by user.
* We will store that in integer variable named size
*/
int size = initializeArray(data);
/**
* Calling printArray() method and pass data[] array and size as its parameter
*/
printArray(data,size);
/**
* Below three integers named minimum, maximum and sum are declared
* respectively. And we call respective methods for each of them.
* For all the three methods parameters are same i.e data[] and size
*/
int minimum = findMinimum(data,size);
int maximum = findMaximum(data,size);
int sum = findSum(data,size);
/**
* Printing all the values
*/
Console.WriteLine("Min is: "+minimum);
Console.WriteLine("Max is: "+maximum);
Console.WriteLine("Sum is: "+sum);
}/*main ends here*/
public static int initializeArray(int[] data){
/**
* Two integer variables named index and value are declared below.
* index is used as index position and also as number of integers
* in data[] array.
*/
int index = 0, value;
/**
* In a while loop we will scan integer inputs from the user
* and store them in data[] array at respective index
* position. Once user enters -1, we will terminate
* the loop.
*/
while(true){
/**
* Prompting user to enter the value which is stored in integer
* variable named value
*/
Console.Write("Enter a number or -1 to finish: ");
value = Convert.ToInt32(Console.ReadLine());
/**
* Check if value is -1, if yes then break
*/
if(value==-1){
break;
}
/**
* If value is not -1 then we will add that value in data[] array
* at index position indicated by index variable.
* And after that, we need to increment index by 1
*/
data[index] = value;
index++;
}/*whilw loop ends here*/
/**
* We will return the value index
*/
return index;
}/*initializeArray function ends here*/
public static void printArray(int[] data, int size){
/**
* First print the verticle line
*/
Console.Write("|");
/**
* Using for loop to traverse data[] array until size,
* we will print each element of the array
*/
for(int i=0;i<size;i++){
Console.Write(data[i]+"|");
}
Console.WriteLine();
}/*printArray function ends here*/
public static int findMinimum(int[] data, int size){
/**
* We know that range of values in data[] array is 0-99,
* so an integer named min is declared and initialized as 100.
*/
int min = 100;
/**
* Using for loop we traverse through the array and compare
* each current value with min variable.
* If current value is smaller than compared to min,
* the we assign current value to min
*/
for(int i=0;i<size;i++){
if(data[i]<min){
min = data[i];
}
}
/**
* Return the min
*/
return min;
}/*findMinimum function ends here*/
public static int findMaximum(int[] data, int size){
/**
* We know that range of values in data[] array is 0-99,
* so an integer named max is declared and initialized as -1.
*/
int max = -1;
/**
* Using for loop we traverse through the array and compare
* each current value with max variable.
* If current value is greater than compared to max,
* the we assign current value to max
*/
for(int i=0;i<size;i++){
if(data[i] > max){
max = data[i];
}
}
/**
* Return the max
*/
return max;
}/*findMaximum function ends here*/
public static int findSum(int[] data, int size){
/**
* An integer named sum is declared and initialized as 0.
*/
int sum = 0;
/**
* Using for loop we traverse through the array and add
* each element into the sum
*/
for(int i=0;i<size;i++){
sum = sum + data[i];
}
/**
* Return the sum
*/
return sum;
}/*findSum functions ends here*/
}/*class ends here*/
Output:
Test Case 1:

Test Case 2:

Please provide the feedback!!
Thank You!!