Modify the program to be a table and so the entries are to be sorted into ascend
ID: 3621609 • Letter: M
Question
Modify the program to be a table and so the entries are to be sorted into ascending order by customer number.The sort routine should be a function called from your main program.
PROGRAM:
// Electricity Cost Program
#include < iostream >
using namespace std;
//function prototype
double computeCharge(double kilowatts);
int main()
{
double kilowatts[10], charge[10];
int id[10];
int num;
int i=0;
cout<<"Enter number of customer:";
cin>>num;
do
{
cout<<"Enter Customer id:";
cin>>id[i];
if(id[i]<1000)
{
cout<<"Invalid Enter Customer id:";
cin>>id[i];
}
// data input
cout << "Enter the kilowatt-hours used: ";
cin >> kilowatts[i];
//function call to compute
charge[i]=computeCharge(kilowatts[i]);
// display the result
cout.setf(ios::fixed | ios::showpoint);
cout.precision(2);
cout << "The charge for " << kilowatts[i]
<< " kilowatt-hours is $"
<< charge[i]<< endl;
i++;
}while(i<num);
system("pause");
return 0;
}
double computeCharge(double kilowatts)
{
double charge;
// calculate charge for kilowatts-hours
if(kilowatts > 1500)
charge = 0.12*400 + 0.1*600 + 0.08*500+ 0.06*(kilowatts - 1500);
else if (kilowatts > 1000)
charge = 0.12*400 + 0.1*600 + 0.08*(kilowatts - 1000);
else if (kilowatts > 400)
charge = 0.12*400 + 0.1*(kilowatts - 400);
else
charge = 0.12*kilowatts;
return charge+20;
}
Explanation / Answer
Dear, Include this fuction and call in main it works void sortID(int id[],double kilo[],double charge[],int n) { double temp1,temp2; int i,j,min,minat; for(i=0;iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.