Please write the answer in C For this program you will build

Please, write the answer in C+

For this program you will build a modular equation evaluator (you may want to start from your solution to programming assignment 1). Once again you will write a C program that evaluates the equations provided below. The program must prompt the user for inputs to the equations and evaluate them based on the inputs. All variables on the right hand sides of the equations must be inputted by the user. All variables, except for the plaintext_character, encoded_character, and variable a are floating-point values. Theplaintext_character and encoded_character variables are characters, and the a variable is an integer. PI must be defined as a constant macro (#defined constants). Error checking is not required for your program. You do not need to check for faulty user input or dividing by zero.

1. Newton’s Second Law of Motion: force = mass * acceleration

2. Volume of a cylinder: volume_cylinder = PI * radius2 * height

3. Character encoding: encoded_character = (plaintext_character - \'a\') + \'A\' (note: what happens if plaintext_character is lowercase?)

4. Gauss Lens Formula (solve for f): 1 / f = 1 / u + 1 / v, where u is the object distance, v is the image distance, and f is the focal length of the lens

5. Tangent: tan_theta = sin (theta) / cos (theta) (recall: find the appropriate functions in <math.h>)

6. Resistive divider: vout = r2 / (r1 + r2) * vin

7. Distance between two points: distance = square root of ((x1 - x2)2 + (y1 - y2)2) (note: you will need to use sqrt ( ) out of <math.h>)

8. General equation: y = a / (a % 2) - (63 / -17) + x * z (recall: a is an integer; the 63 and -17 constants in the equation should be left as integers initially, but explicitly type-casted as floating-point values)

For this assignment you are required to define, at a minimum, the functions provided below (note: these are your required function prototypes or declarations!):

1. double calculate_newtons_2nd_law (double mass, double acceleration)

2. double calculate_volume_cylinder (double radius, double height)

3. char perform_character_encoding (char plaintext_character)

4. double calculate_gauss_lens (double u, double v)

5. double calculate_tangent (double theta)

6. double calculate_resistive_divider (double r1, double r2, double vin)

7. double calculate_distance_between_2pts (double x1, double y1, double x2, double y2)

8. double calculate_general_equation (int a, double x, double z)

A function must be defined for each of the above function signatures. The task that is performed by each function corresponds directly to the equations defined under the Equations section. For example, the calculate_newtons_2nd_law ( ) function should evaluate the equation defined as force = mass *acceleration and return the resultant force, etc. You must print the results to the hundredths place. Also, the functions should not prompt the user for inputs, nor display the result. Prompts and displaying results should be performed in main ( ).

For this assignment you will need to define three different files. One file, called a header file (.h) needs to be defined which will store all #includes, #defines, and function prototypes/declarations. Name the header file for this assignment equations.h. The second file that needs to be defined is just a C source file. This file should be named equations.c and include all definitions for the above functions. The last file that should be defined is the main.c source file. This file will contain the main ( ) function or driver for the program.

Solution

1. equations.h:

#define PI 3.14159265

double calculate_newtons_2nd_law (double mass, double acceleration);

double calculate_volume_cylinder (double radius, double height);

char perform_character_encoding (char plaintext_character);

double calculate_gauss_lens (double u, double v);

double calculate_tangent (double theta);

double calculate_resistive_divider (double r1, double r2, double vin);

double calculate_distance_between_2pts (double x1, double y1, double x2, double y2);

double calculate_general_equation (int a, double x, double z);

2.equations.c:

#include<math.h>

#include \"equations.h\"

double calculate_newtons_2nd_law (double mass, double acceleration)

{//Newton\'s Second Law of Motion: force = mass * acceleration

   double force;

   force = mass * acceleration;

   return force;

}

double calculate_volume_cylinder (double radius, double height)

{//Volume of a cylinder:       volume_cylinder = PI * radius2 * height

   double volume_cylinder = PI * radius * radius * height;

   return volume_cylinder;

}

char perform_character_encoding (char plaintext_character)

{//Character encoding: encoded_character = (plaintext_character - \'a\') + \'A\'

   char encoded_character = (plaintext_character - \'a\') + \'A\';

   return encoded_character;

}

double calculate_gauss_lens (double u, double v)

{//Gauss Lens Formula (solve for f): 1 / f = 1 / u + 1 / v,

   double f=1/((1/u) - (1/v));

   return f;

}

double calculate_tangent (double theta)

{//Tangent: tan_theta = sin (theta) / cos (theta)

   double tan_theta = sin(theta) / cos(theta) ;

   return tan_theta;

}

double calculate_resistive_divider (double r1, double r2, double vin)

{//. Resistive divider: vout = r2 / (r1 + r2) * vin

   double vout = r2 / (r1 + r2) * vin;

   return vout;

}

double calculate_distance_between_2pts (double x1, double y1, double x2, double y2)

{//Distance between two points: distance = square root of ((x1 - x2)2 + (y1 - y2)2)

   double distance = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));

   return distance ;

}

double calculate_general_equation (int a, double x, double z)

{//General equation: y = a / (a % 2) - (63 / -17) + x * z

   double y = a / (a % 2) - (63 / -17) + x * z ;

   return y;

}

3. main.c:

#include<stdio.h>

#include \"equations.c\"

int main()

{

   int choice=1,a;

   char ch;

   double p,q,u,v;

   while(choice!=0)

   {

     

       printf(\"\ 1. Newton\'s Second Law of Motion\ 2. Volume of a cylinder\ 3. Character encoding\ \");

       printf(\"4. Gauss Lens Formula \ 5. Tangent\ 6. Resistive divider\ 7. Distance between two points\ 8. General equation\");

       printf(\"\ Enter your choice: \");

       scanf(\"%d\",&choice);//read choice

       switch(choice)

       {

           case 1:

               printf(\"\ Enter mass and acceleration\");

               scanf(\"%lf%lf\",&p,&q);//read data

               printf(\"\ Newton\'s Second Law of Motion: force = %f * %f = %f\",p,q,calculate_newtons_2nd_law(p,q));

               break;

           case 2:

               printf(\"\ Enter radius and hieght\");

               scanf(\"%lf%lf\",&p,&q);//read data

               printf(\"\ Volume of a cylinder= %f * %f^2 * %f = %f\",PI,p,q,calculate_volume_cylinder(p,q));

               break;

           case 3:

               printf(\"\ Enter char for encoding: \ \");

               scanf(\" %c\",&ch);

               getchar();//read character

               printf(\"\ Character encoding = (%c - \'a\') + \'A\' = %c\",ch,perform_character_encoding (ch));

               break;

           case 4:

               printf(\"\ Enter u and v: \");

               scanf(\"%lf%lf\",&p,&q);//read data

               printf(\"\ Gauss Lens Formula (solve for f): 1/(1/%f +1/%f) = %f\",p,q,calculate_gauss_lens (p,q));

               break;

           case 5:

               printf(\"\ Enter theta: \");

               scanf(\"%lf\",&p);//read data

               printf(\"\ Tangent: = %f\",calculate_tangent (p));

               break;

           case 6:

               printf(\"\ Enter r1, r2 and vin: \");

               scanf(\"%lf%lf%lf\",&p,&q,&v);//read data

               printf(\"\ Resistive divider: vout = %lf / (%lf + %lf) * %lf = %lf\",q,p,q,v,calculate_resistive_divider (p,q,v));

               break;

           case 7:

               printf(\"\ Enter x1 and y1: \");

               scanf(\"%lf%lf\",&p,&q);//read data

               printf(\"\ Enter x2 and y2: \");

               scanf(\"%lf%lf\",&u,&v);//read data

               printf(\"\ distance = %f\",calculate_distance_between_2pts (p, q, u, v));

               break;

           case 8:

               printf(\"\ Enter a, x and z: \");

               scanf(\"%d%lf%lf\",&a,&u,&v);//read data

               printf(\"\ General equation: y = %d / (%d % 2) - (63 / -17) + %lf * %lf = %lf\",a,a,u,v,calculate_general_equation ( a,u,v));

               break;

           case 0:

               printf(\"exiting......\");

               break;

           default:printf(\"Entered incorrect choice.\");

       }

   }

}

Please, write the answer in C+ For this program you will build a modular equation evaluator (you may want to start from your solution to programming assignment
Please, write the answer in C+ For this program you will build a modular equation evaluator (you may want to start from your solution to programming assignment
Please, write the answer in C+ For this program you will build a modular equation evaluator (you may want to start from your solution to programming assignment
Please, write the answer in C+ For this program you will build a modular equation evaluator (you may want to start from your solution to programming assignment
Please, write the answer in C+ For this program you will build a modular equation evaluator (you may want to start from your solution to programming assignment

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site