Question

write a C# program to sort a parallel array that consists of customer names and customer phone numbers. The solution should be in ascending order of customer names. For instance, if the input is string[] custNames- { ccc, ddd, aaa, bbb }; stringl] custIds687-3333, 456-4444, 789-1111, 234-2222 ; then, the solution is string[] string[] custNames- { aaa, bbb, ccc, ddd }; custIds789-1111, 234-2222, 687-3333, 456-4444]; There are some restrictions: Do not use Array.Sort(), List.Sort() methods. Instead, implement your own version of BubbleSort, InsertionSort, or SelectionSort (as discussed in classes) Do not wrap the arrays inside a class. Test the program with the sample data shown above. Print your documented code and screenshots. 1. 2. 3. 4.

Include the blackbox output done with C# microsoft visual studios software.

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

/**C # program that sort the array of strings
of customer names and customer ids in ascending order
and print results on console*/
//program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sorting
{
class Program
{
static void Main(string[] args)
{
//intialize custNames array
string[] custNames = { "ccc", "ddd", "aaa", "bbb" };
//intialize custIds array
string[] custIds = { "687-3333", "456-4444", "789-1111", "234-2222" };

Console.WriteLine("Sorted Customer Names : ");
//calling bubble sort
bubbleSort(custNames,custNames.Length);
//calling display method
display(custNames, custNames.Length);

Console.WriteLine("\nSorted Customer Names : ");
//calling bubble sort method
bubbleSort(custIds, custIds.Length);
//calling display method
display(custIds, custIds.Length);
  

//pause output on console until user enters a key
Console.ReadKey();

}

/**display method that takes string array and lenght as input
and print the string elements on console*/
public static void display(string[] list, int length)
{
for (int i = 0; i < length; i++)
{
Console.WriteLine("{0}", list[i]);
}
}
/**Bubble sort to sor the list of strings in ascending order*/
public static void bubbleSort(string[] list, int length)
{
for (int i = 1; i < length; i++)
{
for (int index = 0; index < length-i; index++)
{
if (list[index].CompareTo (list[index + 1])>0)
{
//swap them
string temp = list[index];
list[index] = list[index + 1];
list[index + 1] = temp;
}
}
}
} //end bubbleSort
}
}

Sample Output:

Sorted Customer Names Sorted Customer Ids 234-2222 456-4444 687-3333 789-1111

Add a comment
Know the answer?
Add Answer to:
Include the blackbox output done with C# microsoft visual studios software. write a C# program to...
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
  • THIS MUST BE DONE ON VISUAL STUDIO Write a C# program that computes a the cost...

    THIS MUST BE DONE ON VISUAL STUDIO Write a C# program that computes a the cost of donuts at your local Rich Horton’s store. The cost, of course, depends on the number of donuts you purchase. The following table gives the break down: Donuts Purchased Cost per Donut ($) = 15 0.75 A customer can save on the HST (13%) if they buy 12 or more donuts so only charge HST (use a constant) on the purchase if the customer...

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