Advertisement
DarK_Camper

main.c SECS

Apr 14th, 2015
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.21 KB | None | 0 0
  1. //Header Files
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <ctype.h>
  5. #include <string.h>
  6. #include <math.h>
  7. #include <assert.h>
  8.  
  9. #include "get_input.h"
  10. ///////////////////////////////////////
  11. //===================================//
  12. //       Function Declarations       //
  13. //===================================//
  14. ///////////////////////////////////////
  15. void clear_screen();
  16. void output_print_dkc(int topology, double effective_resistance, double effective_voltage, double effective_current);
  17.  
  18. ///////////////////////////////////////
  19. //===================================//
  20. //           Main Function           //
  21. //===================================//
  22. ///////////////////////////////////////
  23. int main()
  24. {
  25.     ///////////////////////////////////////
  26.     //===================================//
  27.     //       Variable Declarations       //
  28.     //===================================//
  29.     ///////////////////////////////////////
  30.  
  31.     //Input Values
  32.     int topology;
  33.     int source_type;
  34.     double source_value;
  35.     int resist_no;
  36.     //Declaration of Resistor Value arrays |down|
  37.  
  38.     //Effective Values
  39.     double effective_resistance;
  40.     double effective_voltage;
  41.     double effective_current;
  42.  
  43.  
  44.     ///////////////////////////////////////
  45.     //===================================//
  46.     //      Variable Initialization      //
  47.     //===================================//
  48.     ///////////////////////////////////////
  49.  
  50.     /*===================================
  51.     ||           Input Values          ||
  52.     ===================================*/
  53.     //Topology
  54.     topology = get_topology();//get_input.c
  55.     printf("\n");
  56.  
  57.     //Source
  58.     source_type  = get_source_type();//get_input.c
  59.     printf("\n");
  60.     source_value = get_source_value();//get_input.c
  61.     printf("\n");
  62.  
  63.  
  64.     //Resistors
  65.     resist_no = get_resist_no();//get_input.c
  66.     printf("\n");
  67.     printf("DEBUG: %d\n",resist_no);
  68.  
  69.     //Declaration of Resistor Value arrays |here|
  70.     double resistor_values[resist_no];
  71.      printf("DEBUG: %d\n",resist_no);
  72.  
  73.     //Resistor Values
  74.     int i;
  75.     printf("Please Input the Values of each Resistor: DEBUG: %.6f",get_resist_value());
  76.     for(i=0;i<resist_no;i++){
  77.         printf("\n\tPlease input the value of Resistor #%d: ",i+1);
  78.         resistor_values[i]=get_resist_value(); //Here's the problem============================================<<<<<<<<<<<<<<+++++
  79.     }
  80.     printf("\n");
  81.  
  82.  
  83.     printf("DEBUG: Topology: %d\n\tSourceType: %d\n\tSourceValue: %.2f\n\tResistanceNumber: %d\n",topology,source_type,source_value,resist_no);
  84.     printf("DEBUG: resistor_values[0]: %d\n", resistor_values[0]);
  85.     printf("DEBUG: resistor_values[1]: %d\n", resistor_values[1]);
  86.  
  87.     /*===================================
  88.     ||        Effective Values         ||
  89.     ===================================*/
  90.     //Effective Resistance
  91.     effective_resistance = get_effective_resistance(resistor_values,topology,resist_no);//circuits.c
  92.     printf("DEBUG: effect_restPOST: %.6f\n",effective_resistance);
  93.     //Effective Voltage
  94.     effective_voltage = get_effective_vc(effective_resistance,source_type,source_value,0);//circuits.c
  95.     printf("DEBUG: effect_voltPOST: %.6f\n",effective_voltage);
  96.     //Effective Current
  97.     effective_current = get_effective_vc(effective_resistance,source_type,source_value,1);//circuits.c
  98.     printf("DEBUG: effect_currPOST: %.6f\n",effective_current);
  99.  
  100.     ///////////////////////////////////////
  101.     //===================================//
  102.     //       Console Out Printing        //
  103.     //===================================//
  104.     ///////////////////////////////////////
  105.  
  106.     /*===================================
  107.     ||        Output Function          ||
  108.     ===================================*/
  109.     output_print_dkc(topology, effective_resistance, effective_voltage, effective_current);
  110.  
  111.     /*===================================
  112.     ||      Individual Resistance      ||
  113.     ===================================*/
  114.     if(topology!=3){
  115.         printf("Do you want to compute for the individual voltage and current of a resistor?(y/n)");
  116.         if(get_bool_input()==1){
  117.             //Making Arrays of our current information...
  118.             int integerArray[3+resist_no];
  119.             double doubleArray[4];
  120.             integerArray[0] = topology;
  121.             integerArray[1] = source_type;
  122.             integerArray[2] = resist_no;
  123.             int i;
  124.             for(i=0;i<resist_no;i++){
  125.                 doubleArray[i+4] = resistor_values[i];
  126.             }
  127.             doubleArray[0] = effective_resistance;
  128.             doubleArray[1] = effective_voltage;
  129.             doubleArray[2] = effective_current;
  130.             doubleArray[3] = source_value;
  131.             /*List of indexes
  132.             intArray
  133.             0 - topology
  134.             1 - source_type
  135.             2 - resist_no
  136.             3+resist_no - resistor_values
  137.  
  138.             doubleArray
  139.             0 - effective_resistance
  140.             1 - effective_voltage
  141.             2 - effective_current
  142.             3 - source_value
  143.             */
  144.  
  145.             get_individual_resistor_values(integerArray,doubleArray);
  146.         }
  147.     }
  148.  
  149.     //Goodbye
  150.     printf("\n\nThank you for using the Simplified Electric Circuit Simulator!\nExiting...");
  151.     return 0;
  152. }
  153.  
  154.  
  155. ///////////////////////////////////////
  156. //===================================//
  157. //       Function Definitions        //
  158. //===================================//
  159. ///////////////////////////////////////
  160.  
  161. void clear_screen(){
  162.     int i;
  163.     for(i=0;i<40;i++){printf("\n");}
  164. }
  165.  
  166. void output_print_dkc(int topology, double effective_resistance, double effective_voltage, double effective_current){
  167.     //Printing Effective Values
  168.     printf("The effective Resistance of the Circuit is: %.6f\nEffective Voltage: %.6f\nEffective Current: %.6f\n",effective_resistance,effective_voltage,effective_current);
  169.  
  170.     //Printing Circuit Topology
  171.     switch(topology){
  172.     case 1:
  173.         printf("Series Circuit Detected.");
  174.         break;
  175.     case 2:
  176.         printf("Parallel Circuit Detected.");
  177.         break;
  178.     case 3:
  179.         printf("Ladder Circuit Detected. \n\t Note: It is not possible to calculate for individual values.");
  180.         break;
  181.     }
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement