Question

Create a program named IntegerFacts whose Main() method declares an array of 10 integers. Call a...

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 arithmetic average.

In the Main() method, display all the statistics in the following format: Note: The inputs were 1, 11, and 999

The array has 2 values
The highest value is 11
The lowest value is 1
The sum of the values is 12
The average is 6 

using static System.Console;
class IntegerFacts
{
   static void Main()
   {
      // Write your main here
   }

   public static int FillArray(int[] array)
   {
   }
   public static void Statistics(int[] array, int els, out int high, out int low, out int sum, out double avg)
   {
   }  

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// C# codee

using System;

class IntegerFacts
{
static void Main()
{
int[] x = new int[10];
int sum = 0;
int siz = 0, high = 0, low = 0, avg = 0;

siz = FillArray(x);
  
Statistics(x, ref high, ref low, ref sum, ref avg, siz);
  
Console.Write("The highest value is " + high);
Console.Write("\nThe lowest value is " + low);
Console.Write("\nThe sum of the values is " + sum);
Console.Write("\nThe average is " + avg);
}
  
static void Statistics (int [] b, ref int h, ref int l, ref int s, ref int a, int size)
{
if (size == 0)
h = l = s = a = 0;
else
{
int i =0;
l = 999;
h = 0;
s = 0;
for (; i < size;++i)
{
if(b[i] > h)
h = b[i];
if(b[i] < l)
l = b[i];
s += b[i];
}
a = s / size;
}
}
  
static int FillArray (int[] a)
{
int i = 0, count = 0;
int intTemp =0 ;
string temp;
  
for(i = 0 ; i < 10 ; i++)
{
Console.Write("Enter element number"+(i+1) +" : ");
temp = Console.ReadLine();
if (int.TryParse(temp, out intTemp)) {
if (intTemp != 999)
{
a[i] = intTemp;
count++;
}
else
break;
}
else
{
Console.Write("\n\nOops.. You entered a wrong number. Try again \n\n");
i--;
}
}
return count;
}
}

OUTPUT:

Result... compiLed and executed in 18.888 sec(s) Enter element numberi: g Oops.. You entered a wrong number. Try again Enter

Add a comment
Know the answer?
Add Answer to:
Create a program named IntegerFacts whose Main() method declares an array of 10 integers. Call a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • c# Write compile and test a program named IntegerStatistics. The programs Main() method will: 1. Declare...

    c# Write compile and test a program named IntegerStatistics. The programs Main() method will: 1. Declare an array of 10 integers. 2. Call a method to interactively fill the array with any number of values (up to 10) until a sentinel value is entered. [If an entry is not an integer, continue prompting the user until an integer is entered.] When fewer than 10 integers are placed into the array, your statistics will be off unless you resize the array...

  • In this lab, you will create one class named ArrayFun.java which will contain a main method...

    In this lab, you will create one class named ArrayFun.java which will contain a main method and 4 static methods that will be called from the main method. The process for your main method will be as follows: Declare and create a Scanner object to read from the keyboard Declare and create an array that will hold up to 100 integers Declare a variable to keep track of the number of integers currently in the array Call the fillArray method...

  • Write a program that instantiates an array of integers named scores. Let the size of the...

    Write a program that instantiates an array of integers named scores. Let the size of the array be 10. The program then first invokes randomFill to fill the scores array with random numbers in the range of 0 -100. Once the array is filled with data, methods below are called such that the output resembles the expected output given. The program keeps prompting the user to see if they want to evaluate a new set of random data. Find below...

  • Java 1. Create an application named NumbersDemo whose main() method holds two integer variables. Assign values...

    Java 1. Create an application named NumbersDemo whose main() method holds two integer variables. Assign values to the variables. In turn, pass each value to methods named displayTwiceTheNumber(), displayNumberPlusFive(), and displayNumberSquared(). Create each method to perform the task its name implies. 2. Modify the NumbersDemo class to accept the values of the two integers from a user at the keyboard. This is the base code given: public class NumbersDemo { public static void main (String args[]) { // Write your...

  • LAB: How many negative numbers Write a program that generates a list of integers, and outputs...

    LAB: How many negative numbers Write a program that generates a list of integers, and outputs those integers, and then prints the number of negative elements. Create a method (static void fillArray(int [] array)) that uses Random to generate 50 values (Random.nextInt()), put each value in the array (make sure to pass the array in to this method as an argument). Write another method (static int printAndCountNeg(int [] array)) that prints each element’s value and count the number of negative...

  • In Java Please Create A Program For The Following; Please Note: This program should be able...

    In Java Please Create A Program For The Following; Please Note: This program should be able accept changes to the values of constants ROWS and COLS when testing the codes. Switch2DRows Given a 2D array with ROWS rows and COLS columns of random numbers 0-9, re-order the rows such that the row with the highest row sum is switched with the first row. You can assume that 2D arrau represents a rectangular matrix (i.e. it is not ragged). Sample run:...

  • Programming 5_1: Create a Java class named <YourName>5_1 In this class create a main method...

    Programming 5_1: Create a Java class named <YourName>5_1 In this class create a main method, but for now leave it empty. Then write a Java method getAverage which takes an array of integers as it’s argument. The method calculate the average of all the elements in the array, and returns that average. The method should work for an array of integers of any length greater than or equal to one. The method signature is shown below: public static double getAverage(...

  • Create a C program that: Within main, declares a linear array consisting of 10 double values....

    Create a C program that: Within main, declares a linear array consisting of 10 double values. You can assign values to the array when it is declared or fill them items manually using scanf () - your choice. Also, declare three doubles: min, max, and average. Then from within main, a function is called. The function should take a pointer to the array declared above and then finds the maximum value, the minimum value, and calculates the average of the...

  • . In the method main, prompt the user for a non-negative integer and store it in...

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

  • JAVA 1.Write a static method named getMaxEven(numbers) which takes an array of positive integers as a...

    JAVA 1.Write a static method named getMaxEven(numbers) which takes an array of positive integers as a parameter. This method calculates and returns the largest even number in the list. If there are no even numbers in the array, the method should return 0. You can assume that the array is not empty. For example: Test Result int[] values = {1, 4, 5, 9}; System.out.println(getMaxEven(values)); 4 System.out.println(getMaxEven(new int[]{1, 3, 5, 9})); 0 public static int --------------------------------------------------------------------------------- 2. Write a static method...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT