Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A file contains an unknown number of integers that may be positive, negative, or zero. Complete the following C++ program. THe program should read and

A file contains an unknown number of integers that may be positive, negative, or zero. Complete the following C++ program. THe program should read and process the input as follows.

- for each positive integer, compute the sum of its factors, then display the integer and the sum. -compute the exact average of the negative integers -continue reading and processing input until a 0 is encountered (read) -display the average of the negative integers.

Notes: There we be at least one zero in the file, but it may not be the last value in the file. Input will be read via Linux Redirection. The file will exist and not be empty.There will be at least one negative number in the file (do not check for division by 0). DO NOT USE SEPERATE FUNCTIONS.

Sample input file: 19 24 -3 18 11 -16 0 150 Sample output: Sum of the factors for 19 is 20 Sum of factors for 24 is 60 Sum of factors for 18 is 39 Sum of factors for 11 is 12 Average of negative numbers = -9.5 Part of the code: #include using namespace std; int main() { int count = 0; int factorcount = 0; int data; double sum = 0.0; cin >> data; While (data != 0) { } cin >> data; cout << "Average fo negative number #'s = " << sum << endl;

}

}

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

Step: 3

blur-text-image

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

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions