Write a program with C++ that can be used by the Texas Levy System to track how
ID: 3559565 • Letter: W
Question
Write a program with C++ that can be used by the Texas Levy System to track how much the river has risen with the rain that has fallen in a course of a year. It should have a 12-emelent array of structures, where each structure holds a date and the number of inches of water the levy has risen by the rainfall in that month. The program should have the user input the name of the month, the starting and ending month of the 12 month period being measured, and then the inches of rain the levy has raised in each of the 12 months. The program should then sort the data in ascending order by the base depth and display the results it should also have a class.
Explanation / Answer
Here is the C++ code for given problems.which takes month and water rise in input and sort them in ascending order.
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
struct levy{
string month;
int rise ;
} ;
class C
{
public :
levy data[12];
};
bool compare(struct levy a, struct levy b) {
return a.rise < b.rise ;
}
int main(){
string m ;
int r ;
C myclass;
for(int i=0;i<12;i++){
cout<<" Enter month and water rise ";
cin >> m>> r;
myclass.data[i].month = m ;
myclass.data[i].rise = r ;
}
sort(myclass.data, myclass.data+12, compare);
for(int i=0;i<12;i++){
cout << myclass.data[i].month << " "<<myclass.data[i].rise<<" " ;
}
system("pause ");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.