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...
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 =...
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...
HW_6a - Read a text file Create a new C++ project and name it as:   Numbers...
HW_6a - Read a text file Create a new C++ project and name it as:   Numbers Create a text file and     save it as:   data.txt Create and save the file      in a C++ project      in the Resource folder. Enter the following numbers:        3                                                              4                                                              5       Note:   After you enter the 5, don’t press the enter key. Save and close the file. Add another file and name it:   Source.cpp Write one statement that declares a file...
HW_6d - Write a struct object to a binary file. Create a new C++ project and...
HW_6d - Write a struct object to a binary file. Create a new C++ project and name it as:   Cats Create a Source.cpp file. Declare a struct named Cat. (in the Source.cpp file, or in a separate header file) Each Cat object has a name and age. The name data member is a c_string. The age data member is an integer. Ask the user to enter 3 cats. Use a while loop to read the information about one cat entered...
Instructions: Solve the following problem. To receive credit, readers must be able to follow your logic...
Instructions: Solve the following problem. To receive credit, readers must be able to follow your logic and you must explain each step in detail. Please label each step, identify each equation and variable, and explain your answer. The management of a mutual fund plans to sell a basket of stocks in three months. The stocks are similar to the S&P 500. It seeks protection against a decrease in the price of the stocks. The current price of the S&P 500...
Please! I want the instructions of how to solve it, not the answer. Write a program...
Please! I want the instructions of how to solve it, not the answer. Write a program that does the following in order: 1. Asks the user to enter a name 2. Asks the user to enter a number “x” 3. Asks the user to enter a number “y” 4. Calculates the sum of “x” and “y” 5. Prints out the number for “x”, “y” and “sum” An example of the program input and output is shown below: Enter your name:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT