ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 28 Apr 2017 My Price 8.00

a modification of the program done in CISS 241

Assignment 2

This program will be a modification of the program done in CISS 241, Week 7 Programming Assignment 1. That was the Rainfall Statistics program. For those who did not take 241, that program description is below. Modify the Rainfall Statistics program so that it displays a list of months, sorted in the order of rainfall from highest to lowest.

 

I keep getting errors and can't figure out why.  I've declared the variables, int and strings but later in the code it states not declared.  

Rainfall isn't sorted properly and continues to give me numbers at the end of the month between 0 and 11, instead of the entered rainfall amounts.  Please help.

 

 

// Week 1 Assignment 2
// Anthony J. Bamber
/*
This program will be a modification of the program done in CISS 241, Week 7
Programming Assignment 1. That was the Rainfall Statistics program. For those
who did not take 241, that program description is below. Modify the Rainfall
Statistics program so that it displays a list of months, sorted in the order
of rainfall from highest to lowest.
*/
#include<iostream>
#include<string>
#include<cfloat>
using namespace std;
double getTotal(double, int);
double getAverage(double, int);
double getLowest(double, int, int&); //returns the lowest value, provides the
index of the lowest value in the last parameter.
double getHighest(double, int, int&); //returns the highest value, provides
the index of the highest value in the last parameter.
void showOrder(double rainFall, string months, const int AMT, int index);
void dualSort(double rainFall, string months, const int AMT);
int main()
{
//Variables
const int AMT = 12;
int lowIndex = 0;
int highIndex = 0;
double lowRainfall = 0;
double highRainfall = 0;
double rainfall[AMT];
string months[AMT] =
{ "January","February","March","April","May","June","July","August","September",
"October","November","December" };
int count;
for (count = 0; count < AMT; count++)
{
cout << "Enter rain fall for " << months[count] << " : ";
cin >> rainfall[count];
while (rainfall [count] < 0)
{
cout << "You entered a number that is below 0, please enter a
number that is above 0." << endl;
cin >> rainfall[count];
}
}
lowRainfall = getLowest(rainfall, 12, lowIndex);
highRainfall = getHighest(rainfall, 12, highIndex);
cout << "The total rainfall for the year : " << getTotal(rainfall, 12) <<
endl; cout << "The average monthly rainfall : " << getAverage(rainfall, 12) << endl;
getHighest(rainfall, 12, highIndex);
getLowest(rainfall, 12, lowIndex);
cout << "The month with the highest amount of rainfall : " <<
months[highIndex] << endl;
cout << "The month with the lowest amount of rainfall : " << months[lowIndex] << endl;
cout << "Months sorted in decending order of rainfall: " << endl;
for (int i = 1; i < 13; i++)
{
highRainfall = getHighest(rainfall, 12, highIndex);
cout << months[highIndex] << "(" << highRainfall << ")" << endl;
rainfall[highIndex] = -1;
}
system("pause");
return 0;
}
double getTotal(double rainfall, int n)
{
double totalFall = 0;
for (int i = 1; i<n; i++)
totalFall += rainfall[i];
return totalFall;
}
double getAverage(double rainfall, int n)
{
double total = getTotal(rainfall, n);
return total / n;
}
double getLowest(double rainfall, int n, int& index) //returns the lowest
value, provides the index of the lowest value in the last parameter.
{
double min = rainfall[0];
index = 0;
for (int i = 1; i<n; i++)
{
if (rainfall[i]<min)
{
min = rainfall[i];
index = i;
}
}
return min;
}
double getHighest(double rainfall, int n, int& index) //returns the highest
value, provides the index of the highest value in the last parameter.
{
double max = rainfall[0];
index = 0;
for (int i = 1; i < n; i++)
{
if (rainfall[i] > max)
{
max = rainfall[i];
index = i;
}
}
return index;
// Function to show the order
void showOrder(double rainFall, string months, const int AMT, int
index)
cout << "\nMonth \t\t Rainfall amount\n";
cout << "-------------------------------"; for (int index = 0; index < AMT; index++);
{
cout << "\n" << months[index] << "\t";
cout << setw(8) << rainfall[index] << endl;
}
cout << endl;
}
// Dual Sort function
void dualSort(double rainFall, string months, const int AMT)
{
int startScan, maxIndex, tempID;
string maxValue;
for (startScan
{
maxIndex
maxValue
tempID = = 0; startScan < (AMT - 1); startScan++)
= startScan;
= months[startScan];
rainFall[startScan]; for (int index = startScan + 1; index < AMT; index++)
{
if (months[index] > maxValue)
{
maxValue = months[index];
tempID = rainFall[index];
maxIndex = index;
} } } } months[maxIndex] = months[startScan];
rainFall[maxIndex] = rainFall[startScan];
months[startScan] = maxValue;
rainFall[startScan] = tempID;

Answers

(11)
Status NEW Posted 28 Apr 2017 06:04 AM My Price 8.00

-----------

Not Rated(0)