For the following C# program: Let’s add one more user defined method to the program. This method, called ReverseDump is to output the values in the array in revere order (please note that you are NOT to use the Array.Reverse method from the Array class). The approach is quite simple: your ReverseDump method will look very similar to the Dump method with the exception that the for loop will count backwards from num 1 to 0 . The method header will look like: public static void ReverseDump(int [] arrItems, int num) ***What needs to be done*** Create the ReverseDump method and Call the ReverseDump method in main The goal is just to output the values from the array in reverse order. ****Program in C#**** using System; public static class Lab4_1 { public static void Main() { int[] dataArray = new int[10] {9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; int n = 0; // Fill the array Fill(dataArray, ref n); // Display the array contents Dump(dataArray, n); // Pause until user is done Console.ReadLine(); } // Method: Fill // Description: Fill an array with values. // Parameters: arrValues: the array to fill. // num: number of elements in the array. // Returns: void public static void Fill(int[] arrValues, ref int num) { // input the number of data values to put in the array do { Console.Write("Enter the number of elements (between 0 and 10) => "); num = Convert.ToInt32(Console.ReadLine()); } while(num < 0 || num > 10); // loop to enter the values for(int i = 0; i < num; ++i) { Console.Write("Enter the Element {0} => ", i); arrValues[i] = Convert.ToInt32(Console.ReadLine()); } } // Method: Dump // Description: Display the contents of an array. // Parameters: arrVals: array to be displayed. // num: number of elements in the array. // Returns: void public static void Dump(int[] arrVals, int num) { // output the values from the array Console.WriteLine("The elements in the array are:"); for (int i = 0; i < num; ++i) Console.WriteLine(" {0}", arrVals[i]); } }
SOURCE CODE IN C#:
using System;
public static class main
{
public static void Main()
{
int[] dataArray = new int[10] {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
int n = 0;
// Fill the array Fill(dataArray, ref n);
Fill(dataArray, ref n);
Dump(dataArray, n);
ReverseDump(dataArray, n);
}
// Method: Fill
// Description: Fill an array with values.
// Parameters: arrValues: the array to fill.
// num: number of elements in the array.
// Returns: void
public static void Fill(int[] arrValues, ref int num)
{
// input the number of data values to put in the array
do
{
Console.Write("Enter the number of elements (between 0 and 10) => ");
num = Convert.ToInt32(Console.ReadLine());
}while(num < 0 || num > 10);
// loop to enter the values
for(int i = 0; i < num; ++i)
{
Console.Write("Enter the Element {0} => ", i);
arrValues[i] = Convert.ToInt32(Console.ReadLine());
}
}
// Method: Dump
// Description: Display the contents of an array.
// Parameters: arrVals: array to be displayed.
// num: number of elements in the array.
// Returns: void
public static void Dump(int[] arrVals, int num)
{
// output the values from the array
Console.WriteLine("The elements in the array are:"); for (int i = 0; i < num; ++i)
Console.WriteLine("{0}", arrVals[i]);
}
// Method: ReverseDump
// Description: Display the contents of an array in reverse order.
// Parameters: arrItems: array to be displayed.
// num: number of elements in the array.
// Returns: void
public static void ReverseDump(int [] arrItems, int num)
{
//output the values from the array in reverse order
Console.WriteLine("The elements in the array in reverse order are:"); for (int i = num-1; i >= 0; --i)
Console.WriteLine("{0}", arrItems[i]);
}
}
OUTPUT:
For the following C# program: Let’s add one more user defined method to the program. This...
What I need: Write a program named Averages that includes a method named Average that accepts any number of numeric parameters, displays them, and displays their average. For example, if 7 and 4 were passed to the method, the ouput would be: 7 4 -- Average is 5.5 Test your function in your Main(). Tests will be run against Average() to determine that it works correctly when passed one, two, or three numbers, or an array of numbers. What I...
Hello in C#. I need help understanding and knwoing what i missed in my program. The issue is, the program is supposed to have user input for 12 family members and at the end of the 12 it asks for user to input a name to search for. When i put a correct name, it always gives me a relative not found message. WHat did i miss. And can you adjust the new code so im able to see where...
This C# program prints out a corresponding letter grade for a given mark. It uses a method (called MarktoGrade) to determine the letter grade. MarktoGrade takes one integer call by value formal parameter (called mark) and returns a char value that is the letter grade. All of the input and output (except an error message) is done in Main. There is one syntax error in this program that you will need to fix before it will compile (the error is...
C# Arrays pne and Look at the code below Notice that the program has one class called Tournament. . It defines an integer array called scores to hold all the scores in the tournament .The constructor for the class then actually creates the array of the required size. class Tournament int[ ] scores; const int MAX = 6; // define scores as an integer array // set a constant size public static void Main() //program starts executing here Tournament myTournament...
. In the method main, prompt the user for a non-negative integer and store it in an int variable num (Data validation is not required for the lab). Create an int array whose size equals num+10. Initialize the array with random integers between 0 and 50 (including 0 and excluding 50). Hint: See Topic 4 Decision Structures and File IO slides page 42 for how to generate a random integer between 0 (inclusive) and bound (exclusive) by using bound in...
C#, I am getting error placing them all in one file pls set them in the order that all 3 work in one file. Thanks //Program 1 using System; class MatrixLibrary { public static int[,] Matrix_Multi(int[,] a, int [,]b){ int r1= a.GetLength(0); int c1 = a.GetLength(1); int c2 = b.GetLength(1); int r2 = b.GetLength(0); if(r2 != c2){ Console.WriteLine("Matrices cannot be multiplied together.\n"); return null; }else { int[,] c = new int[r1, c2]; for (int i = 0; i <...
X. (10 points) In the box provided show the output for this program segment public static void main (String [) args) intl num-(1,2.3,4) System.out printinx+y+num12) tyit(y, x. num): System.out printin(x+ynum(2): public static void tryit(int a, int b, intl c) int x c[2]-20 System.out printin(x+bCI2) XI. (7 points) a. Write a method NEGATIVE that receives as parameters a one-dimensional array variable LIST of integers. The method should return the sum of the negative elements in the array. You may not assume...
Write a C Program that inputs an array of integers from the user along-with the length of array. The program then prints out the array of integers in reverse. (You do not need to change (re-assign) the elements in the array, only print the array in reverse.) The program uses a function call with array passed as call by reference. Part of the Program has been given here. You need to complete the Program by writing the function. #include<stdio.h> void...
Add a method called median() to the ArrayIns class in the insertSort.java program (Listing 3.3). This method should return the median value in the array. (Recall that in a group of numbers half are larger than the median and half are smaller.) Do it the easy way. LISTING 3.3 The insertSort.java Program // insertSort.java // demonstrates insertion sort // to run this program: C>java InsertSortApp //-------------------------------------------------------------- class ArrayIns { private long[] a; // ref to array a private int nElems;...
Create a program named IntegerFacts whose Main() method declares an array of 10 integers. Call a method named FillArray to interactively fill the array with any number of values up to 10 or until a sentinel value (999) is entered. If an entry is not an integer, reprompt the user. Call a second method named Statistics that accepts out parameters for the highest value in the array, lowest value in the array, sum of the values in the array, and...