Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help please Part B, Question 1 Write a C program to sort 30 randomly generated uppercase characters in descending order (Z to A). Use the

Help please image text in transcribed
image text in transcribed
Part B, Question 1 Write a C program to sort 30 randomly generated uppercase characters in descending order (Z to A). Use the insertion sort algorithm. The program should: a) Generate a random array of 30 uppercase characters b) Print the random array c) Sort the random array using insertion sort d) Print the sorted array 2 marks] 1 mark] [6 marks] [1 mark] In order to achieve the above objectives, you may choose to follow the suggestions below: Write a function called generateRandomChar to generate one random character. This function has no input argument but returns a char (i.e. the random character). Call this function 30 times in the main function to generate 30 uppercase characters and assign each of these characters as an element of an array. Hint: Use the function rand() to generate random integers a) Write function called printArray to print out the contents of an array. The function's input argument is the char array that has to be printed. The function does not return any value. b) Write a function calledinsertionSort that carries out the insertion sort algorithm. The function's input argument is the char array containing unsorted uppercase characters. The function does not return any value. c) d) Call the printArray function accordingly in main function. An example of the output is shown in Figure Q1. Before: DLOLOHDCWTCBETOWVEPMYISZPGAJTN After: ZYWWVTTTSQ2PPONMLLJIHGEEDDCCBA Figure Q1 Note: BOLD and underlined denotes user's input. Part B, Question 2 Write a C program to sort 30 randomly generated uppercase characters in descending order (Z to A). Use the selection sort algorithm. The program should: a) Generate a random array of 30 uppercase characters b) Print the random array c) Sort the random array using selection sort d) Print the sorted array [2 marks] (1 mark] (6 marks] [1 mark] In order to achieve the above objectives, you may choose to follow the suggestions below: Write a function called generateRandomChar to generate one random character. This function has no input argument but returns a char (i.e. the random character). Call this function 30 times in the main function to generate 30 uppercase characters and assign each of these characters as an element of an array. Hint: Use the function rand () to generate random integers a) Write function called printArray to print out the contents of an array. The function's input argument is the char array that has to be printed. The function does not return any value. b) Write a function called selectionSort that carries out the selection sort algorithm. The function's input argument is the char array containing unsorted c) uppercase characters. The function does not return any value. d) Call the printArray function accordingly in main function. An example of the output is shown in Figure Q2. Before: NWLRBBMOBHCDARZOWKKYHIDDOSCDXR After: zYXWWSRRRQOONMLKKIHHDDDDCCBBBA

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions

Question

2. What potential barriers would you encourage Samuel to avoid?

Answered: 1 week ago