Please do not give solution in image format thanku //I'm having issues with my writeTemps function as it wont display my data. Would you please help me debug this and anything else that might need fixing? I really appreaciate your time!! *** PROGRAM DESCRIPTION : *** Read file Temps.txt up to 150 integers, display (five per line), ask user what temp they would like to search for, use linear search, display where it was found (or wasnt), bubble sort into ascending order, display, compute average temp * *** *****************/ #include #include using namespace std; const int MAXSIZE=150; void readFile(int [], int&); void writeTemps(int[], int); void findTemp(int[], int); void sortTemps(int[], int); double computeAvg(int[],int); int main() { int temps[MAXSIZE],count=0; readFile(temps,count); writeTemps(temps,count); findTemp(temps,count); sortTemps(temps,count); writeTemps(temps,count); cout<<"The average temperature is "<> temps[count]) //checks to make sure count is less than maxsize and updates count count ++; inFile.close(); //closes file } void writeTemps(int temps[], int count) { for(int i=0; i"; cin >> searchVal; for (int z = 0; z < count; z++) { if (temps[z] == searchVal) { found = true; cout << "Temperature was located at index " << z << "!" << endl; } } cout << "Temperature is not found ! !" << endl; } while (found == false); return; } void sortTemps(int temps[], int count) { int t; bool swap; do { swap = false; for (int u = 0; u < count - 1; u++) //swaps the biggest number until it's reached ascending order { if (temps[u] > temps[u + 1]) { t = temps[u]; //temporarily holds value temps[u + 1] = t; swap = true; } } } while (swap == true); //loops until swap can no longer occur return; } double computeAvg(int temps[], int count) { int total = 0; double average; for (int a = 0; a < count; a++) total += temps[a]; //adds up each of the integers for a total average = total / count; return average; }
Please do not give solution in image format thanku
//I'm having issues with my writeTemps function as it wont display my data. Would you please help me debug this and anything else that might need fixing? I really appreaciate your time!!
*** PROGRAM DESCRIPTION :
*** Read file Temps.txt up to 150 integers, display (five per line), ask user what temp they would like to search for,
use linear search, display where it was found (or wasnt), bubble sort into ascending order, display, compute average temp
* *** *****************/
#include <iostream>
#include <fstream>
using namespace std;
const int MAXSIZE=150;
void readFile(int [], int&);
void writeTemps(int[], int);
void findTemp(int[], int);
void sortTemps(int[], int);
double computeAvg(int[],int);
int main()
{
int temps[MAXSIZE],count=0;
readFile(temps,count);
writeTemps(temps,count);
findTemp(temps,count);
sortTemps(temps,count);
writeTemps(temps,count);
cout<<"The average temperature is "<<computeAvg(temps,count)<<endl;
return 0;
}
void readFile(int temps[], int& count)
{
ifstream inFile;
inFile.open ("/Users/nadiapinos/Library/Mobile Documents/com~apple~TextEdit/Documents"); //I have to format it like this for Mac
if (!inFile)
{
cout << "Error opening file ! !" << endl; //checks to make sure file can be opened
exit (102);
}
while (count < MAXSIZE && inFile >> temps[count]) //checks to make sure count is less than maxsize and updates count
count ++;
inFile.close(); //closes file
}
void writeTemps(int temps[], int count)
{
for(int i=0; i<count; i++)
{
cout << temps [i] << endl; //print temps in array for counted integers
if (i%5 == 0)cout<<endl; //checks if five are already in line, if so, starts new line
}
cout<<endl;
}
void findTemp(int temps[], int count)
{
bool found=false;
int searchVal;
do //loops until a temperature could be found
{
cout << "Please enter the temperature you wish to find ->";
cin >> searchVal;
for (int z = 0; z < count; z++)
{ if (temps[z] == searchVal)
{
found = true;
cout << "Temperature was located at index " << z << "!" << endl;
}
}
cout << "Temperature is not found ! !" << endl;
} while (found == false);
return;
}
void sortTemps(int temps[], int count)
{
int t;
bool swap;
do
{
swap = false;
for (int u = 0; u < count - 1; u++) //swaps the biggest number until it's reached ascending order
{
if (temps[u] > temps[u + 1])
{
t = temps[u]; //temporarily holds value
temps[u + 1] = t;
swap = true;
}
}
} while (swap == true); //loops until swap can no longer occur
return;
}
double computeAvg(int temps[], int count)
{
int total = 0;
double average;
for (int a = 0; a < count; a++)
total += temps[a]; //adds up each of the integers for a total
average = total / count;
return average;
}
Step by step
Solved in 3 steps with 1 images