Answer To: Brief Documentation Guide Comments must be used to document the problem the code solves. You...
Snehil answered on May 11 2020
main.c
#include
#include
//defining value for PI (11 digit precision)
#define PI 3.14159265358
//Function prototypes
void calculate_impedance(double* result_table_impedance_real, double* result_table_impedance_imag, int components[], double values[], int n, int freq, int choice);
void print_results(double * result_table_impedance_real, double* result_table_impedance_imag,
double * result_table_current_real, double* result_table_current_imag,
double * result_table_voltage_real, double* result_table_voltage_imag, int n, int components[]);
void complex_addition(double in1_real, double in1_imag, double in2_real, double in2_imag, double* out3_real, double* out3_imag);
void complex_subtraction(double in1_real, double in1_imag, double in2_real, double in2_imag, double* out3_real, double* out3_imag);
void complex_multiplication(double in1_real, double in1_imag, double in2_real, double in2_imag, double* out3_real, double* out3_imag);
void complex_division(double in1_real, double in1_imag, double in2_real, double in2_imag, double* out3_real, double* out3_imag);
char* get_signed_brackets_value(char* s, double num);
char* get_component_unit(char*s, int component_type);
char get_component_initial(int component_type);
//main function
int main()
{
int n;//number of components
int* components;//component types
double* values;//component sizes
int choice;//user choice
int freq;//frequency
int source_voltage;//source voltage
printf("**%d %s**", 3777777, "John Smith Assignment 2");
do// loop to get user choice, runs till user provides valid choice
{
printf("\nDo you want to create a 1.Parallel or 2.Series circuit evaluation? ");
scanf("%d",&choice);
if(!(choice==1 || choice==2))
{
printf("Invalid Selection\n");
}
}while(!(choice==1 || choice==2));
//get user input for frequency, source voltage and number of components
printf("Enter the frequency in Hertz of the source: ");
scanf("%d",&freq);
printf("Enter the source voltage: ");
scanf("%d",&source_voltage);
printf("How many components are in %s: ",choice==1?"parallel":"series");
scanf("%d",&n);
//assigning memory to various pointers based on number of components
double* result_table_impedance_real= malloc(sizeof(double)*(n+1));
double* result_table_impedance_imag= malloc(sizeof(double)*(n+1));
double* result_table_current_real= malloc(sizeof(double)*(n+1));
double* result_table_current_imag= malloc(sizeof(double)*(n+1));
double* result_table_voltage_real= malloc(sizeof(double)*(n+1));
double* result_table_voltage_imag= malloc(sizeof(double)*(n+1));
components = malloc(sizeof(int)*n);
values = malloc(sizeof(double)*n);
int i;
char s[12];
//get user input for component types and sizes
printf("\nEnter the component type for each component where 1 is Resistor, 2 is Capacitor and 3 is Inductor.\n");
for(i=0;i {
printf("Component %d: ",i+1);
scanf("%d",components+i);
printf("Enter the size of the component in %s: ",get_component_unit(s,components[i]));
scanf("%lf",values+i);
}
//calling function to calculate impedance
calculate_impedance(result_table_impedance_real,result_table_impedance_imag,components,values, n, freq, choice);
...