In this c++ program, explain every line of this program. Please thank you Source Code: #include using namespace std; int main() { //printing the statements as mentioned cout<<"The function is f(x)= 2x+3(2)"<<"\n"; cout<<"Width is 0.05"<<"\n"; //declaring variables of float datatype float lowLim,upperLim; //asking user for input cout<<"Enter Lower Limit: "; //taking input for lowLim cin>>lowLim; //asking user for input cout<<"Enter Upper Limit: "; //taking input for upperLim cin>>upperLim; //declaring variables iterations,initAns,i float iterations,initAns,i; //calculating number of iterations iterations=(upperLim-lowLim)/0.05; //declaring i=0 i=0; //declaring variable finAns of float datatype float finAns=0; //loop for iterations while(i
In this c++ program, explain every line of this program. Please thank you
Source Code:
#include<bits/stdc++.h>
using namespace std;
int main()
{
//printing the statements as mentioned
cout<<"The function is f(x)= 2x+3(2)"<<"\n";
cout<<"Width is 0.05"<<"\n";
//declaring variables of float datatype
float lowLim,upperLim;
//asking user for input
cout<<"Enter Lower Limit: ";
//taking input for lowLim
cin>>lowLim;
//asking user for input
cout<<"Enter Upper Limit: ";
//taking input for upperLim
cin>>upperLim;
//declaring variables iterations,initAns,i
float iterations,initAns,i;
//calculating number of iterations
iterations=(upperLim-lowLim)/0.05;
//declaring i=0
i=0;
//declaring variable finAns of float datatype
float finAns=0;
//loop for iterations
while(i<iterations)
{
//printing in required format
cout<<"_________________________________________________________________________________________________________________________________\n";
//printing Iteration number
cout<<"Iteration: "<<i+1<<"\n";
//printing upper and lower limit of present Iteration
cout<<"Function\t\t|\tLower Limit \t|\t Upper Limit \t|\t LRAM Application (width=0.05) \t|\t Answer\n";
//calculating value of initAns
initAns=((2*lowLim)+(3*2))*0.05;
//printing values of lowLim,Upper limit,value of function and answer for this Iteration
printf("f(x)= 2x+3(2) \t\t|\tx= %.2f\t\t|\tx=%.2f\t\t|\t f(x) = (2(%.2f)+3(2) * 0.05\t|\t %.2f\n",lowLim,lowLim+0.05,lowLim,initAns);
//adding value of this iteration to the final answer
finAns+=initAns;
//incrementing value of lowLim by 0.05
lowLim+=0.05;
//incrementing i by 1
i+=1;
}
//printing in required format
cout<<"_________________________________________________________________________________________________________________________________\n";
//printing final answer to the console
printf("Final answer/Summation of all iterations is: %f\n",finAns);
return 0;
}

Step by step
Solved in 2 steps









