jTruBela

lab7.c JT/EW

Apr 5th, 2022 (edited)
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.98 KB | None | 0 0
  1. // CSIT231-Sys. Prog. 4/2/22
  2. // Justin Trubela & Edward Wynman - Lab7
  3.  
  4. /*
  5. Might need to cp Dropbox items like beer.c, ffiles.c, fibonacci.c, and maybe test.out
  6. */
  7.  
  8. #include <time.h>       //enable clock_gettime()
  9. #include <sys/stat.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12. // #include <math.h>    //try to use?
  13. // #include <stdlib.h>  //try to use?
  14. // #include <unistd.h>  //try to use?
  15.  
  16. //you must declare the "stop" and "start" variables as follows...
  17. // struct timespec start stop;
  18.  
  19. // Timespec struct - Grabbing the time.. for this the variables are "stop" and "start"
  20. struct timespec {
  21.     //declare the "stop" and "start" variables
  22.  
  23.     //to capture the start time and then, when the function is finished
  24.     long start; //clock_gettime(CLOCK_REALTIME, &start);
  25.     //to capture the stop time and then, when the function is finished
  26.     long stop; //clock_gettime(CLOCK_REALTIME, &stop);
  27.  
  28.     //You will now have two data filled variables named "start" and stop" to use but they have 2 properties...
  29.     time_t   tv_sec;   //time_t data type       seconds         variable named tv_sec
  30.     long     tv_nsec;  //long data type       nanoseconds       variable named tv_nsec
  31.     // figure out how to use these
  32. }
  33.  
  34.  
  35.  
  36. int main (int argc, char **argv){
  37.  
  38.     // 1. Write 2 functions:
  39.     //     A: The first function will recursively calculate a Fibonacci sequence number
  40.     //     B: The second function will calculate the same WITHOUT using recursion.
  41.     //         The inputs of both functions will be a single integer
  42.     //          indicating which number in the series you will calculate.
  43.  
  44.     // 2. You will input, on the command line, a number for which these sequences will be calculated.
  45.     //     So, if I enter 5, your program will calculate the first 5 positions of the Fibonacci sequence both ways.
  46.  
  47.     // 3. Before starting the process:
  48.     //     A: grab the start time of the entire process within the maximum time precision available including nanoseconds.
  49.     //     You will capture this time at the end of the ENTIRE process the same way.
  50.     //     You will use these to calculate the entire time ALL the calculations took to run.
  51.  
  52.     // 4. For each number, whose Fibonacci sequence is calculated:
  53.     //     grab the start time before the function is called the first time
  54.     //     and then grab it again when it returns for the final time.
  55.     //     Calculate how long that number in the sequence took to calculate.
  56.     //         Remember, you are calculating it 2 ways, so you need two start and stop times
  57.     //             (recursive and non-recursive) for each.
  58.     //         Please grab 10 samples of each and calculate the average time for EVERY NUMBER calculated in the series.
  59.  
  60.     // 5. If the file does not already exist:
  61.     //     create a file called fibonacci.out and put the date and time of the run right on top.
  62.     //     The date should read in THIS FORMAT... November 12, 1962 23:00.123456789.
  63.  
  64.     // 6. To fibonacci.out:
  65.     //     for each number calculated in the series:
  66.     //     1. append the sequence number,
  67.     //     2. the calculated result,
  68.     //     3. the calculated average:
  69.     //         a: the calculated average recursive time and
  70.     //         b: the calculated average non-recursive time
  71.     //         SEPARATED BY TABS or COMMAS (important...you'll see why soon).
  72.  
  73.     // 7. At the end of the run:
  74.     //     add the date and time of the run completion in the same format: November 12, 1962 23:00.123456789.
  75.  
  76.     // 8. State how long the entire process took to complete at the VERY end.
  77.  
  78.     // 9. Transfer this file to your PC and graph it in Excel. (one line for recursive, one line for non-recursive).
  79.     //    Time should be the Y-axis and sequence number should be the X-axis.
  80.     //     (explains why I wanted this tab or comma delimited!!!)
  81.  
  82.     // 10. Set the permissions to fibonnacci.out so that it is "write-protected"
  83.     //     (no one has "write" privilege) but can be read by anyone who can log into Turing.
  84.  
  85.     return 0;
  86. }
  87.  
  88.  
  89. /*
  90. ----------------------------------------------------------------------------------------------------
  91.  
  92. Here is a sample of what the file should look like after running "./lab7 15"
  93.  
  94. November 12, 1962 23:00:00.123456789
  95. Sequence    Result    Recursive-time    Non-Recursive-time
  96. 1    1    0.123456789    0.34567890
  97. 2    1    1.123456789    1.34567890
  98. 3    2    3.123456789    4.34567890
  99. 4    3    5.123456789    7.34567890
  100. 5    5    11.123456789    12.34567890
  101. 6    8    15.123456789    19.34567890
  102. 7    13    20.123456789    25.34567890
  103. 8    21    28.123456789    32.34567890
  104. 9    34    40.123456789    45.34567890
  105. 10    55    55.123456789    57.34567890
  106. 11    89    72.123456789    77.34567890
  107. 12    144    94.123456789    97.34567890
  108. 13    233    120.123456789    122.34567890
  109. 14    377    149.123456789    152.34567890
  110. 15    610    200.123456789    201.34567890
  111. November 12, 1962 23:04:00.345678912
  112. Total Time = 4:00.222222123
  113.  
  114. */
Add Comment
Please, Sign In to add comment