Program 6: Sums and Averages. Assigned Wednesday, 10/05/16 Program Due Wednesday, 10/12/16 , at start of class. Write a program in c++ that asks the user to input a list of numbers, one at a time, until the user is finished. The program should keep track of how many numbers, how many positive numbers, and how many negative numbers were entered. It should also calculate the sums for each of these (positives, negatives, and total). After exiting the loop, the program should calculate the averages for each (positives, negatives, and total). Then output the sums and their averages, with labels describing each output appropriately. Note that there may be no positives, or no negatives, or no numbers at all in a list! Also, a 0 counts as a number in the overall list, but it doesn't counts as positive or negative. Allow the user to enter as many lists as they like. Note that there is no data check for a bad number -- any integer is valid! Data to test/run: --------------------------------------------------------------- Dataset 1: (empty) --------------------------------------------------------------- Dataset 2: 10 -13 0 26 -17 --------------------------------------------------------------- Dataset 3: -10 -20 -45 --------------------------------------------------------------- Dataset 4: 10 30 80 --------------------------------------------------------------- Dataset 5: 0 0 0 ---------------------------------------------------------------
Program:
#include<iostream>
using namespace std;
int main()
{
int num, NoOfPositiveNumbers=0,NoOfNegativeNumbers=0,
TotalNumbers=0;
float sumOfPositives=0,sumOfNegatives=0,total=0;
float avgOfPositives=0,avgOfNegatives=0,avg=0;
bool repeat =true;
//read numbers from user until the user enters 77777(
5 sevens)
//i used 77777 as sentinel value to exit the
loop
cout<<"Enter numbers (77777 to exit): ";
do
{
cin>>num;
//check if number enter is not
sentinel and if number is negative
//if so increment the count of
negatives and add it to sum of negatives
//also get the total here
if(num<0 &&
num!=77777)
{
NoOfNegativeNumbers=NoOfNegativeNumbers+1;
sumOfNegatives=sumOfNegatives+num;
total=total+num;
TotalNumbers=TotalNumbers+1;
}
//check if number enter is not
sentinel and if number is positive
//if so increment the count of
positives and add it to sum of positives
//also get the total here
else if(num>0 &&
num!=77777)
{
NoOfPositiveNumbers=NoOfPositiveNumbers+1;
sumOfPositives=sumOfPositives+num;
total=total+num;
TotalNumbers=TotalNumbers+1;
}
//check if number enter is not
sentinel and if number is 0
//if so increment the count of
total
else if(num==0 &&
num!=77777)
{
TotalNumbers=TotalNumbers+1;
total=total+num;
}
//if sentinel value is entered exit
the loop
else if(num==77777)
{
repeat=false;
}
}while(repeat);
//calculate the averages and display results
if(TotalNumbers>0)
{
if(NoOfPositiveNumbers==0)
{
avgOfPositives=0;
}
else
{
avgOfPositives=sumOfPositives/NoOfPositiveNumbers;
}
if(sumOfNegatives==0)
{
avgOfNegatives=0;
}
else
{
avgOfNegatives=sumOfNegatives/NoOfNegativeNumbers;
}
avg=total/TotalNumbers;
cout<<"\nTotal Numbers:
"<<TotalNumbers<<"\tSum:
"<<total<<"\tAverage: "<<avg;
cout<<"\nTotal Positives:
"<<NoOfPositiveNumbers<<"\t"<<"Sum of Positives:
"<<sumOfPositives<<"\tAverage of Positives:
"<<avgOfPositives;
cout<<"\nTotal Negatives:
"<<NoOfNegativeNumbers<<"\t"<<"Sum of Negatives:
"<<sumOfNegatives<<"\tAverage of Negatives:
"<<avgOfNegatives;
}
else
{
cout<<"\nThe dataset is
empty.";
}
return 0;
}
Output:





Program 6: Sums and Averages. Assigned Wednesday, 10/05/16 Program Due Wednesday, 10/12/16 , at start of...
Positive and negative: Return these four results using C++ reference parameter Write a function, named sums(), that has two input parameters; an array of floats; and an integer, n, which is the number of values stored in the array. Compute the sum of the positive values in the array and the sum of the negative values. Also count the number of positives and negative numbers in each category. Write a main program that reads no more than 10 real numbers...
Using basic c++ 2. Count the positive and negative numbers using ***while loop*** • Write a program that reads unspecified number of integers , determines how many negative and positive values have been read. Also calculate total and average. Your program will end with input 0. • Output Enter an integer, the input ends if it is 0: 25 34 -89 72 -35 -67 21 48 0 The number of positives is 5 The number of negatives is 3 The...
Java programming 1. Write a program that reads an unspecified number of integers, determines how many positive and negative value have been read, and computes the total and average of the input values (not counting zeros. Your program ends with the input 0. Display the average as a floating point number Here are sample runs: (red indicates a user input) Enter an integer, the input ends if it is 0: 1 2 -1 3 0 The number of positives is...
Use Python 3
11a is using the binary search program that counts steps amend
the program so that a list of size 10000 is made - using unique
random numbers in the range 1 through 20000. Test how many steps to
find the number 9467.
Using your solution to Lab 11A, write a program that counts how many steps to find the number 9467 in a list of size 20000 (using unique random numbers in the range 1 through 321000)....
C++ Programming Help Please! NOTE: Please READ All Steps very carefully. DO #10! (10 is based off of 9). Program Info: #9. Write a program that reads in ten whole numbers and that outputs the sum of all the numbers greater than zero, the sum of all the numbers less than zero (which will be a negative number or zero), and the sum of all the numbers, whether positive, negative, or zero. The user enters the ten numbers just once...
I need help writing these 2 programs please include all the indents :) In this programming challenge you are to create two Python programs: randomwrite.py andrandomread.py. One program, randomwrite.py, is to write a set of random numbers to a file. The second program, randomread.py, is to read a set of random numbers from a file, counts how many were read, displays the random numbers, and displays the total count of random numbers. Random Number File Writer (randomwrite.py) Create a program...
10) Write a program that inputs five numbers and determines the number of negative numbers input, the number of positive numbers input and the number of zeros input. An easy way to create a counter is given in the example below: int counter 0; initializes the counter counter counter +1;//increments the counter each time is used. Note: Output should read as shown below where # replaces the number of inputs and it is displayed on a table format] (40 pts.)...
Write a program that calculates the average of a stream of non-negative numbers. The user can enter as many non-negative numbers as they want, and they will indicate that they are finished by entering a negative number. For this program, zero counts as a number that goes into the average. Of course, the negative number should not be part of the average (and, for this program, the average of 0 numbers is 0). You must use a method to read...
You will be given a file that will contain averages for classes which are divided into sections in the following format. The name of this file will be "grades.txt". A 93B 82A 86C 75 F 83 You are to write a program that computes the averages for the sections of classes, they are divided into groups that are denoted by a capital letter. You are to use arrays to calculate the average. I recommend using two arrays one to keep...
In python please.. Problem 4 (Tracking Statistics – Part 1) Write a program that repeatedly asks the user to enter an integer until they want to quit (e.g., by entering ‘q’). The program should then print the largest number entered, the smallest number entered, the average of all numbers entered, the number of positive numbers entered, and the number of negative numbers entered (0 should not count as positive or negative). Problem 5 (Tracking Statistics – Part 2) Copy your...