Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

29. (20 points) Write the complete C++ program that implements the following pro

ID: 3911580 • Letter: 2

Question

29. (20 points) Write the complete C++ program that implements the following program, as if you were turning this in for homework. Your program should have a commented header (your name, etc), comments within the program and a well-built display for the output. Don't forget the pre-processor commands Define an array called nums with a maximum of 20 integers, and fill the array with numbers, recei the keyboard (prompt for the numbers.) In this program, exactly 20 integers will be input (no need vectors). Then write a function named split0 that accepts the arra positive and negative. This function places all zeros and positiv numbers into negative. Finally, back in the main, have your program only positive and negative. Do not use vectors in any of vour code. The output should look like the following example. You will need to account for in your code that the arrays positive and negative will not necessarily contain 20 numbers. y, along with two other arrays called e numbers into positive and all negative display the values in the array The positive numbers are: 0 4 6 2 100 The negative numbers are: 1 -5 -99-100 -2

Explanation / Answer

code:

#include <cstdlib>
#include<iostream>

using namespace std;
//Function prototype for split
void split(int[],int[],int[]);

//global variable declaration
int ct1=0;
int ct2 =0;

//driver program
int main(int argc, char** argv) {
//declare an array variable to hold the 20 array values
int nums[20];
//array of positive and negative numbers
int positive[20],negative[20];
//Prompt the user to accept 20 values
cout<<" Enter 20 values :";
for(int i = 0; i<20; i++){
cin>>nums[i];
}
//calls the function to split the numbers as positive and negative
split(nums,positive,negative);
  
//displays the positive numbers
cout<<" Positive numbers :";
for(int i = 0; i<ct1; i++){
cout<<positive[i]<<" ";
}
cout<<" NEgative Numbers :";
//displays the negative numbers
for(int i = 0; i<ct2; i++){
cout<<negative[i]<<" ";
}
return 0;
}

//function to split positive and negative numbers
void split(int nums[],int positive[],int negative[]){
for(int i = 0; i<20; i++){
if (nums[i]<0 ){
negative[ct2]=nums[i];
ct2++;
}
else{
positive[ct1] = nums[i];
ct1++;
}
}
}

output:


Enter 20 values :2
3
12
100
25
67
0
-9
8
-7
-6
-5
-4
-3
-100
400
300
11
-34
-65

Positive numbers :2 3 12 100 25 67 0 8 400 300 11
NEgative Numbers :-9 -7 -6 -5 -4 -3 -100 -34 -65
RUN SUCCESSFUL (total time: 38s)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote