1D Array Methods Exercise

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What method can be used to sort an array in descending order after sorting it in ascending order?

  • Array.Reverse() (correct)
  • Array.OrderDescending()
  • Array.Sort()
  • Array.Invert()

If a user inputs a color that does not exist in the color array, what method can be used to check for the color's presence?

  • Array.Contains()
  • Array.Find()
  • Array.Exists()
  • Array.IndexOf() (correct)

What is the proper naming convention for the file that stores the code for question 3?

  • last_name_first name_E02_3.cs
  • last_name_first name_U4_E02_3.cs (correct)
  • U4_E02_3_last_name_first name.cs
  • last_name_E02_3.cs

What data type must the user input when required to provide 5 integers for sorting?

<p>Integers (C)</p> Signup and view all the answers

In the provided CSV file structure, what does the first line represent?

<p>An integer indicating the number of records (C)</p> Signup and view all the answers

How many marks are associated with each student's record in the given CSV file format?

<p>4 (D)</p> Signup and view all the answers

What will the output be if a user inputs a color that is in the color array?

<p>The color exists. (D)</p> Signup and view all the answers

What is the expected output when utilizing the Array.Reverse() method on an already sorted ascending array?

<p>The array is reversed to descending order. (B)</p> Signup and view all the answers

What is the purpose of the .Split() method in the context of reading records?

<p>To separate the last name and first name from the marks. (B)</p> Signup and view all the answers

If a user inputs an index 'i' of value 2, which value will be deleted from the array?

<p>The value at index 2. (A)</p> Signup and view all the answers

What should be done to the last element in the array after deleting an element?

<p>It should be set to '0'. (A)</p> Signup and view all the answers

What is the expected output when the program finds duplicates in the given array?

<p>All duplicates present in the array should be listed. (D)</p> Signup and view all the answers

Which operation is necessary before finding duplicates in the integer array?

<p>Sorting the array. (D)</p> Signup and view all the answers

How do you determine the student with the highest average based on the provided exercise?

<p>By comparing the averages of all students. (D)</p> Signup and view all the answers

What will happen if two students have the same average?

<p>It is assumed that all averages are unique. (B)</p> Signup and view all the answers

What should the program output after deleting an element from the array?

<p>The array after deletion, sorted. (A)</p> Signup and view all the answers

Flashcards

Array.Reverse() method

A method in C# that can be used to reverse the order of elements in a one-dimensional array.

Array.IndexOf() method

A method in C# that searches an array for a specific element and returns its index position, or -1 if the element is not found.

CSV (Comma-Separated Values) file

A file format used to store tabular data, where data is separated by commas and each line represents a row.

One-Dimensional Array

A collection of data elements of the same type stored in contiguous memory locations, accessible by an index.

Signup and view all the flashcards

Sorting an Array

To arrange elements in increasing order (ascending) or decreasing order (descending).

Signup and view all the flashcards

Key-Value Pair

Organizing information based on a key or criteria, often used for fast retrieval.

Signup and view all the flashcards

Interactive Program

A program that interacts with the user, often by taking input and producing output.

Signup and view all the flashcards

Tree Data Structure

A data structure that allows you to store and access data efficiently by organizing it into a hierarchy of parent and child nodes.

Signup and view all the flashcards

Split() Method

A method used to split a string into an array of substrings based on a specified delimiter. This method takes a delimiter as an argument and returns an array of strings where each element represents a substring separated by the delimiter.

Signup and view all the flashcards

What is an array?

An array is a data structure that stores a collection of elements of the same data type, accessed using an index.

Signup and view all the flashcards

For-loop

A loop that iterates through a specific number of times, controlled by a counter variable.

Signup and view all the flashcards

Double data type

A variable that stores a number with decimal places, suitable for representing quantities like weights, temperatures, or averages.

Signup and view all the flashcards

Minimum value

The smallest value in a given dataset.

Signup and view all the flashcards

Maximum value

The largest value in a given dataset.

Signup and view all the flashcards

Average

The average of a set of values, calculated by summing them and dividing by the number of values.

Signup and view all the flashcards

Deleting an element from an array

The process of removing an element from an array by shifting all subsequent elements to the left, ensuring a compact array without gaps.

Signup and view all the flashcards

Study Notes

Exercise 02 - 1D Array Methods

  • File Naming Convention: Rename program files to last_name_first_name_U4_E02_#.cs (where # is the question number) before submission.

Question 1

  • Ascending Order: Write a program that takes 5 integer inputs from the user and then sorts and displays them in ascending order.
  • Descending Order: Output the same integers in descending order, using the Array.Reverse() method.

Question 2

  • Color Check: Create a string array containing colors. Prompt the user for a color, and check if that color exists within the array. Use the Array.IndexOf() method.

Question 3

  • Input CSV: The input file input.csv contains student names and their marks. The first line has the number of records. Each following pair of lines represents a student and their scores.

  • Output Requirements: Calculate minimum, maximum, and the average score for each student and output it. Output the name and average of the student with the highest average.

Question 4

  • Array Manipulation: Create an array of 5 doubles, taking user input for an index, delete the value at that index by shifting all elements to the left.

  • Element Replacement: The last element should be set to 0.

  • Sorting: Sort the resulting array and display it.

Question 5

  • Duplicate Finder (Optional): Find and output all duplicate integers within a given array of size 20, containing integers between 1 and 10. The array is int[] myInts = {3, 5, 6, 9, 10, 10, 3, 7, 5, 4, 2, 1, 2, 4, 3, 7, 8, 5, 2, 6};

Question 6

  • Array Methods Comparison (Optional): Research and describe scenarios where Array.BinarySearch() or Array.IndexOf() should be used. Document your answer in a .txt file.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

More Like This

JavaScript Array Methods and Loops
3 questions

JavaScript Array Methods and Loops

EnterprisingAcademicArt avatar
EnterprisingAcademicArt
JavaScript Array Methods
48 questions

JavaScript Array Methods

FastPacedLightYear avatar
FastPacedLightYear
Use Quizgecko on...
Browser
Browser