Question
code must be c++ thank you
This assignment is about array operations. You need to count a specific items in an array. Steps to follow are here: • Create
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here's the c++ code with necessary comments.

# include <iostream>
using namespace std;

int main() {
    // if srand() is not set, rand() always generates the same number as rand seed is alwys the same.
    srand(time(0));
    int k, arr[1000], count = 0;
    
    for (int i = 0; i < 1000; i++) {
        // generate a random number and insert it into array
        // generate a number from 0 - 200 and then subtract 100 from it
        // so that the range is now (-100, 100)
        arr[i] = rand() % (201) - 100;
    }
    
    cout << "The array with 1000 random items is ready...\n\n";
    
    cout << "Enter a number: ";
    cin >> k;
    
    while (k <= 100 && k >= -100) {

        for (int i = 0; i < 1000; i++) {
            // check if arr[i] is k
            if (arr[i] == k) {
                count ++;
            }
        }
        
        cout << "\nFrequency of " << k << ": " << count;
        
        // to read the next k
        cout << "\n\nEnter a number: ";
        cin >> k;
    }
    
    return 0;
}

Find the output in the screenshot below.

Run Code Untitled Save C++ - Output: Finished Clear Console Finished in 0 ms The array with 1000 random items is ready... Ent

Add a comment
Know the answer?
Add Answer to:
code must be c++ thank you This assignment is about array operations. You need to count...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This assignment is about array operations. You need to count a specific items in an array....

    This assignment is about array operations. You need to count a specific items in an array. Steps to follow are here: • Create an array with 1000 items and fill it with random numbers from the range of -100, 100 (including - 100 and 100). . In your program asks user to enter a number, K. • Search this number and print the frequency (how many) of this K is found in the array. • Ask another number, and so...

  • write c++ program This assignment is about array operations. You need to count a specific items...

    write c++ program This assignment is about array operations. You need to count a specific items in an array. Steps to follow are here: . Create an array with 1000 items and fill it with random numbers from the range of -100, 100 (including -100 and 100). In your program asks user to enter a number, K. Search this number and print the frequency (how many) of this K is found in the array. • Ask another number, and so...

  • In C++ 1. Write a program that allows a user to enter 10 integer values from...

    In C++ 1. Write a program that allows a user to enter 10 integer values from the keyboard. The values should be stored in an array. 2. The program should then ask the user for a number to search for in the array: The program should use a binary search to determine if the number exists in a list of values that are stored in an array (from Step #1). If the user enters a number that is in the...

  • 1. Write a C code that do the following: Generate array of random integer numbers of...

    1. Write a C code that do the following: Generate array of random integer numbers of size 25 Fill the array with random integers ranging from [1-100] Find the maximum number of the array and its location Find the minimum number of the array and its location Search for a number in the array Print the array Flip the array Sort this array Quit the program when the user choose to exit

  • Write a C++ program that prompts the user with the following menu options: Erase-ArrayContent Count-Words Quit...

    Write a C++ program that prompts the user with the following menu options: Erase-ArrayContent Count-Words Quit 1. For Erase-ArrayContent option, write complete code for the C++ function Erase described below. The prototype for Erase function is as follow: void Erase( int a[ ], int * N, int * Search-Element) The function Erase should remove all occurrences of Search-Element from the array al). Note that array a[ ] is loaded with integer numbers entered by the user through the keyboard. N...

  • The purpose of this assignment is to get experience with an array, do while loop and...

    The purpose of this assignment is to get experience with an array, do while loop and read and write file operations. Your goal is to create a program that reads the exam.txt file with 10 scores. After that, the user can select from a 4 choice menu that handles the user’s choices as described in the details below. The program should display the menu until the user selects the menu option quit. The project requirements: It is an important part...

  • ASSIGNMENT: Create a program to do the following: BONUS: A bonus of 20 points if you create the p...

    ASSIGNMENT: Create a program to do the following: BONUS: A bonus of 20 points if you create the program in such a way that there is no limit on the number of names to be handled. 1) Read in names to sort until the user types the “enter” key as the first character of a “C-type” string (the maximum number of names is 20, there is not a maximum length to a name), using a two dimensional array of characters....

  • Please complete this code for java Lab Write a program as follows: Create an array with...

    Please complete this code for java Lab Write a program as follows: Create an array with 10 elements. The array should contain numbers generated randomly between 1 and 100 Ask the user to enter any number - Search the array to see if the user entered number is in the array If the user-entered number is in the array, print a 'match found' message. Also print at which index the match was found, else print a 'match not found' message...

  • (C programing, Not C++) Write a program in C that asks the user to input 10...

    (C programing, Not C++) Write a program in C that asks the user to input 10 numbers. Store these numbers in an array. Then ask the user to input a single number. Your program should execute a linear search on the array, trying to find that number. If the number exists in the array, have the program print out which position/element the number was found at. If the target number is not in the array, have the program print out...

  • Write in C# Programming Language.   - count =0; - Create a 2d array "items". string[,] items...

    Write in C# Programming Language.   - count =0; - Create a 2d array "items". string[,] items = new string[100, 4]; - Create a do while loop, when user enter "0", stop the loop. - User enter item name, price, quantity, save these info and subtotal to array. - increase "count++" -conver price(decimal, Convert.ToDecimal() ) and quantity(int) to do mulplication for subtotal - create a for loop (with count ) to cycle through the "items", display item name, price, quantity, and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT