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.
Please complete it in C++ Part 2: Queue Create a New Project and give your project...
Please complete it in C++ Part 2: Queue Create a New Project and give your project a name, say Lab6b. Download the given source files StackArr.h, StackArr.cpp, QueueArr.h and QueueArr.cpp from Canvas and save them to your Lab6b folder. Also import them to your project. Add a source file to your project, called QueueMain.cpp and implement your program according to the following: prompt the user to input a string; change each uppercase letter to lowercase; place each letter both in...
Please complete it in C++ Part 1: Stack Create a New Project and give your project...
Please complete it in C++ Part 1: Stack Create a New Project and give your project a name, say Lab6a. Download the given source files StackArr.h and StackArr.cpp from Moodle and save them to your Lab6a folder. Also import them to your project. Add a source file to your project, called StackMain.cpp and implement your program according to the following: Prompt the user to input a program filename. Open the file and check if every right brace (i.e. }), bracket...
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 =...
Instructions Write a program in C++ that create a LookupNames project. In the main function: Ask...
Instructions Write a program in C++ that create a LookupNames project. In the main function: Ask the user to enter a number of names, X to quit input. Store the names in an array. Also use a counter variable to count the number of names entered. Write a function displayNames to display the names. The function must receive the array and the counter as parameters. Write a function called lookupNames. The function must receive the array and the counter as...
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...
Instructions (No array) (c++) (visual studio) 1. Create a project called Project3B 2. Create 3 String...
Instructions (No array) (c++) (visual studio) 1. Create a project called Project3B 2. Create 3 String variables called name1, name2, name3 3. Create 9 double variables called test1_1, test1_2, test1_3, test2_1, test2_2, test2_3, test3_1, test3_2, test3_3 4. Create 3 double variables called average1, average2, average3 To calculate the average score = (test1 + test2 + test3) / 3.0 5. Run the program with the following data using cin name1 = “Tom”, name2 = “Mary”, name3 = “Ali” test1_1 = 81.4,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT