please write code for me first i have a inputfile named in8.txt file it is inclu
ID: 3659696 • Letter: P
Question
please write code for me first i have a inputfile named in8.txt file
it is include below values
------------------------
3.8
5.2
4.7
6.3
3.9
-1.07
.91
2.16
3.4
1.55
2.0
3.7
------------------------
output on the screen must be
-------------------------
YEARLY RAINFALL CALCULATIONS
Please enter the name of the input file a:in8.txt <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /?>
Please enter the name of the output file a:out8.txt
Rainfall amount was negative, 0 amount used.
Enter a value to count rainfalls less than
or equal to amount 4
The number of months this year with rainfalls
less than or equal to 4.00 is 9.
Programmer: insert your name here
Processing complete
Press any key to continue...
---------------------------------------------
in a output file( out8.txt)
it must be
---------------------------------------------
Output file: (named out8.txt)
YEARLY RAINFALL CALCULATIONS
Month Rainfall(in inches)
January 3.80
February 5.20
March 4.70
April 6.30
May 3.90
June 0.00
July 0.91
August 2.16
September 3.40
October 1.55
November 2.00
December 3.70
The yearly rainfall sorted from highest to lowest:
Month Rainfall(in inches)
April 6.30
February 5.20
March 4.70
May 3.90
January 3.80
December 3.70
September 3.40
August 2.16
November 2.00
October 1.55
July 0.91
June 0.00
The total rainfall for the year is 37.62 inches.
The average monthly rainfall is 3.14 inches.
The highest rainfall of 6.30 occurred in April
The lowest rainfall of 0.00 occurred in June
Programmer: insert your name here
-----------------------------------------
1. you should use a least 4 functions
2.bubble sort funtionand parallel array must be used
3.out out on the screen and txt file must be exact same as given
4.when value is negative number it must be replaced by 0.
5.find minimum and maximum by using sort funtion.
please help thank you
Explanation / Answer
please rate - thanks
I am messageing you the sample run, input and output files
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
void getData(double[],istream&);
void print(double[],int[],string,ostream&);
void sort(double[],int[]);
double getSum(double[]);
void outData(double,double[],int[],ostream&);
void getLess(double[]);
int main()
{char filename[30];
double rain[12],sum;
int mon[12];
double average;
int i;
for(i=0;i<12;i++)
mon[i]=i;
cout<<"Please enter the name of the input file ";
cin>>filename;
ifstream input;
input.open(filename); //open file
if(input.fail()) //is it ok?
{ cout<<"file did not open please check it ";
system("pause");
system("exit");
}
cout<<"Please enter the name of the output file ";
cin>>filename;
ofstream output;
output.open(filename);
getData(rain,input);
print(rain,mon,"YEARLY RAINFALL CALCULATIONS",output);
sort(rain,mon);
print(rain,mon,"The yearly rainfall sorted from highest to lowest:",output);
sum=getSum(rain);
outData(sum,rain,mon,output);
getLess(rain);
cout<<"Programmer: ";
input.close();
output.close();
system("pause");
return 0;
}
void getLess(double rain[])
{double val;
int i,c=0;
cout<<"Enter a value to count rainfalls less than or equal to amount: ";
cin>>val;
for(i=0;i<12;i++)
if(rain[i]<val)
c++;
cout<<"The number of months this year with rainfalls less than or equal to ";
cout<<setprecision(2)<<fixed<<val<<" is "<<c<<". ";
}
void outData(double sum,double rain[],int mon[],ostream& output)
{string months[12]={"January","February","March","April","May","June","July",
"August","September","October","November","December"};
output<<"The total rainfall for the year is "<<sum<<" inches. ";
output<<"The average monthly rainfall is "<<sum/12<<" inches. ";
output<<"The highest rainfall of "<<setprecision(2)<<fixed<<rain[0]<<" occurred in "<<months[mon[0]]<<endl;
output<<"The lowest rainfall of "<<setprecision(2)<<fixed<<rain[11]<<" occurred in "<<months[mon[11]]<<endl;
output<<"Programmer: ";
}
double getSum(double rain[])
{int i;
double sum=0;
for(i=0;i<12;i++)
sum+=rain[i];
return sum;
}
void print(double rain[],int mon[],string message,ostream& output)
{string months[12]={"January","February","March","April","May","June","July",
"August","September","October","November","December"};
int i;
output<<message<<" Month Rainfall(in inches) ";
for(i=0;i<12;i++)
output<<left<<months[mon[i]]<<" "<<setprecision(2)<<fixed<<rain[i]<<endl;
}
void sort(double rain[],int mon[])
{double tp;
int t,i,j;
for(i=0;i<11;i++)
for(j=i;j<12;j++)
if(rain[i]<rain[j])
{tp=rain[i];
rain[i]=rain[j];
rain[j]=tp;
t=mon[i];mon[i]=mon[j];
mon[j]=t;
}
}
void getData(double rain[],istream& input)
{int i;
for(i=0;i<12;i++)
{
input>>rain[i];
if(rain[i]<0)
{ rain[i]=0;
cout<<"Rainfall amount was negative, 0 amount used. ";
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.