Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an application using C# visual studio that can be used to test input value

ID: 3688983 • Letter: W

Question

Write an application using C# visual studio that can be used to test input values to ensure they fall within an established range. Use an array to keep a count of the number of times each acceptable value was entered. Acceptable values are integers between 0 and 10. Your program should display the total number of valid values inputted as well as the number of invalid entries. Show not only the number of values outside the range, but also the number of non-numeric invalid values entered. For your final display, output a list of distinct valid entries and a count of how many times that entry occurred. Provide your listing in a tabular format, with values number aligned. Do not display the value unless it was entered. Use the following test data: 7 2 4 2 q 87 4 6 4 4 7

Explanation / Answer

Console Application program of c# with required logic and code..........

using System;

namespace Example1
{
class Program
{


static void Main(string[] args)
{

   int [,]valid_arr;
string [,]invalid_arr;

Console.Write(" Enter values: ");

string[] tokens = Console.ReadLine().Split();
  
for( int i=0; i < tokens.length; i++)
{
       bool isNumeric = int.TryParse(tokens[i]);
int flag = 0;
int num = -1;
      

       if(isNumeric)       
       {  
flag = 1;
       num = int.Parse(tokens[i]);
       int index = Array.IndexOf(tokens, num.ToString());
       }

       if(num >= 0 && num <= 10)
       {
       if(index > -1)
       {
          
       valid_arr[1][index]++; // INCREEMENT FREQUENCY

       }
       else
       {
       valid_arr[0][valid_arr.GetLength(1)-1] = num;
       valid_arr[1][valid_arr.GetLength(1)-1] = 1; // INITIALIZING FREQUENCY FOR FIRST OCCURENCE
       }


       }
      

       if(flag == 1)
       {
       int index = Array.IndexOf(tokens, tokens[i]);

           if(index > -1)
           {
           int a = int.Parse(invalid_arr[1][index]);
a++;
          
invalid_arr[1][index] = a.ToString(); // INCREEMENT FREQUENCY

           }
           else
           {
           invalid_arr[0][invalid_arr.GetLength(1)-1] = tokens[i];
           invalid_arr[1][invalid_arr.GetLength(1)-1] = 1;   // INITIALIZING FREQUENCY FOR FIRST OCCURENCE
           }
       }

   }


   /* for( int i=0; i <=1; i++)
   {
   for(int j = 0; j < valid_arr[i].length; j++)
    Console.Write("{0} " + valid_arr[i,j]);
   Console.Write(" ");
   }*/

   Console.WriteLine("Valid Elements -- Frequency");

   for( int i=0; i < valid_arr.GetLength(1); i++)
   {
Console.WriteLine("{0} -- {1} " + valid_arr[0,i], valid_arr[1,i]);
   }


   Console.WriteLine("InValid Elements -- Frequency");      
   for( int i=0; i < invalid_arr.GetLength(1); i++)
   {
Console.WriteLine("{0} -- {1} " + invalid_arr[0,i], invalid_arr[1,i]);
   }

}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote