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" ; } }
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
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" ;
}
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images
Knowledge Booster
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.Recommended textbooks for you
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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education