Weather, Temperature System-Applications of Programming-C Plus Plus Code, Exercises of Applications of Computer Sciences

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

2011/2012

Uploaded on 08/01/2012

omni
omni 🇮🇳

4.6

(9)

46 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
#include <iostream>
#include <conio.h>
using namespace std;
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;
}
docsity.com
pf2

Partial preview of the text

Download Weather, Temperature System-Applications of Programming-C Plus Plus Code and more Exercises Applications of Computer Sciences in PDF only on Docsity!

#include #include <conio.h> using namespace std;

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; }

docsity.com

// 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; }

docsity.com