Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please write in C++, if you can only do a few thats ok something to get me started 4.2 Requirements In this question, you will
Please write in C++, if you can only do a few thats ok something to get me started
4.2 Requirements In this question, you will write a serial program that executes a scquence of oommands that operate on individual files. Valid commands include: Start Name, where Name is a character string of maxi ength 20 alphabetic characters representing the name of the data file (Name.txt). The structure of Name.txt is an integer N indicating the total number of data entries contained in this file, followed by N additional lines of integers (the actal data entries). This command first eads N frothe file Name.txt, dynamically allocates an array of integers of size N ( it has not already been allocated), and then reads the remaiing N data entries into the array. The commands that follow until the End command are to be applied to the resulting data array. The output of the Start command is: Processing data from: Name.tat End Name, which indicates the end of the processing for the data in file Name.txt. The Start and End commands will always come in pairs with matching n Auy memory dynamically allocated for Name must be freed on an End command. The output of the End conmand is: End of processing data from: Name.txt InsertionSort, applies insersion sort on the input data array. You ust implement the insertion sort based on the pseudocode discussed in class or from the textbook. The output inchudes the number of comparisons made () the nmber of swaps made in sorting the data (s), and the time taken to run the insertion sort (ti in the following format Number of comparisons made by insertion sort: c Number of swaps made by insertion sort: s Time to run insertion sort (ms): .MergeSort, applies merge sort on the input data array. Yomust implement the merge sort based on the pseudocode discussed in class or from the textbook. The output includes the number of comparisons made (m), the number of swaps made in sorting the data (Sm), and the time taken to run the merge sort (%) in the following format Number of comparisons Number of swaps made by merge sort: m Time to run merge sort (ms): made by merge sort: . Select item, selects an item from a sorted data array. If the array has not been sorted by a previous command yet, the following Unable to select from an unsorted array Valid items for selection include: error must be reported - max, prints the largest value in the data array: - min, prints the smallest item in the data array; - median, prints the median value of the data array Output the selected item (), and the time taken () to select this item as follows: Time to run the selection (ms): t Exit, indicates that there are no more commands to execute, i.e., the program terminates. Test your program against the following command sequece All the test files are provided in the folder named 'data files' Start test l InsertionSort Select max Select min Select median End test.1 Start test 2 Select max End test.2 Start test 3 Select medianStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started