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

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter14: Exception Handling
Section: Chapter Questions
Problem 14SA
icon
Related questions
Question

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

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning