Hi, I need help with a program that I\'m completely stuck with. Sorry for it bei
ID: 3649407 • Letter: H
Question
Hi, I need help with a program that I'm completely stuck with. Sorry for it being soo long, but I'm really stuck here.The assignment is as stated:
Write a program that will:
1. Call a function to input temperatures for consecutive days in 1D array. NOTE: The temperatures will be integer numbers. There will be no more than 10 temperatures.
The user will input the number of temperatures to be read. There will be no more than 10 temperatures.
2. Call a function to sort the array by ascending order. You can use any sorting algorithm you wish as long as you can explain it.
3. Call a function that will return the average of the temperatures. The average should be displayed to two decimal places.
Sample Run:
Please input the number of temperatures to be read
5
Input temperature 1:
68
Input temperature 2:
75
Input temperature 3:
36
Input temperature 4:
91
Input temperature 5:
84
Sorted temperature array in ascending order is 36 68 75 84 91
The average temperature is 70.80
The highest temperature is 91.00
The lowest temperature is 36.00
In my program, I chose to use the "bubble sort" format to organize my program. I had this program running when I had the bubble sort in the main function, without some errors where "0"s were appearring in random places. After trying to put the "bubble sort" into another function, I'm completely lost with what I'm suppose to do next. Please help.
****************************This is what I currently have *******************
#include <iostream>
#include <cstdlib>
using namespace std;
int temp();
const int SIZE = 10;
int hold = -1;
int main()
{
int number;
int i;
int temperature[SIZE];
cout << "Please input the number of temperatures to be read, where a limit of 10 can be " << endl;
cout << "inputted:" << endl;
cin >> number;
for (i = 0; i < number; i++)
{
cout << "Input temperature " << i << ":" << endl;
cin >> temperature[i];
}
cout << endl;
temp();
for (int j = 1; j <= number; j++)
{
cout << temperature[j] << " ";
}
cout << endl;
return 0;
}
int temp(int number, int temperature[SIZE])
{
int length = number;
int end = number;
for (int counter = length - 1; counter > 0; counter--)
{
for (int h = 0; h < number; h++)
{
if (temperature[h] > temperature[h+1])
{
hold = temperature[h+1];
temperature[h+1] = temperature[h];
temperature[h] = hold;
}
}
for (int j = 0; j < number; j++)
{
cout << temperature[j] << " ";
}
cout << endl;
end--;
}
return temperature[SIZE];
}
Explanation / Answer
#include //#include #include using namespace std; void sort(int arr[],int size) { int temp=arr[0]; for (int i=0;iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.