Question

In: Computer Science

Please follow the instructions and solve it by c++ Close the project and create a new...

Please follow the instructions and solve it by c++

Close the project and create a new one called 'Lab0-Part3' with the same options as in the previous step. Write a C++ program that does the following:

  • Creates a 100-element array, either statically or dynamically
  • Fills the array with random integers between 1 and 100 inclusive
  • Then, creates two more 100-element arrays, one holding odd values and the other holding even values.
  • Prints both of the new arrays to the console.

Solutions

Expert Solution

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main() {
    // Creates a 100-element array, either statically or dynamically
    int arr[100];
    // Fills the array with random integers between 1 and 100 inclusive
    srand(time(NULL));
    for (int i = 0; i < 100; ++i) {
        arr[i] = 1 + (rand() % 100);
    }
    // Then, creates two more 100-element arrays, one holding odd values and the other holding even values.
    int odds[100], evens[100], oddCount = 0, evenCount = 0;
    for (int i = 0; i < 100; ++i) {
        if (arr[i] % 2 == 0) {
            evens[evenCount++] = arr[i];
        } else {
            odds[oddCount++] = arr[i];
        }
    }
    // Prints both of the new arrays to the console.
    cout << "Odd array: ";
    for (int i = 0; i < oddCount; ++i) {
        cout << odds[i] << " ";
    }
    cout << endl;
    cout << "Even array: ";
    for (int i = 0; i < evenCount; ++i) {
        cout << evens[i] << " ";
    }
    cout << endl;
    return 0;
}

Related Solutions

Please follow the instructions and solve it by C++. Thank you! What to Submit Submit the...
Please follow the instructions and solve it by C++. Thank you! What to Submit Submit the following: 1) Your .cpp file of the solution. 2) For what n value (approximately) does your computer stop producing output? Why is this? Enter your answer in the 'Comments' field when you submit the file.   So far in our study of recursion we identified a few common recursive number sequences, such as the Fibonacci numbers. Number sequences like this are not recursive algorithms themselves...
Create a C program that simulates time-sharing in the operating system. Please follow the instructions provided:...
Create a C program that simulates time-sharing in the operating system. Please follow the instructions provided: a) Use a circular queue. b) It is required that the process be inputted by the user. The user must input the process name and the duration in seconds, and for this simulation let the user input 5 processes. c) As this requires process name and duration, use an array of structures. d) To simulate time-sharing, following the algorithm presented below: d.1) Use the...
in c++ please follow instructions and fix the errors and please make a comment next to...
in c++ please follow instructions and fix the errors and please make a comment next to each code error you fix. Below are 25 code fragments, inserted into a try catch block. Each line has zero or more errors. Your task is to find and remove all errors in each fragment. Do not fix problems by simply deleting a statement; repair the problems by changing, adding, or deleting a few characters. There may be different ways to fix them You...
please follow the instructions and ASAP. It is a project work. we need to write a...
please follow the instructions and ASAP. It is a project work. we need to write a report about to ::: find a real-life corrosion problem that has not been solved, conduct a thorough investigation as to the cause(s) and type(s) of corrosion, and, finally, propose possible solutions for the problem, indicating which of the solutions is best and why. Submit a report that addresses these issues.
C++ Follow Instructions Please By placing a break in the IIF statement you are using it...
C++ Follow Instructions Please By placing a break in the IIF statement you are using it to force an exit from the WHILE loop. The break statement is only allowed with the SELECT/CASE statement. Also, don't use one structure to force an exit from another. Use the logic from the WHILE loop to end by removing the IF with the break #include <iostream> using namespace std; bool IsMultiple(int,int); int main() { char choice; int n1,n2; bool result; int test =...
Make a C program that simulates time-sharing in the operating system. Please follow the instructions provided:...
Make a C program that simulates time-sharing in the operating system. Please follow the instructions provided: a) Use a circular queue. b) It is required that the process be inputted by the user. The user must input the process name and the duration in seconds, and for this simulation let the user input 5 processes. c) As this requires process name and duration, use an array of structures. d) To simulate time-sharing, following the algorithm presented below: d.1) Use the...
C++ Please. Break it down barney style if possible. Instructions Create a program to keep track...
C++ Please. Break it down barney style if possible. Instructions Create a program to keep track of the statistics for a kid’s soccer team. The program will have a structure that defines what data the program will collect for each of the players. The structure will keep the following data: Players Name (string) Players Jersey Number (integer) Points scored by Player (integer) The program will have an array of 12 players (use less for testing and development, use a constant...
I am having problems making code to follow these parameters. 1. Create a new project and...
I am having problems making code to follow these parameters. 1. Create a new project and class in Eclipse. (5 points) 2. Add a comment with your name(s) on the first line of your code. (5 points) 3. Add the main method to the class. (5 points) 4. Use variables to store three book titles and their authors. (10 points) 5. Use variables to store the price of each book. (10 points) 6. Use variables to store the number of...
Create a new project in BlueJ. Create two new classes in the project, with the following...
Create a new project in BlueJ. Create two new classes in the project, with the following specifications: Class name: Part Fields: id (int) description (String) price (double) onSale (boolean) 1 Constructor: takes parameters partId, partDescrip, and partPrice to initialize fields id, description, and price; sets onSale field to false. Methods: Write get-methods (getters) for all four fields. The getters should be named getId, getDescription, getPrice, and isOnSale.
Please solve by hand A company is investing in a new expansion project which will cost...
Please solve by hand A company is investing in a new expansion project which will cost $180,000 paid over 3 equal payments of $60,000. one payment is due now, one at the end of the first year and one at the end of the 2nd year. The project will start generating revenues of $44,000 per year at the end of the third year and up to and including the 10th year. Minimum Acceptable Rate of Return (MARR) = 8%. Please...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT