Advertisement
Guest User

Untitled

a guest
Dec 18th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. `#include <stdio.h>
  2. #include <ctype.h>
  3. #include <stdlib.h>
  4. #include "prog8_functions.h"
  5.  
  6. int main() {
  7. FILE* Volt = NULL;
  8. FILE* Resist = NULL;
  9. FILE* fp_output;
  10. char file1 [200]; //file of resistors
  11. char file2 [200]; //file of Voltages
  12. char fileout [200];
  13. int M;
  14. int p = 0;
  15. double a;
  16. double b;
  17.  
  18. double I;
  19. double P;
  20.  
  21. double c = 10000;
  22. double d = 10000;
  23. double e = 10000;
  24. double f = 0;
  25. double g = 0;
  26. double h = 0;
  27. double i = 0;
  28. double j = 0;
  29. double k = 0;
  30.  
  31. do{
  32. printf("Enter name of file for resistor input:");
  33. scanf("%s", file1);
  34.  
  35. if( Resist == NULL ){
  36. printf("Invalid file name\n");
  37. }
  38.  
  39. else{
  40. M = M + 1;
  41. }
  42.  
  43. }while (M != 1);
  44. do{
  45.  
  46. printf("Enter name of file for voltage input:");
  47. scanf("%s", file2);
  48.  
  49. if( Volt == NULL ) {
  50. printf("Invalid file name\n");
  51. }
  52.  
  53. else{
  54. M = M + 1;
  55. }
  56.  
  57. }while (M != 2);
  58.  
  59. printf("Enter name of file for output:");
  60. scanf("%s", fileout);
  61.  
  62. Volt = fopen(file1, "rb");
  63. Resist = fopen(file2, "rb");
  64.  
  65. fp_output = fopen(fileout, "w");
  66.  
  67. fprintf(" R (ohms) V (volts)\n");
  68.  
  69. do{
  70. fread(&a, sizeof(a), 1, Volt);
  71. fread(&b, sizeof(b), 1, Resist);
  72. fprintf("RV pair %d: %.2lf %.2lf\n", p, a, b);
  73. p = p + 1;
  74.  
  75. if(b < c ){
  76. c = b;
  77. }
  78. if(b > f ){
  79. f = b;
  80. }
  81.  
  82. I = b / a;
  83. P = I * b;
  84.  
  85. if(I < d ){
  86. c = b;
  87. }
  88. if(I > g ){
  89. f = b;
  90. }
  91.  
  92. if(P < e ){
  93. c = b;
  94. }
  95. if(P > h ){
  96. f = b;
  97. }
  98.  
  99. i = i + b;
  100. j = j + I;
  101. k = k + P;
  102.  
  103. }while((fscanf(Volt, "%.2lf", &a) != EOF) && (fscanf(Resist, "%.2lf", &b) != EOF));
  104.  
  105. i = i / (p + 1);
  106. j = j / (p + 1);
  107. k = k / (p + 1);
  108.  
  109. fprintf(" Voltage Current Power\n");
  110. fprintf("MIN %.2lf %.4lf %.4lf\n", c, d, e);
  111. fprintf("MAX %.2lf %.4lf %.4lf\n", f, g, h);
  112. fprintf("AVG %.2lf %.4lf %.4lf\n", i, j, k);
  113.  
  114. //fwrite(userNums, sizeof(int), NUM_VALUES, outFile);
  115.  
  116. fclose(Volt);
  117. fclose(Resist);
  118. fclose(fp_output);
  119.  
  120. return 0;
  121.  
  122. }`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement