Engine Ering Analys IS: Name: Amna Ali Alkhalidi ID:202020019
Engine Ering Analys IS: Name: Amna Ali Alkhalidi ID:202020019
Engine Ering Analys IS: Name: Amna Ali Alkhalidi ID:202020019
ERING
ANALYS
IS
C++
Assignment 1
#include <iostream>
#include <cmath>
int main()
cout << "Enter the x and y coordinates of the first point: ";
cout << "Enter the x and y coordinates of the second point: ";
cout << "The distance between (" << x1 << ", " << y1 << ") and (" << x2 << ", " << y2 << ") is " << distance
<<"KM" <<endl;
return 0;
1|Page
2|Page
2- Find the root of any function. Use Functions:
#include <iostream>
#include <cmath>
int main() {
//Square root of 0
cout << "Square root of 0.15 = " << sqrt(0.15) << endl;
cout << "Square root of -19 = " << sqrt(-19) << endl;
return 0;
3|Page
4|Page
3- Find derivative and integration of a function:
#include <iostream>
#include <functional>
double x1 = Foo(x+mtDx);
double x0 = Foo(x);
return ( x1 - x0 ) / mtDx;
};
return f;
double Foo(double x)
return x*x;
5|Page
double Bar(double x)
return x*x*x;
int main()
6|Page
4- Convert from polar to Cartesian coordinates:
#include <bits/stdc++.h>
double pi = 3.14159;
// coordinate to cartesian
void ConvertToCartesian(
polar.second = ConvertDegToRad(
polar.second);
// x = rcos(theta), y = rsin(theta)
7|Page
pair<double, double> cartesian
= { polar.first * cos(polar.second),
polar.first * sin(polar.second) };
printf("%0.3f, %0.3f",
cartesian.first,
cartesian.second);
// Driver Code
int main()
pair<double,
double>
polar = { 1.4142, 45 };
// coordinates to equivalent
// cartesian coordinates
ConvertToCartesian(polar);
return 0;
8|Page
9|Page
10 | P a g e