Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Waubonsee Community College CIS130 C++ Programming Spring 2018 Maya Tolappa Test 3 hand on Portion (50 points) The purpose of this test is to test
Waubonsee Community College CIS130 C++ Programming
Spring 2018 Maya Tolappa
Test 3 hand on Portion (50 points)
The purpose of this test is to test your knowledge of arrays and pointers.
You may change line 24 to use a SMART POINTER if you wish!
Consider the following cpp file that is part of the solution provided to you. Download it by clicking this link or from BlackBoard.
#include
#include
#include
#include
#include
using namespace std;
int main()
{
srand(time(NULL));
string arr_inst_names[10] = { "Georgette","Francene", "Earle",
"Hsiu", "Antonio", "Gema",
"Wallace","Josefina","Belia",
"Margaretta" };
//********************** 5 points *******************
//code a loop to print out the contents of the arr_inst_names array
//generate a random number as per specifications and assign it to
//the arr_size variable
int arr_size;
string *ptr_to_names_arr;
//create a string array with arr_size elements and place address
//of this newly created array into the ptr_to_names_arr pointer
//variable.
//Populate this newly created array from elements in
//the arr_inst_names array
//********************** 5 points *******************
cout
//**************** 15 points for print_arr function **************
//The print_array function prints the elements in the array whose
//address is maintained in the ptr_to_names_arr pointer
//Remember to create a function prototype for the function
print_array(ptr_to_names_arr, arr_size);
//**************** 15 points for sort_arr function **************
//The sort_array function must sort the elements in the array whose
//address is maintained in the ptr_to_names_arr pointer
//as per specifications. Remember to create function prototype
sort_array(ptr_to_names_arr, arr_size);
cout
The output from my implementation of the program looks like this.: Georgette Francene Earle Hsiu Antonio Gema Wallace Josefina Belia Margaretta -Before sort-- Array size 4 Georgette Francene Earle Hsiu -After sort-- Array size = 4 Earle Francene Georgette Hsiu print_array(ptr_to_names_arr, arr_size);
//**************** 10 points deletion statement.**************
//delete the memory taken up by the array whose address is maintained in
//the ptr_to_names_arr pointer
//****** Automatically awarded when you use smart pointers! *********
return 0;
}
In order to complete this program, complete these steps:
Task
Points
1.
Code a loop to print out the contents of the arr_inst_names array
5
Place a random number between 4 and 8 in arr_size
Create a string array with arr_size elements and place address of this newly created array into the names_arr pointer variable. Populate this newly created array from elements in the arr_inst_names array.
Implement print_array function
Implement sort_array function to sort elements in ascending order
Delete space taken up by dynamically created array.
You can when you use a smart pointer!
The output from my implementation of the program looks like this.:
Georgette Francene Earle Hsiu Antonio Gema Wallace Josefina Belia Margaretta
---Before sort---
Array size = 4
Georgette Francene Earle Hsiu
---After sort---
Array size = 4
Earle Francene Georgette Hsiu
Step 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