CEIS295 Lab 4: All exercises – Header and cpp files included for all exercises with screenshots – Perfect Solution – Instant Delivery
Lab Overview
Scenario/Summary
The purpose of the Lab exercises is to help the student acquire skills in developing programs that involve algorithm analysis, recursion, and sorting.
Deliverables
There are four exercises in this Lab, although not all of them will be required for submission. Be sure to read the following instructions carefully.
• Exercise 1: No submission is required.
• Exercise 4 requires not only software development but also explanations about the results of the experiments that are conducted.
• Create a separate Word document to provide the details required in the exercise.
• Create a folder and name it Week 4 Lab. Inside this folder, create the subfolders Ex2, Ex3, and Ex4. Place the solution to each of the three exercises required for submission in the corresponding subfolder. Compress the folder Week 4 Lab, and submit the resulting zipped folder.
• Note that Exercises 2, 3, and 4 require software development. For each of them, place in the corresponding folder the source code files (i.e., .h and .cpp files) you created, and a screenshot of the execution window. Do not submit other files or folders, including those automatically generated by the IDE.
Required Software
Visual Studio
Access the software at https://lab.devry.edu (Links to an external site.)Links to an external site..
All steps
Microsoft Office: Word
Use a personal copy or access the software at https://lab.devry.edu (Links to an external site.)Links to an external site..
Step: 4
Lab Steps
Exercise 1: Lesson Review
Create three projects, Minimum, Factorial, and Sorting Algorithms, using the programs as follows.
• Minimum (Links to an external site.)Links to an external site.
• Factorial (Links to an external site.)Links to an external site.
• Sorting Algorithms (Links to an external site.)Links to an external site.
Compile the three projects, run them, and review the code that is given carefully. These programs test the code discussed in the lesson.
Exercise 2: Designing and Implementing Algorithms
Design and implement an algorithm that, when given a collection of integers in an unsorted array, determines the third smallest number (or third minimum). For example, if the array consists of the values 21, 3, 25, 1, 12, and 6 the algorithm should report the value 6, because it is the third smallest number in the array. Do not sort the array.
To implement your algorithm, write a function thirdSmallest that receives an array as a parameter and returns the third-smallest number. To test your function, write a program that populates an array with random numbers and then calls your function.
Exercise 3: Recursion
The following problem is a variation of Exercise C-4.27 in the Exercises section of Chapter 4 in our textbook.
Implement a recursive function for computing the n-th Harmonic number:
Hn=∑ni=11i/Hn=∑i=1n1i
.
Here you have some examples of harmonic numbers.
H1 = 1
H2 = 1 + 1/2 = 1.5
H3 = 1 + 1/2 + 1/3 = 1.8333
H4 = 1 + 1/2 + 1/3 + 1/4 = 2.0833
Exercise 4: Sorting
In this week’s lesson, the algorithms quicksort and bubblesort are described. In Sorting Algorithms (Links to an external site.)Links to an external site. you can find the class ArrayList, where these sorting algorithms are implemented. Write a program that times both of them for various list lengths, filling the array lists with random numbers. Use at least 10 different list lengths, and be sure to include both small values and large values for the list lengths (it might be convenient to add a parameterized constructor to the class ArrayList so the size of the list can be set at the moment an ArrayList object is declared).
Create a table to record the times as follows.
List Length Bubblesort Time
(seconds) Quicksort Time
(seconds)
Regarding the efficiency of both sorting methods, what are your conclusions? In addition to the source code and a screenshot of the execution window, please submit a separate document with the table and your conclusions about the experiment.
Note: To time a section of your source code, you can do this.
#include
using namespace std;
int main()
{
start = chrono::steady_clock::now();
//add code to time here
end = chrono::steady_clock::now();
chrono::duration
cout << "Code duration: " << timeElapsed.count() << " seconds" << endl;
}