Write a C program that evaluates the equations provided below. The program must
ID: 3743677 • Letter: W
Question
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, variable a, shift, R1, R2, and R3 are floating-point values. The plaintext_character and encoded_character variables are characters, and the a, shift, R1, R2, and R3 variables are integers. The constant 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. However, please consider inputs that could cause your program to work incorrectly.
Newton’s Second Law of Motion: force = mass * acceleration
Volume of a cylinder: volume_cylinder = PI * radius2 * height
Character encoding: encoded_character = (plaintext_character - 'A') + 'a' - shift; shift is an integer (note: what happens if plaintext_character is uppercase? What happens with various shift keys?)
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>)
Tangent: tan_theta = sin (theta) / cos (theta) (recall: find the appropriate functions in <math.h>)
Equivalent parallel resistance: parallel_resistance = 1 / (1 / R1 + 1 / R2 + 1 / R3), for 3 resistors. R1, R2, and R3 are integers.
General equation: y = (2 / 3) - y + z * x / (a % 2) + PI (recall: a is an integer; the 2 and 3 constants in the equation should be left as integers initially, but explicitly type-casted as floating-point values)
All coding is done in Visual studios using C++
Explanation / Answer
Program is as follows-
#include <stdio.h>
#include <math.h>
#define PI 3.14
int main()
{
float force,mass,acceleration;
float volume_cylinder,radius,height;
char encoded_character,plaintext_character;
int shift;
float distance;
float x1,x2,y1,y2;
float sin_theta,cos_theta,tan_theta,theta;
float parallel_resistance;
int R1,R2,R3;
int a;
float x,z,y=0;
//Newton’s Second Law of Motion: force = mass * acceleration;
printf("Newton's second law of motion: Force = mass * acceleration ");
printf("Enter mass- ");
scanf("%f",&mass);
printf("Enter acceleration- ");
scanf("%f",&acceleration);
force = mass * acceleration;
printf("Force = %.2f ",force);
//Volume of a cylinder: volume_cylinder = PI * radius2 * height;
printf("Volume of a cylinder: volume_cylinder = PI * radius2 * height ");
printf("Enter radius- ");
scanf("%f",&radius);
printf("Enter height- ");
scanf("%f",&height);
volume_cylinder = PI * pow(radius,2) * height;
printf("Volume = %.2f ",volume_cylinder);
//Character encoding: encoded_character = (plaintext_character - 'A') + 'a' - shift;
printf("Character encoding: encoded_character = (plaintext_character - 'A') + 'a' - shift ");
printf("Enter a plaintext_character- ");
scanf(" %c",&plaintext_character);
printf("Enter the value of shift(here shift is an integer)- ");
scanf("%d",&shift);
encoded_character = (plaintext_character - 'A') + 'a' - shift;
printf("Encoded character = %c ",encoded_character);
//Distance between two points: distance = square root of ((x1 - x2)2 + (y1 - y2)2);
printf("Distance between two points: distance = square root of ((x1 - x2)2 + (y1 - y2)2) ");
printf("Enter the value of x1- ");
scanf("%f",&x1);
printf("Enter the value of x2- ");
scanf("%f",&x2);
printf("Enter the value of y1- ");
scanf("%f",&y1);
printf("Enter the value of y2- ");
scanf("%f",&y2);
distance = sqrtf(pow((x1-x2),2) + pow((y1-y2),2));
printf("Distance = %.2f ",distance);
//Tangent: tan_theta = sin (theta) / cos (theta);
printf("Tangent: tan_theta = sin (theta) / cos (theta) ");
printf("Enter an angle in radians- ");
scanf("%f",&theta);
tan_theta = sin(theta) / cos(theta);
printf("Tan_theta = %.2f ",tan_theta);
//Equivalent parallel resistance: parallel_resistance = 1 / (1 / R1 + 1 / R2 + 1 / R3), for 3 resistors;
printf("Equivalent parallel resistance: parallel_resistance = 1 / (1 / R1 + 1 / R2 + 1 / R3), for 3 resistors ");
printf("Enter the value of resistance R1- ");
scanf("%d",&R1);
printf("Enter the value of resistance R2- ");
scanf("%d",&R2);
printf("Enter the value of resistance R13- ");
scanf("%d",&R3);
parallel_resistance = (1 / ((1.0/R1)+(1.0/R2)+(1.0/R3)));
printf("parallel_resistance = %f ",parallel_resistance);
//General equation: y = (2 / 3) - y + z * x / (a % 2) + PI;
printf("General equation: y = (2 / 3) - y + z * x / (a % 2) + PI ");
printf("Enter the value of x- ");
scanf("%d",&x);
printf("Enter the value of z- ");
scanf("%d",&z);
printf("Enter the value of a- ");
scanf("%d",&a);
float temp = (float)2/3;
y = ( temp + z * x / (a % 2) + PI )*0.5;
printf("Answer of the equation y = %f",y);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.