Guest User

Untitled

a guest
Nov 16th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1. #include "stdafx.h" /* printf, scanf definitions */
  2. #include "iostream" /* The iostream library is an object-oriented library that provides input and output functionality using streams. */
  3. using namespace std; /* Namespaces allows us to group a set of global classes */
  4. #include "iomanip" /* Manipulators Definition */
  5.  
  6.  
  7.  
  8. int
  9. main (void)
  10. {
  11. FILE *inp; /* File Pointer - inp */
  12. inp = fopen("C:\\input1.dat", "r"); /* File Location Which is to Be Used and The Mode - Which is Read */
  13.  
  14. double B, /* Stored Value - X1 - Read From Data File */
  15. C, /* Stored Value - X2 - Read From Data File */
  16. D, /* Stored Value - X3 - Read From Data File */
  17. X_Initial, /* Stored Value - X Initial - Read From Data File */
  18. X_Final; /* Stored Value - X Final - Read From Data File */
  19.  
  20.  
  21. int Data, /* Stored Value Read From Data File */
  22. N, /* Stored Value Read From Data File */
  23. height, /* Stored Value Read From Data File */
  24. Area_Total, /* Stored Value Read From Data File */
  25. Area_1,
  26. Area_2,
  27. Area_3,
  28. Area_4,
  29. input_status; /* Stored Value Read From Data File */
  30.  
  31. printf("The Following are The Data Inputs: \n\n");
  32.  
  33. cout << setw(8) << "Data Set" << setw(13) << "B-Values" << setw(13) << "C-Values" << setw(13) << "D-Values" << setw(13) << "X-Initial" << setw(13) << "X-Final" <<endl;
  34.  
  35. printf("\n");
  36.  
  37. /* Read File and Gather Input Data */
  38.  
  39. input_status = fscanf(inp, "%lf %lf %lf %lf %lf", &B, &C, &D, &X_Initial, &X_Final); /* Each Value is Stored at Certain Places */
  40. while (input_status != EOF){ /* When it Reaches EOF - End of File */
  41.  
  42. cout << setw(3) << ("1)") << setw(13)<< ("%lf",B) << setw(13)<< ("%lf",C) << setw(13)<< ("%lf",D) << setw(13)<< ("%lf",X_Initial) << setw(13)<< ("%lf",X_Final) << endl; /* Prints H Under Values and The Result of H Under Results */
  43.  
  44. /* Prints Area Under Values and The Result of The Area Under Results */
  45.  
  46. input_status = fscanf(inp, "%lf %lf %lf %lf %lf", &B, &C, &D, &X_Initial, &X_Final); /* Scans Next Line for Data Values Untill EOF*/
  47. }
  48. fclose(inp); /* Closes The Data File Once It Has Finished */
  49.  
  50. if(inp == NULL){ /* If It Cannot Find The File */
  51. printf( "Could not open file or Locate File \n" ); /* It Will Print An Error - Could not open file or Locate File */
  52. }
  53. else
  54. {
  55.  
  56. {
  57. if( X_Initial <= '0.0' && X_Final >= '0.0') /* If X_Initial Is Less Than or Equal to 0.0 */
  58. printf( "Integration cannot be done (as the function is not defined for x=0)" ); /* And If X_Final Greater or Equal to 0.0 */
  59. /* It Will Print Out a Message - Integration cannot be done (as the function is not defined for x=0) */
  60. }
  61. }
  62.  
  63.  
  64. height = (X_Final - X_Initial) / 4; /* Calculates Height */
  65.  
  66. N = (X_Final - X_Initial) / height; /* The number of trapezium calculations required for any h value will be */
  67.  
  68. Area_1 = height * (( X_Initial + B)/2); /* The mathematical relationships associated with this technique now follow: */
  69. Area_2 = height * (( B + C )/2);
  70. Area_3 = height * (( C + D )/2);
  71. Area_4 = height * (( D + X_Final)/2);
  72.  
  73. Area_Total = Area_1 + Area_2 + Area_3 + Area_4;
  74.  
  75.  
  76. printf("\n"); /* Prints Results in Table */
  77.  
  78. cout << setw(8) << "Values" << setw(20) << "Results" << endl; /* Headings: Values - Results */
  79.  
  80. printf("\n");
  81.  
  82. cout << setw(8) << "H>" << setw(20)<< ("%8.5f",height) << endl /* Prints H Under Values and The Result of H Under Results */
  83.  
  84. << setw(8) << "N>" << setw(20)<< ("%6d",N) << endl; /* Prints N Under Values and The Result of N Under Results */
  85.  
  86. printf("\n"); /* Prints Results in Table */
  87.  
  88. cout << setw(8) << "Area 1" << setw(13) << "Area 2" << setw(13) << "Area 3" << setw(13) << "Area 4" << setw(13) << "Total Area" << endl; /* Headings: Values - Results */
  89.  
  90. printf("\n");
  91.  
  92. cout << setw(8) << ("%lf",Area_1) << setw(13)<< ("%lf",Area_2) << setw(13)<< ("%lf",Area_3) << setw(13)<< ("%lf",Area_4) << setw(13)<< ("%lf",Area_Total) << endl; /* Prints H Under Values and The Result of H Under Results */
  93.  
  94. printf("\n");
  95.  
  96. return 0;
  97.  
  98. }
Add Comment
Please, Sign In to add comment