Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This program is C not C++ or C# In this exercise you will build a small library

ID: 3722090 • Letter: T

Question

This program is C not C++ or C#

In this exercise you will build a small library of utility functions by implementing the following functions with the given prototypes and specified functionality · int degreesToRadians (double degree, double *radians) -write a function to convert degrees to radians using the formula 180 The function should place the computed value into the radians variable, which is passed by reference. The return value should indicate an error code: 0 for no error, 1 for any type of error NULL pointers, or an invalid degree which should be on the scale [0, 360 int compute the annual percentage yield given an annual percentage rate using the fol- lowing formula annualPercentageYield(double double *apy) -this function should · apr, variable, which is The function should place the computed value into the apy passed by reference. The return value should indicate an error code: 0 for no error, 1 for any type of error (NULL pointers, or an invalid APR which should be on the scale [0, 1] . int getAirDistance (double latA, double longA, double latB, double longB, double *distance) this function should compute the air distance between the two locations given by their latitude/longitude. The latitude and longitude are on the scale -180, 180] (negative values are southern and western hemisphere). The air distance between two latitude/longitude points can be calculated with the Spherical Law of Cosines d = arccos (sin(A ) sin(P2) + cos(A) cos(p) cos(A) ) . R where -p 1 is the latitude of location A, P2 is the latitude of location B is the difference between location B's longitude and location A's longitude - R is the (average) radius of the earth, 6,371 kilometers

Explanation / Answer

main.cpp

#include<iostream>

#include "./Library.h"

using namespace std;

int main(){

double d = 90, *rad;

//Degrees to Radians

if(degreesToRadians(d,rad)==0)

cout<<*rad<<endl;

else{

cout<<"Conversion failed";

}

return 0;

}

Library.h

#include <iostream>

#include <cmath>

typedef enum {

AVERAGE,

LIGHTNESS,

LUMINOUSITY

} Mode;

int degreesToRadians(double degree, double *radians)

{

if (degree >= 0 && degree <= 360 && radians != NULL)

{

*radians = (degree * M_PI) / 180;

return 0;

}

return 1;

}

int annualPercentageYield(double apr, double *apy)

{

if (apr >= 0 && apr <= 1 && apy != NULL)

{

*apy = pow(M_E, apr) - 1;

return 0;

}

return 1;

}

int getAirDistance(double latA, double longA, double latB, double longB, double *distance)

{

if (latA >= -90 && latA <= 90 && latB >= -90 && latB <= 90 && longA >= -180 && longA <= 180 && longB >= -180 && longB <= 180 && distance != NULL)

{

*distance = acos(sin(latA) * sin(latB) + (cos(latA) * cos(latB) * cos(longB - longA))) * 6371;

return 0;

}

return 1;

}

double max(double r, double g, double b)

{

if (r >= g)

{

if (r >= b)

return r;

else

return b;

}

else

{

if (g >= b)

return g;

else

return b;

}

}

int min(int r, int g, int b)

{

if ((r < g) && (r < b))

return r;

else

{

if (g < b)

return g;

else

return b;

}

}

int rgbToCMYK(int r, int g, int b, double *c, double *m, double *y, double *k)

{

if (r >= 0 && r <= 255 && g >= 0 && b <= 255 && b >= 0 && b <= 255 && c != NULL && m != NULL && y != NULL && k != NULL)

{

double r_d = r / 255, g_d = g / 255, b_d = b / 255;

*k = 1 - max(r_d, g_d, b_d);

*c = (1 - r_d - *k) / (1 - *k);

*m = (1 - g_d - *k) / (1 - *k);

*y = (1 - b_d - *k) / (1 - *k);

return 0;

}

return 1;

}

int cmykToRGB(double c, double m, double y, double k, int *r, int *g, int *b)

{

if (c >= 0 && c <= 1 && m >= 0 && m <= 1 && y >= 0 && y <= 1 && k >= 0 && k <= 1 && r != NULL && g != NULL && b != NULL)

{

*r = 255 * (1 - c) * (1 - k);

*g = 255 * (1 - m) * (1 - k);

*b = 255 * (1 - y) * (1 - k);

return 0;

}

return 1;

}

int toGrayScale(int *r, int *g, int *b, Mode m)

{

if (r != NULL && g != NULL && b != NULL)

{

if (m == AVERAGE)

{

*r = (*r + *g + *b) / 3;

*g = *b = *r;

}

else if (m == LIGHTNESS)

{

*r = max(*r, *g, *b) + min(*r, *g, *b);

*g = *b = *r;

}

else if (m == LUMINOUSITY)

{

*r = 0.21 * (*r) + 0.72 * (*g) + 0.07 * (*b);

*g = *b = *r;

}

return 0;

}

return 1;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote