Question

In: Computer Science

C++ Please read the question carefully and make sure that the function prototypes given are used...

C++

Please read the question carefully and make sure that the function prototypes given are used correctly for both parts. This is one whole programming assignment so please make sure that it;s answered entirely not just one part.

The output example is provided at the end of the question.

First , write a program to create an array and fill it up with 20 randomly generated integers between 0 to 10 and output the array.

Part 1:
Write a function to implement following function prototype:
void search( int array [], int length, int key);
Precondition: Function accepts an integer array, the size of the array, and a key to search.
Post condition: Function outputs the key value and a message whether or not the key exists in the
array. If the key exists, function outputs the number of occurrence of the key in the array.

Part 2:
Write a function to sort the array in Descending order (from largest to smallest) and output the
result.
You should implement the following function prototype!!
void selectionSort( int list[], int length);

Output:

1 7 0 5 0 6 3 8 8 9

8 0 9 8 0 1 8 9 8 7

0 was found! the number of occurence is 4

50 not found!

9 9 9 8 8 8 8 8 8 7

7 6 5 3 1 1 0 0 0 0

Solutions

Expert Solution

#include<iostream>
#include <time.h>
#include <stdlib.h>

void search(int array[], int length, int key)
{
   int occ=0;
   for(int i=0;i<length;i++)
   {
       if(array[i]==key) occ++;
   }
  
   if(occ>0)cout <<key<<" was found!the number of occurence is "<<occ;
}
void selectionSort(int list[], int length)
{
   int min,loc,temp;
   for(int i=0;i<length;i++)
   {
       min=list[i];
loc=i;
for(int j=i+1;j<length;j++)
{
if(min<list[j])
{
min=list[j];
loc=j;
}
}

temp=list[i];
list[i]=list[loc];
list[loc]=temp;
   }
   cout <<"\nSorted array\n";
   for(int i=0;i<length;i++) cout <<list[i]<<" ";
  
}

/* Main function */
int main()
{
   int array[10];
   srand (time(NULL));
   /* generate random nos*/
for(int i=0;i<20;i++) array[i]=rand() % 10;
  
for(int i=0;i<20;i++) cout <<array[i]<<" ";
  
cout << endl;
  
search(array,20,0);
selectionSort(array,20);

}


Related Solutions

C++ Please read the question carefully and match the output example given at the end! Question...
C++ Please read the question carefully and match the output example given at the end! Question In this project you will implement operator overloading for a two dimensional Vector class. Begin with the declaration of the Vector class on the final page. There are three operators that must be overloaded insertion (​<<​), addition (​+​), and subtraction (​-​). insertion (​<<​): The insertion operator is used to send the values of a vector to an ostream object, if a vector has two...
Instructions: Please read problem carefully. Write the answers on the answer sheets provided. Make sure that...
Instructions: Please read problem carefully. Write the answers on the answer sheets provided. Make sure that you clearly show all of the work that went in to solving the problem. Partial credit will be awarded on each part of the problem, so make sure that you attempt each part. You are the marketing manager for TotalControl, an electronics company in Orangeburg. Your company produces a line of remote controls for use in home theaters. The company’s main product, the UR...
Please make sure to read the instructions carefully! Must use P8! (A) Write the following assembly...
Please make sure to read the instructions carefully! Must use P8! (A) Write the following assembly language program. Start at 6 and counts down by 2 to 0. (No Loops!) Comment each line except STOP and .END. Add something to the output that makes this program uniquely yours. Cut and paste the Assembler Listing into your document. (B) Paste a screenshot of the Output area of the Pep8. (C) Explain the status bits NZVC at the point STOP is loaded....
Please explain each step very carefully and make sure your handwriting is easy to read. Thank...
Please explain each step very carefully and make sure your handwriting is easy to read. Thank you Question: Suppose p(x) is a polynomial of degree n with coefficients in R and suppose p(x) has exactly n real roots. Show that p'(x) has exactly n-1 real roots.
Read each question carefully, make sure to answer all questions are answered and show your work:...
Read each question carefully, make sure to answer all questions are answered and show your work: 5. Nast stores has derived the following consumer credit-scoring model after years of data collect Y=(0.20 x Employment) + (0.4 x Homeowner) + (0.3 x Cards) Employment = 1 if employed part-time, and 0 if unemployed Cards= 1 if presently has 1-5 credit cards, 0 otherwise Nast determines that a score of at least 0.70 indicates a very good credit risk, and it extends...
The Programming Language is C++ PLEASE, Make sure to read the requirements and grading criteria for...
The Programming Language is C++ PLEASE, Make sure to read the requirements and grading criteria for homework first... Thank you!!! Objective: The purpose of this project is to expose you to: One-dimensional parallel arrays, input/output, Manipulating summation, maintenance of array elements. In addition, defining an array type and passing arrays and array elements to functions. Problem Specification: Using the structured chart below, write a program to keep records and print statistical analysis for a class of students. There are three...
Please Read Carefully Before start answering this question. Please follow the instructions. This Question is from...
Please Read Carefully Before start answering this question. Please follow the instructions. This Question is from 'BSBFIM501 Manage budgets and financial plans' course. There are no parts missing for this Question; guaranteed!. This is the original Screenshot direct from the question. Therefore, there are nothing any further information can be provided. Thanks for your understanding and Cooperation. Please answer the following questions from the topics discussed for Prepare, implement, monitor and modify contingency plans: 1.a. Explain the process of preparing...
Please make sure to complete all parts of the question and to show all work used...
Please make sure to complete all parts of the question and to show all work used to compute the answer so I can see how the answer was found. A five-year annuity of 10 $5,230 semiannual payments will begin nine years from now, with the first payment coming nine and a half years from now. If the discount rate is 10 percent compounded monthly, what is the value of this annuity five years from now? What is the value three...
Please read the question carefully and relate the situation to the type of antagonist with reasoning...
Please read the question carefully and relate the situation to the type of antagonist with reasoning During anaphylaxis, massive quantities of histamine are released, causing vasodilation that leads to bronchoconstriction. The emergency treatment for anaphylaxis is adrenaline, which causes vasoconstriction that leads to bronchodilation. What type of antagonist/antagonism does this represent? (Physiological, pharmacokinetic, chemical, irreversible, competitive). The thing that confuses me is how to come to the conclusion of what the drug is doing? I'm wondering does adrenaline react with...
Please answer this using MATLAB (Not c or c++) and make sure to provide proper commenting:...
Please answer this using MATLAB (Not c or c++) and make sure to provide proper commenting: a. Write a function that writes a series of random Fahrenheit temperatures and their corresponding Celsius temperatures to a tab-delimited le. Use 32 to 212 as your temperature range. From the user, obtain the following: 1) The number of temperatures to randomly generate. 2) The name of the output file. b. Write a function that reads a file produced by part (a). Focusing only...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT