Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h" /* printf, scanf definitions */
- #include "iostream" /* The iostream library is an object-oriented library that provides input and output functionality using streams. */
- using namespace std; /* Namespaces allows us to group a set of global classes */
- #include "iomanip" /* Manipulators Definition */
- int
- main (void)
- {
- FILE *inp; /* File Pointer - inp */
- inp = fopen("C:\\input1.dat", "r"); /* File Location Which is to Be Used and The Mode - Which is Read */
- double B, /* Stored Value - X1 - Read From Data File */
- C, /* Stored Value - X2 - Read From Data File */
- D, /* Stored Value - X3 - Read From Data File */
- X_Initial, /* Stored Value - X Initial - Read From Data File */
- X_Final; /* Stored Value - X Final - Read From Data File */
- int Data, /* Stored Value Read From Data File */
- N, /* Stored Value Read From Data File */
- height, /* Stored Value Read From Data File */
- Area_Total, /* Stored Value Read From Data File */
- Area_1,
- Area_2,
- Area_3,
- Area_4,
- input_status; /* Stored Value Read From Data File */
- printf("The Following are The Data Inputs: \n\n");
- 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;
- printf("\n");
- /* Read File and Gather Input Data */
- input_status = fscanf(inp, "%lf %lf %lf %lf %lf", &B, &C, &D, &X_Initial, &X_Final); /* Each Value is Stored at Certain Places */
- while (input_status != EOF){ /* When it Reaches EOF - End of File */
- 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 */
- /* Prints Area Under Values and The Result of The Area Under Results */
- input_status = fscanf(inp, "%lf %lf %lf %lf %lf", &B, &C, &D, &X_Initial, &X_Final); /* Scans Next Line for Data Values Untill EOF*/
- }
- fclose(inp); /* Closes The Data File Once It Has Finished */
- if(inp == NULL){ /* If It Cannot Find The File */
- printf( "Could not open file or Locate File \n" ); /* It Will Print An Error - Could not open file or Locate File */
- }
- else
- {
- {
- if( X_Initial <= '0.0' && X_Final >= '0.0') /* If X_Initial Is Less Than or Equal to 0.0 */
- printf( "Integration cannot be done (as the function is not defined for x=0)" ); /* And If X_Final Greater or Equal to 0.0 */
- /* It Will Print Out a Message - Integration cannot be done (as the function is not defined for x=0) */
- }
- }
- height = (X_Final - X_Initial) / 4; /* Calculates Height */
- N = (X_Final - X_Initial) / height; /* The number of trapezium calculations required for any h value will be */
- Area_1 = height * (( X_Initial + B)/2); /* The mathematical relationships associated with this technique now follow: */
- Area_2 = height * (( B + C )/2);
- Area_3 = height * (( C + D )/2);
- Area_4 = height * (( D + X_Final)/2);
- Area_Total = Area_1 + Area_2 + Area_3 + Area_4;
- printf("\n"); /* Prints Results in Table */
- cout << setw(8) << "Values" << setw(20) << "Results" << endl; /* Headings: Values - Results */
- printf("\n");
- cout << setw(8) << "H>" << setw(20)<< ("%8.5f",height) << endl /* Prints H Under Values and The Result of H Under Results */
- << setw(8) << "N>" << setw(20)<< ("%6d",N) << endl; /* Prints N Under Values and The Result of N Under Results */
- printf("\n"); /* Prints Results in Table */
- 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 */
- printf("\n");
- 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 */
- printf("\n");
- return 0;
- }
Add Comment
Please, Sign In to add comment