Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help on C++ Homework. Thanks I did the code for function 1- 4 But got confused with the rest . Here is the code

Need help on C++ Homework.

Thanks

image text in transcribed

image text in transcribed

I did the code for function 1- 4 But got confused with the rest .

Here is the code for it below

#include

#include

using namespace std;

void printArray(int array[]) {

for (int i = 0; i

cout

cout

}

cout

}

void oddNums(int array[]) {

int oddTotal = 0;

for (int i = 0; i

if (array[i] % 2 == 1) {

oddTotal += array[i];

}

}

cout

}

void evenNums(int array[]) {

int evenTotal = 0;

for (int i = 0; i

if (array[i] % 2 == 0) {

evenTotal += array[i];

}

}

cout

}

void search(int array[]) {

cout

int key;

cin >> key;

int found = 0;

for (int i = 0; i

if (array[i] == key) {

cout

++found;

}

}

if (found == 0) {

cout

}

}

int main() {

int array[1000];

for (int i = 0; i

array[i] = 1 + rand() % 1000;

}

int choice = 1;

while (choice) {

cout

cout

cout

cout

cout

cout

cin >> choice;

switch (choice){

case 1:

printArray(array);

break;

case 2:

oddNums(array);

break;

case 3:

evenNums(array);

break;

case 4:

search(array);

break;

case 5:

exit(1);

break;

default:

cout

cout

break;

}

}

return 0;

}

LaB aSSIGN MeNT Task 1: Main Function: Declare and fill an array with 1000 random integers between 1 - 1000. You will pass the array into functions that will perform operations on the array. Function 1 create a function that will output all the integers in the array. (Make sure output is clearly formatted. Function 2: create a Function that will sum and output all the odd numbers in the array. Function 3: create a Function that will sum and output all the even numbers in the array. Function 4: create a function that will allow the user to enter an integer value to search. Program will output if integer value is found and the location of the integer in the array. or The program wil output "value is not in array". ("value is not in array should not be printed more than once.") Function 5 create a function that will output the highest value in the array

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data, Mining, And Analytics Components Of Strategic Decision Making

Authors: Stephan Kudyba

1st Edition

1466568704, 9781466568709

More Books

Students also viewed these Databases questions