Question

PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE INTO VISUAL STUDIO Exercise #2:...

PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE INTO VISUAL STUDIO Exercise #2: Design and implement a program (name it CompareArrays) that compares the content of 2 single-dimensional arrays of the same size. The program prompts the users to enter the array size. Then prompts the user to initialize each array with integer values. The program defines method Compare() that takes two signal-dimensional arrays of type integer. The method compares the content of the arrays and returns true (Boolean type) if the arrays store same values in the same order. Otherwise, it returns false. The program main method calls method Compare()and prints the result from the method as shown below. Document your code and organized your output following these sample runs. Sample run 1: Array size: 4 First array: 23, -45, 78, 10 Second array: 23, -45, 78, 10 Judgment: The arrays are identical Sample run 2: Array size: 5 First array: 78, 128, 300, 12, 300 Second array: 78, 128, 12, 300, 300 Judgment: The arrays are not identical Sample run 3: Array size: 1 First array: 0 Second array: 0 Judgment: The arrays are identical

0 0
Add a comment Improve this question Transcribed image text
Answer #1
using System;
using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CompareArrays
{
    class Program
    {
        static void Main(string[] args)
        {
            //create variables
            int[] arr1, arr2;

            //get variables
            Console.Write("Enter a size for the arrays: ");
            int size = Convert.ToInt32(Console.ReadLine());
            arr1 = new int[size];
            arr2 = new int[size];

            Console.WriteLine("Enter values for first array");
            for (int j = 0; j < size; j++)
            {
                Console.Write("number " + j + ": ");
                arr1[j] = Convert.ToInt32(Console.ReadLine());                
            }

            Console.WriteLine("Enter values for second array");
            for (int j = 0; j < size; j++)
            {
                Console.Write("number " + j + ": ");
                arr2[j] = Convert.ToInt32(Console.ReadLine());
            }

            Console.WriteLine("");

            //call methods and print to console
            Console.WriteLine("Array size:\t" + size);
            Console.Write("First array:\t");
            for (int i = 0; i < size; i++)
            {
                Console.Write(arr1[i]);
                if (i != (size - 1))
                {
                    Console.Write(", ");
                }
                else
                {
                    Console.WriteLine("");
                }
            }
            Console.Write("Second array:\t");
            for (int i = 0; i < size; i++)
            {
                Console.Write(arr2[i]);
                if (i != (size - 1))
                {
                    Console.Write(", ");
                }
                else
                {
                    Console.WriteLine("");
                }
            }
            Console.Write("Judgement:\t");

            if (Compare(arr1, arr2, size))
            {
                Console.WriteLine("The arrays are identical");
            }else
            {
                Console.WriteLine("The arrays are not identical");
            }



            Console.ReadLine();

        }

        //methods
        public static bool Compare(int[] arr1, int[] arr2, int size)
        {
            for (int i = 0; i < size; i++)
            {
                if (arr1[i] != arr2[i])
                {
                    return false;
                }
            }
            return true;
        }
    }
}


Add a comment
Know the answer?
Add Answer to:
PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE INTO VISUAL STUDIO Exercise #2:...
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
  • SOLVE IN PYTHON: Exercise #2: Design and implement a program (name it CompareArrays) that compares the...

    SOLVE IN PYTHON: Exercise #2: Design and implement a program (name it CompareArrays) that compares the content of 2 single-dimensional arrays of the same size. The program prompts the users to enter the array size. Then prompts the user to initialize each array with integer values. The program defines method Compare() that takes two signal-dimensional arrays of type integer. The method compares the content of the arrays and returns true (Boolean type) if the arrays store same values in the...

  • Note: According to the question, please write source code in java only using the class method....

    Note: According to the question, please write source code in java only using the class method. Sample Run (output) should be the same as displayed in the question below. Make sure the source code is working properly and no errors. Exercise #2: Design and implement a program (name it compareArrays) that compares the content of 2 single-dimensional arrays of the same size. The program prompts the users to enter the array size. Then prompts the user to initialize each array...

  • C++ Arrays & Methods

     #2: Design and implement a program (name it CompareArrays) that compares the content of 2 single-dimensional arrays of the same size. The program prompts the users to enter the array size. Then prompts the user to initialize each array with integer values. The program defines method Compare() that takes two signal-dimensional arrays of type integer. The method compares the content of the arrays and returns true (Boolean type) if the arrays store same values in the same order. Otherwise, it...

  • C++ Single Dimensional Arrays

    Exercise #1: Design and implement a program (name it AssignGrades) that stores and processes numeric scores for a class. The program prompts the users to enter the class size (number of students) to create a single-dimensional array of that size to store the scores. The program prompts the user to enter a valid integer score (between 0 and 100) for each student. The program validates entered scores, rejects invalid scores, and stores only valid scores in the array.  The program...

  • C++Implement only (source code) a program to determine whether two two-dimensional arrays are equivalent or not....

    C++Implement only (source code) a program to determine whether two two-dimensional arrays are equivalent or not. Two arrays are equivalent if they contain the same values in any order. The program main method defines two two-dimensional array of size 3-by-3 of type integer, and prompts the user to enter integer values to initialize the arrays. The main method calls method isEquivalent()that takes two two-dimensional arrays of integer and returns true (boolean value) if the arrays contain the same values in...

  • IN PYTHON ONLY !! Design (pseudocode) and implement (source code) a program (name it Occurrences) to...

    IN PYTHON ONLY !! Design (pseudocode) and implement (source code) a program (name it Occurrences) to determine whether two two-dimensional arrays are equivalent or not. Two arrays are equivalent if they contain the same values in any order. The program main method defines two two-dimensional array of size 3-by-3 of type integer, and prompts the user to enter integer values to initialize the arrays. - The main method calls method isEquivalent()that takes two two-dimensional arrays of integer and returns true...

  • PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE IN VISUAL STUDIO Exercise #1:...

    PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE IN VISUAL STUDIO Exercise #1: Design and implement class Rectangle to represent a rectangle object. The class defines the following attributes (variables) and methods: 1. Two Class variables of type double named height and width to represent the height and width of the rectangle. Set their default values to 1.0 in the default constructor. 2. A non-argument constructor method to create a default rectangle. 3. Another constructor method to...

  • IN PYTHON WITHOUT USING: .APPEND/ .SORT/ INSERT / .SPLIT Program 1: Design (pseudocode) and implement (source...

    IN PYTHON WITHOUT USING: .APPEND/ .SORT/ INSERT / .SPLIT Program 1: Design (pseudocode) and implement (source code) a program (name it Occurrences) to determine whether two two-dimensional arrays are equivalent or not. Two arrays are equivalent if they contain the same values in any order. The program main method defines two two-dimensional array of size 3-by-3 of type integer, and prompts the user to enter integer values to initialize the arrays. The main method calls method isEquivalent()that takes two two-dimensional...

  • In pseudocode only Design (pseudocode) a program (name it Occurrences) to determine whether two two-dimensional arrays...

    In pseudocode only Design (pseudocode) a program (name it Occurrences) to determine whether two two-dimensional arrays are equivalent or not. Two arrays are equivalent if they contain the same values in any order. The program main method defines two two-dimensional array of size 3-by-3 of type integer, and prompts the user to enter integer values to initialize the arrays. The main method calls method isEquivalent()that takes two two-dimensional arrays of integer and returns true (boolean value) if the arrays contain...

  • PLEASE DO IN C# AND MAKE SURE I CAN COPY COPY CODE INTO VISUAL STUDIO Now,...

    PLEASE DO IN C# AND MAKE SURE I CAN COPY COPY CODE INTO VISUAL STUDIO Now, complete the provided “main” method by calling the previous method (“SortArray”). Display the contents of your array before and after the method call. A simple example of the output is provided below: Arrays Values before Sorting: Value at: [0] is: 11 Value at: [1] is: 4 Value at: [2] is: 44 Value at: [3] is: 14 Value at: [4] is: 5 Sorted Arrays Values:...

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