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...
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...
Create a new “Area” project. Create a new Visual Studio Project and call it “Area”. This...
Create a new “Area” project. Create a new Visual Studio Project and call it “Area”. This project will be used to calculate the area of certain figures, like circles, squares and rectangles. So add a title to the Form. The Form Title should say “Area”. Also add 3 labels, 3 Buttons, 3 Textboxes and 3 RadioButtons. The 3 Buttons should be near the bottom of the Form and say “Calc Area”, “Clear” and “Exit”. Make sure to give all your...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT