Skip to content

Commit

Permalink
added and modified
Browse files Browse the repository at this point in the history
  • Loading branch information
jesushilarioh committed Jun 4, 2020
1 parent 328c09a commit 1e6773d
Show file tree
Hide file tree
Showing 29 changed files with 2,754 additions and 813 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*
*************************************************************/
#include <iostream>
#include <vector>
using namespace std;

// Global constants
Expand All @@ -26,9 +27,9 @@ double inputValidate(double);
void getValues(double []);
double average(double);
double calculateTotal(double []);
int findHighestMonth(double []);
int findLowestMonth(double []);
void display(double, double, int, int);
void findHighestMonths(double [], vector<int> &);
void findLowestMonths(double [], vector<int> &);
void display(double, double, vector<int>, vector<int>);


int main()
Expand All @@ -39,9 +40,14 @@ int main()

double total_rainfall = calculateTotal(rainfall);
double avarage_rainfall = average(total_rainfall);
int highest_month = findHighestMonth(rainfall);
int lowest_month = findLowestMonth(rainfall);
display(total_rainfall, avarage_rainfall, highest_month, lowest_month);

vector<int>highest_months;
findHighestMonths(rainfall, highest_months);

vector<int>lowest_months;
findLowestMonths(rainfall, lowest_months);

display(total_rainfall, avarage_rainfall, highest_months, lowest_months);

return 0;
}
Expand Down Expand Up @@ -87,48 +93,59 @@ double average(double sum)
return sum / ARRAY_SIZE;
}

int findHighestMonth(double array[])
void findHighestMonths(double array[], vector<int> &vector_array)
{
double max = array[0];
int index = 1;
vector_array.push_back(0);

for (int i = 1; i < ARRAY_SIZE; i++)
{
if(array[i] >= max)
if(array[i] > max)
{
max = array[i];
index = (i + 1);
vector_array.clear();
vector_array.push_back(i);
}
else if (array[i] == max)
{
max = array[i];
vector_array.push_back(i);
}

}

return index;
}

int findLowestMonth(double array[])
void findLowestMonths(double array[], vector<int> &vector_array)
{
double min = array[0];
int index = 1;
vector_array.push_back(0);

for (int i = 1; i < ARRAY_SIZE; i++)
{
if(array[i] <= min)
if(array[i] < min)
{
min = array[i];
index = (i + 1);
vector_array.clear();
vector_array.push_back(i);
}
else if (array[i] == min)
{
min = array[i];
vector_array.push_back(i);
}


}

return index;
}

void display(double total, double average, int highest, int lowest)
void display(double total, double average, vector<int> highest_months, vector<int> lowest_months)
{
string months[] = {"January", "February", "March",
"April" , "May" , "June",
"July" , "August" , "September",
"October", "November", "December"};
const string MONTHS[] = {"January", "February", "March",
"April" , "May" , "June",
"July" , "August" , "September",
"October", "November", "December"};

cout << "\nTotal rainfall for the year = "
<< total
Expand All @@ -139,15 +156,27 @@ void display(double total, double average, int highest, int lowest)
<< endl;

cout << "Month with highest amount = ";
for (int i = 0; i < ARRAY_SIZE; i++)

for (int i = 0; i < highest_months.size(); i++)
{
if (highest == (i + 1))
cout << months[i];
if(i == highest_months.size() - 1)
cout << MONTHS[highest_months[i]];
else
cout << MONTHS[highest_months[i]] << ", ";

}

cout << endl;

cout << "Month with lowest amount = "
<< lowest
<< endl;
cout << "Month with lowest amount = ";

for (int i = 0; i < lowest_months.size(); i++)
{
if(i == lowest_months.size() - 1)
cout << MONTHS[lowest_months[i]];
else
cout << MONTHS[lowest_months[i]] << ", ";
}

cout << endl;
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
#include <iostream>
using namespace std;

// Global constants

// Function Prototypes
void greaterNumbers(int[], const int, int);
void greaterNumbers(const int[], int, int);

int main()
{
Expand All @@ -29,19 +27,19 @@ int main()
26, 27, 28, 29, 30};
int n = 20;

cout << "All numbers greater that " << n << " are: ";
greaterNumbers(numbers_array, ARRAY_SIZE, n);
cout << endl;

return 0;
}

/********************************************************
* void greaterNumbers(): prints numbers greater that n
********************************************************/
void greaterNumbers(int array[], const int ARRAY_SIZE, int n)
void greaterNumbers(const int array[], int ARRAY_SIZE, int n)
{
cout << "All numbers greater that "
<< n
<< " are: ";


for (int i = 0; i < ARRAY_SIZE; i++)
{
Expand All @@ -56,5 +54,4 @@ void greaterNumbers(int array[], const int ARRAY_SIZE, int n)

}

cout << endl;
}
Loading

0 comments on commit 1e6773d

Please sign in to comment.