Question

In: Computer Science

Need in C# with the exact style of output listed. Assignment7A: A new field of computer...

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

Solutions

Expert Solution

Explanation:

  • Code in C# is given below
  • Please read comments for better understanding of the code
  • Output is given at the end of the code

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!!


Related Solutions

Java Program. Please read carefully. i need the exact same output as below. if you unable...
Java Program. Please read carefully. i need the exact same output as below. if you unable to write the code according to the question, please dont do it. thanks To the HighArray class in the highArray.java program (Listing 2.3), add the following methods: 1.      getMax() that returns the value of the highest key (value) in the array without removing it from the array, or –1 if the array is empty. 2.      removeMax() that removes the item with the highest key from the...
PROBLEM: Write a C program that will produce the EXACT output shown below. Using initialization lists,...
PROBLEM: Write a C program that will produce the EXACT output shown below. Using initialization lists, create 5 one-dimensional arrays, one for each of these: hold the names of the people running in the election (see note below) hold the names of the subdivision (see note below) hold the vote counts in the Aberdeen subdivision for each candidate hold the vote counts in the Brock subdivision for each candidate hold the vote counts in the Sahali subdivision for each candidate...
c# code working but output not right, I need to output all numbers like : Prime...
c# code working but output not right, I need to output all numbers like : Prime factors of 4 are: 2 x 2 here is just 2 Prime factors of 7 are: 7 Prime factors of 30 are: 2 x 3 x 5 Prime factors of 40 are: 2 x 2 x 2 x 5 here is just 2,5 Prime factors of 50 are: 2 x 5 x 5 here is just 2,5 1) How I can fix it 2)I...
computer ,input and output device sof computer
What is computer list some input and output devices  of compueter.
C++: (I need this program to output in a certain format I will post the "needed...
C++: (I need this program to output in a certain format I will post the "needed results" below) To make telephone numbers easier to remember, some companies use letters to show their telephone number. For example, using letters, the telephone number 438-5626 can be shown as GET LOAN. In some cases, to make a telephone number meaningful, companies might use more than seven letters. For example, 225-5466 can be displayed as CALL HOME, which uses eight letter. Write a program...
I need the output of the code like this in java First we create a new...
I need the output of the code like this in java First we create a new building and display the result: This building has no apartments. Press enter to continue......................... Now we add some apartments to the building and display the result: This building has the following apartments: Unit 1 3 Bedroom Rent $450 per month Currently unavailable Unit 2 2 Bedroom Rent $400 per month Currently available Unit 3 4 Bedroom Rent $1000 per month Currently unavailable Unit 4...
need an example of a water pollution report in APA style
need an example of a water pollution report in APA style
Suppose you have algorithms with the five running times listed below. (Assume these are the exact...
Suppose you have algorithms with the five running times listed below. (Assume these are the exact running times.) How much slower (i.e., you need check the ratio) do each of these algorithms get when you (a) double the input size, (b) increase the input size by one? 5nlog(n)
Need this 8 queen code with same exact solution without goto. Need to keep the code...
Need this 8 queen code with same exact solution without goto. Need to keep the code as similar as possible. #include <iostream> #include <cmath> using namespace std; int main(){ int q[8], c = 0, i, j,count=0; q[0] = 0; //first queen top corner nc: c++; if(c == 8 ) goto print; q[c] = -1; nr: q[c]++; if(q[c] == 8) goto backtrack; for(i= 0; i < c; i++) { if((q[i] == q[c])||(c - i == abs(q[c] - q[i]))) goto nr; }...
In C Programming Language Write a program to output to a text log file a new...
In C Programming Language Write a program to output to a text log file a new line starting with day time date followed by the message "SUCCESSFUL". Please screenshot the results.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT