C++ PLEASE INCLUDE COMMENTS, ADD WHAT IS NEEDED TO THIS CODE (feel free to make fixes or just write a totally new code, thank you) ---------------------------------------------------------------------------------------------------------------------------   #include #include #include using namespace std;   void fillArray(int intArray[],int size); void displayArray(int intArray[],int size) ; void searchElement(int intArray[],int size,int search) ;   //main function int main()   {   srand(static_cast(clock())) ;   int randomArray[20] ;   while(1)   {   cout << "Press (Y or y) to continue or (q or Q) to quit: " ; char ch; cin >> ch ;   if(ch=='y' || ch=='Y')   {   //function to fill the array fillArray(randomArray,20) ;   //function to display the array displayArray(randomArray,20);   //function to search the array int randomNumber = rand() % (10+1) ;   //it will generate the number between 0 to 10 inclusive searchElement(randomArray,20,randomNumber) ;   }   else if (ch=='q' || ch=='Q') {   cout << "Program over\n"; break ;   }   else   {   cout << "**** ERROR: Please select proper choice ****\n" ; }   }   return 0 ;   }   //filling the array void fillArray(int intArray[],int size)   {   //generating the random numbers for number of hours students spent on social media for(int i=0; i0) { cout << "The random number " << search << " occured " << count << " times\n" ;   }   else   {   cout << "The random number did not occur at all\n" ;   }   }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%
C++ PLEASE INCLUDE COMMENTS, ADD WHAT IS NEEDED TO THIS CODE
(feel free to make fixes or just write a totally new code, thank you)
---------------------------------------------------------------------------------------------------------------------------
 
#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
 
void fillArray(int intArray[],int size);
void displayArray(int intArray[],int size) ;
void searchElement(int intArray[],int size,int search) ;
 
//main function
int main()
 
{
 
srand(static_cast<unsigned int>(clock())) ;
 
int randomArray[20] ;
 
while(1)
 
{
 
cout << "Press (Y or y) to continue or (q or Q) to quit: " ;
char ch; cin >> ch ;
 
if(ch=='y' || ch=='Y')
 
{
 
//function to fill the array
fillArray(randomArray,20) ;
 
//function to display the array
displayArray(randomArray,20);
 
//function to search the array
int randomNumber = rand() % (10+1) ;
 
//it will generate the number between 0 to 10 inclusive
searchElement(randomArray,20,randomNumber) ;
 
}
 
else if (ch=='q' || ch=='Q')
{
 
cout << "Program over\n";
break ;
 
}
 
else
 
{
 
cout << "**** ERROR: Please select proper choice ****\n" ;
}
 
}
 
return 0 ;
 
}
 
//filling the array
void fillArray(int intArray[],int size)
 
{
 
//generating the random numbers for number of hours students spent on social media
for(int i=0; i<size; i++){int random= rand() % (10+1) ;
 
//it will generate the number between 0 to 10 inclusive
intArray[i]=(random) ;
 
}
 
}
 
//displaying the array
void displayArray(int intArray[],int size)
 
{
 
//displaying the array of element
scout << "Array elements are:\n" ;
for(int i=0; i<size; i++)
 
{
 
cout << intArray[i] << " ";
 
}
 
cout << "\n" ;
 
}
 
//searching the array
void searchElement(int intArray[],int size,int search)
 
{
 
int count=0 ;
 
//searching the array for element
for(int i=0; i<size; i++)
 
{
 
if(intArray[i]==search){count++;
 
}
 
}
 
//printing the results
if(count>0)
{
cout << "The random number " << search << " occured " << count << " times\n" ;
 
}
 
else
 
{
 
cout << "The random number did not occur at all\n" ;
 
}
 
}
Lab #11:
Write a program that will do the following:
1. In main, declare an array of size 20 and name it "randomArray." Use the function in step 2 to fill the array. Use the function in step 3 to print the array.
2. Create a function that generates 20 random integers with a range of 1 to 10 and places them into an array. Re-cycle the functions from Lab 10 where appropriate.
• Make this a function.
• There will be two arguments in the parameter list of this function: an array and the size of the array.
• Within the function and the function prototype name the array: intArray.
• Within the function and the function prototype name the size of the array: size.
• The data type of the function will be void since the array will be sent back through the parameter list.
• Bring in the function that generates and returns a random number that you created from the previous module. Call that function from this within the loop that adds random numbers to the array.
3. Display the contents of the array. Re-cycle the function that prints out the contents of an integer array from Lab 10.
o Make this a function.
• There will be two arguments in the parameter list of this function: an array and the size of the array.
• Within the function and the function prototype name the array: intArray.
• Within the function and the function prototype name the size of the array: size.
• The data type of the function will be void since the array will be sent back through the parameter list.
4. From main, generate one more random number (also from 1 to 10) from the random number function. Do not put this in an array. This is a stand alone variable that contains one random number.
5. Search though the array and count how many times the extra random number occurs. It is possible that the extra random number may occur more than once or not at all.
Output:
Display the entire array.
Display the extra random number.
Depending upon the result of your search, display one of the following:
How many times the random number occurs.
That the random number did not occur at all.
Also include:
· Use a sentinel driven outer While Loop to repeat the task
• Ask the User if they wish to generate a new set of random numbers
· Clear the previous list of numbers from the output screen before displaying the new set.
NOTE 1: Other than the prompt to repeat the task, there is no input from the User in this program.
NOTE 2: This program will have 3 functions:
1. The function that fills the array with random numbers.
2. The function that generates one random number at a time (re-use the one from Lab 10).
3. The function that prints out an array of integers (re-use the one from Lab 10).
Transcribed Image Text:Lab #11: Write a program that will do the following: 1. In main, declare an array of size 20 and name it "randomArray." Use the function in step 2 to fill the array. Use the function in step 3 to print the array. 2. Create a function that generates 20 random integers with a range of 1 to 10 and places them into an array. Re-cycle the functions from Lab 10 where appropriate. • Make this a function. • There will be two arguments in the parameter list of this function: an array and the size of the array. • Within the function and the function prototype name the array: intArray. • Within the function and the function prototype name the size of the array: size. • The data type of the function will be void since the array will be sent back through the parameter list. • Bring in the function that generates and returns a random number that you created from the previous module. Call that function from this within the loop that adds random numbers to the array. 3. Display the contents of the array. Re-cycle the function that prints out the contents of an integer array from Lab 10. o Make this a function. • There will be two arguments in the parameter list of this function: an array and the size of the array. • Within the function and the function prototype name the array: intArray. • Within the function and the function prototype name the size of the array: size. • The data type of the function will be void since the array will be sent back through the parameter list. 4. From main, generate one more random number (also from 1 to 10) from the random number function. Do not put this in an array. This is a stand alone variable that contains one random number. 5. Search though the array and count how many times the extra random number occurs. It is possible that the extra random number may occur more than once or not at all. Output: Display the entire array. Display the extra random number. Depending upon the result of your search, display one of the following: How many times the random number occurs. That the random number did not occur at all. Also include: · Use a sentinel driven outer While Loop to repeat the task • Ask the User if they wish to generate a new set of random numbers · Clear the previous list of numbers from the output screen before displaying the new set. NOTE 1: Other than the prompt to repeat the task, there is no input from the User in this program. NOTE 2: This program will have 3 functions: 1. The function that fills the array with random numbers. 2. The function that generates one random number at a time (re-use the one from Lab 10). 3. The function that prints out an array of integers (re-use the one from Lab 10).
Program 6
Program #6:
Write a program that adds the following to Lab 11:
• Create a function that will use the BubbleSort to put the numbers in ascending order.
• There will be two arguments in the parameter list of this function: an array and the size of the array.
• Within the function and the function prototype name the array: intArray.
• Within the function and the function prototype name the size of the array: size.
• The data type of the function will be void since the array will be sent back through the parameter list.
Output:
• Display the array after the numbers have been placed in it. It will be unsorted at this point.
• Display the array after it has been sorted. This will display the numbers in ascending order.
NOTE: There is no input from the User in this program.
Transcribed Image Text:Program 6 Program #6: Write a program that adds the following to Lab 11: • Create a function that will use the BubbleSort to put the numbers in ascending order. • There will be two arguments in the parameter list of this function: an array and the size of the array. • Within the function and the function prototype name the array: intArray. • Within the function and the function prototype name the size of the array: size. • The data type of the function will be void since the array will be sent back through the parameter list. Output: • Display the array after the numbers have been placed in it. It will be unsorted at this point. • Display the array after it has been sorted. This will display the numbers in ascending order. NOTE: There is no input from the User in this program.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Linux
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education