63 043
Assignments Done
Successfully Done
In July 2018

Answer to Question #11678 in C++ for Chad Dylan Cooper

Question #11678
Write a program that reads a set of integers (can be +ve or -ve) and then finds and prints the sum of the positive odd integers, negative even integers, and all integers not belonging to the previous two groups. (Use the following as test data: 1,2,3,4,5,-5,-4,-3,-2,-1,18,-18). You must make use a function named sumofNumbers that take an integer number that indicate how many numbers are in the test data and return the results (sum of positive odd integers, sum of negative even integers and sum of all integers which are not belonging to the previous two groups.
Expert's answer

#include <tchar.h>
#include <iostream>
using namespace std;

int* sumofNumbers(int n){
int* data = new int[n];
for(int i = 0; i < n; i++)
& cin >> data[i];
int* result = new int[3];
for(int i = 0; i < 3; i++)
& result[i] = 0;
for(int i = 0; i < n; i++)
& if((data[i] > 0)&&(data[i]%2 ==1))
& result[0] += data[i];
& else if((data[i] < 0)&&(data[i]%2 == 0))
& result[1] += data[i];
& else
& result[2] += data[i];
return result;

int _tmain(int argc, _TCHAR* argv[])
int* result = sumofNumbers(12);
for(int i = 0; i < 3; i++)
& cout << result[i] << endl;

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions