Answer to Question #183988 in C++ for Bilal

Question #183988

Comment this code line by line in simple english

Comment each line



include <iostream>
 
#include <cmath>
 
using namespace std;
 
 
main(void)
 
{
 
    float x1=2,y1=3,x2=6,y2=9;
 
    float Dist;
 
 
    Dist = sqrt(pow(x1-x2,2) + pow(y1-y2,2));
 
    cout<<"\nPoint-1: ("<<x1<<", "<<y1<<")";
 
    cout<<"\nPoint-2: ("<<x2<<", "<<y2<<")";
 
    cout<<"\n\nDistance between the points: "<<Dist;
 
    return(0);
 
}
 
1
Expert's answer
2021-04-21T12:42:39-0400
// using preproccessor directive `include` add code 
// from the header iostream 
// (contain definition of output/input streams, etc)
// to this compilation unit 
#include <iostream>
// using preproccessor directive `include` add code 
// from the header cmath
// (contain definition of math stuff like: sqrt, pow, etc )
// to this compilation unit 
#include <cmath>

// make all functions/types from namespace std:: 
// visible in this scope 
using namespace std;
 
// define main function which is entry point of any program
main(void)
// start main function body
{
    // define 4 single precision floating-point variables on the stack
    // They represent 2 2D points: (2, 3), (6, 9)
    float x1=2,y1=3,x2=6,y2=9;
    // define another float variable to keep distance
    float Dist;
 
    // calculate distance between points 
    // distance = square root of sum in (...)
    Dist = sqrt(pow(x1-x2,2) + pow(y1-y2,2));
    // print to standard output (it's console here) point1 
    cout<<"\nPoint-1: ("<<x1<<", "<<y1<<")";
 
    // print to standard output (it's console here) point2 
    cout<<"\nPoint-2: ("<<x2<<", "<<y2<<")";
    
    // print to standard output distance between points 
    cout<<"\n\nDistance between the points: "<<Dist;
    
    // return from the function with 0 code 
    // (which means success of program execution)
    return(0);
// end main fucntion body
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS