Question:
Problem Statement:
Temperature Calculation system
Write a program that
displays average, highest and lowest temperatures.
Detailed Description:
- The program will take temperature readings as input from user for specifiednumber of consecutive days.
- Program will store these temperature values into an array.
- Then it will pass this array to three different functions.
- One function will return highest temperature, one will return lowesttemperature and third one will return average temperature.
- All these functions will be called inside main() function where thesetemperature results will be displayed to the user.Enter the number ofconsecutive days to read their temperature : 5Enter temperature for day 1:50Enter temperature for day 2: 80
Enter temperature for day
3: 30
Enter temperature for
day 4: 92
Enter temperature for
day 5: 47
The
average temperature is 59.80
The
highest temperature is 92.00 The
lowest temperature is 30.00
NOTE:
The array
containing temperature values must be passed to three different functions
to return average, highest and lowest temperatures. Marks will
be deducted if assignment is solved with some other technique.
Solution:
#include <cstdlib>
#include <iostream>
#include <iostream>
void high_Tenp(int [],int);
void low_Tenp(int []);
void Average_Tenp(int [],int);
using namespace std;
int main(int argc, char *argv[])
{
{
cout<<"\t\t***********************************"<<endl
<<"\t\t TEMPRATURE CALCULATION SYSTEM "<<endl
<<"\t\t***********************************"<<endl<<endl;
int n;
<<"\t\t TEMPRATURE CALCULATION SYSTEM "<<endl
<<"\t\t***********************************"<<endl<<endl;
int n;
cout<<"Enter
the number of consecutive days to read theirtemperature :
";
cin>>n;
int x[n];
int i, j, tmp;
for(i=0;i<n;i++)
{
{
cout<<endl<<"Enter temperature for
day "<<i+1<<" : ";
cin>>x[i];
}
for(i=0; i<n; i++)
{
{
for(j=0; j<n-1; j++)
{
{
if (x[j] > x[j+1])
{
{
tmp = x[j];
x[j] = x[j+1];
x[j+1] = tmp;
}
}
}
Average_Tenp(x,n);
high_Tenp(x,n);
low_Tenp(x);
system("pause");
}
void high_Tenp(int a[],int
arraysize)
{
cout<<"The Higest Temprature is : "<<a[arraysize-1]<<endl;
}
{
cout<<"The Higest Temprature is : "<<a[arraysize-1]<<endl;
}
void low_Tenp(int a[])
{
int b=0;
cout<<"The Lowest Temprature is : "<<a[b]<<endl;
}
{
int b=0;
cout<<"The Lowest Temprature is : "<<a[b]<<endl;
}
void Average_Tenp(int a[],int
arraysize)
{
int i;
{
int i;
double c=0;
for ( i = 0 ; i < arraysize ; i
++)
{
c=c+a[i];
}
c=c/i;
cout<<endl<<"The Average Temprature is : "<<c<<endl;
}
{
c=c+a[i];
}
c=c/i;
cout<<endl<<"The Average Temprature is : "<<c<<endl;
}
void swap(int *x, int *y)
//function using pointers to interchange the values
{
int tmp;
if(*x > *y)
{
tmp = *x;
*x = *y;
*y = tmp;
}
}
0 comments:
Post a Comment