Objective: This assignment is a grab bag of practice problems with an emphasis o
ID: 3852213 • Letter: O
Question
Objective: This assignment is a grab bag of practice problems with an emphasis on strings, vectors, and File Input/Output and more practice with functions. Specification: Write functions to perform the indicated task. Most of the functions are short and can be written in a handful of lines. Each function should use the most optimal solution. Please test your functions within main). Leave all your test code active in main) so it can be reviewed in a hanful of lines. Each function should use the most optimal solution. Please test yourExplanation / Answer
16
double degreesToRadian(double degrees) {
degrees = fmod(degrees,360);
return 3.14159265359 * degrees / 180;
}
17
struct cpair {
double x;
double y;
};
double findSlope (struct cpair a, struct cpair b) {
double slope;
slope = (b.y - a.y)/(b.x - a.x);
return slope;
}
double findYIntercept(struct cpair a, struct cpair b) {
double c;
double m = findSlope(a,b);
c = a.y - m * a.x;
return c;
}
18
void rectangle (struct cpair a, struct cpair b, double *length, double *breadth, double *area) {
*length = abs(a.x - b.x);
*breadth = abs(a.y - b.y);
*area = (*length) * (*breadth);
}
I hode you like it! If you have any doubt or query on this, please feel free to comment below. I shall be glad to help.
--------------------------------------EDIT---------------------------------------------------
#include<iostream>
#include<cmath>
using namespace std;
double degreesToRadian(double degrees) {
degrees = fmod(degrees,360);
return 3.14159265359 * degrees / 180;
}
struct cpair {
double x;
double y;
};
double findSlope (struct cpair a, struct cpair b) {
double slope;
slope = (b.y - a.y)/(b.x - a.x);
return slope;
}
double findYIntercept(struct cpair A, struct cpair B) {
double b;
double m = findSlope(A,B);
b = A.y - m*A.x;
return b;
}
void rectangle (struct cpair a, struct cpair b, double *length, double *breadth, double *area) {
*length = abs(a.x - b.x);
*breadth = abs(a.y - b.y);
*area = (*length) * (*breadth);
}
int main() {
double degree;
cout << "Enter degree: ";
cin >> degree;
cout << "Radian= " << degreesToRadian(degree) << endl;
struct cpair A, B;
cout << "Enter x and y of point A: ";
cin >> A.x >> A.y;
cout << "Enter x and y of point B: ";
cin >> B.x >> B.y;
cout << "Slope of line: " << findSlope(A,B) << endl;
cout << "Y intercept of line: " << findYIntercept(A,B) << endl;
double l,b,a;
rectangle(A,B, &l, &b, &a);
cout << "length of rect: " << l << endl;
cout << "breadth of rect: " << b << endl;
cout << "area of rect: " << a << endl;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.