

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Applications of different concepts in programming are in this code. These can be used in learning C plus plus. It includes: Include, Temperature, Store, Array, Defination, Return, Float, Return, Average
Typology: Exercises
1 / 2
This page cannot be seen from the preview
Don't miss anything!


#include
int getMaxTemp(int[],int); // function to calcualte Maximum Temprature int getMinTemp(int[],int); // function to calculate Minimum Temprature float getAvgTemp(int[],int); // function to calculate Average Temprature
main() { int NDays; cout<<"Enter the number of consecutive days to read their temperature : "; cin>>NDays; if(NDays<=0){ cout<<"Please Enter number of days greater than 0!"<<endl; system("pause"); return 0; }
int Cday[NDays]; // array to store temprature for(int i=0;i<NDays;i++){ cout<<endl<<"Enter temperature for day "<<i+1<<": "; cin>>Cday[i]; }
cout<<endl<<"The average temperature is "<<getAvgTemp(Cday,NDays); cout<<endl<<"The highest temperature is "<<getMaxTemp(Cday,NDays); cout<<endl<<"The lowest temperature is "<<getMinTemp(Cday,NDays); cout<<"\n\n"; system("PAUSE"); return EXIT_SUCCESS; }
// function defination of calculating maximum temprature
int getMaxTemp(int data[],int length){ int max=data[0]; for(int i=0;i<length;i++) if(max<data[i]) max=data[i]; return max; }
// function defination of calculating minimum temprature
int getMinTemp(int data[],int length){ int min=data[0]; for(int i=0;i<length;i++) if(min>data[i]) min=data[i]; return min; }
// function defination of calculating average temprature float getAvgTemp(int data[],int length){ float total=0; float avg = 0; for(int i=0;i<length;i++) total+=data[i]; avg = total/length; return avg; }