Guest User

Untitled

a guest
Apr 20th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 16.88 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <string.h>
  5. #define ARRAYLAENGDE 50
  6. #define antalloeb 1000
  7. #define antal_maaneder 2
  8. #define antal_dageprmaaned 31
  9. #define antal_unikkeloebere 40
  10.  
  11. // (hele opg) Main - Laver motionstruct for opgaven
  12. typedef struct
  13. {
  14.     char navn[ARRAYLAENGDE],
  15.          ugedag[ARRAYLAENGDE],
  16.          maaned[ARRAYLAENGDE];
  17.     int  dato,
  18.          timestart,
  19.          minutstart,
  20.          distance,
  21.          timeantal,
  22.          minutantal,
  23.          sekundantal;
  24. }struMotion;
  25.  
  26. // (hele opg) Main - funktion der læser hver linje ind i hver sit struct - gemmes i array aMotion
  27. void fLaesdata(const char *filnavn, struMotion aMotion[])
  28. {
  29.     FILE *ifp;
  30.     char aNavn[ARRAYLAENGDE], aUgedag[ARRAYLAENGDE],aMaaned[ARRAYLAENGDE];
  31.     int iDato,
  32.         iTimestart,
  33.         iMinutstart,
  34.         iDistance,
  35.         iTimeantal,
  36.         iMinutantal,
  37.         iSekundantal,
  38.         i = 0;
  39.     struMotion lokalLoeber;
  40.    
  41.     ifp = fopen(filnavn, "r");
  42.  
  43.     while (fscanf(ifp, " %s %s %s %d, 2011 %d:%d %d %d:%d:%d", aNavn, aUgedag, aMaaned,
  44.             &iDato, &iTimestart, &iMinutstart, &iDistance,
  45.             &iTimeantal, &iMinutantal, &iSekundantal) == 10)
  46.     {
  47.    
  48.         strcpy(lokalLoeber.navn, aNavn);
  49.         strcpy(lokalLoeber.ugedag, aUgedag);
  50.         strcpy(lokalLoeber.maaned, aMaaned);
  51.         lokalLoeber.dato = iDato;
  52.         lokalLoeber.timestart = iTimestart;
  53.         lokalLoeber.minutstart = iMinutstart;
  54.         lokalLoeber.distance = iDistance;
  55.         lokalLoeber.timeantal = iTimeantal;
  56.         lokalLoeber.minutantal = iMinutantal;
  57.         lokalLoeber.sekundantal = iSekundantal;
  58.  
  59.         aMotion[i] = lokalLoeber;
  60.         i++;
  61.     }
  62.  
  63.  
  64.   fclose(ifp);
  65. }
  66.  
  67. // 1.1 - Udregner hastigheden for den i'te loeber
  68. void fRegnhast(struMotion aMotion, double *dHast)
  69. {
  70.     int a = 60, b = 3600;
  71.     double tidTim = 0.0, tidMin = 0.0,
  72.            tidSek = 0.0, tidTimer = 0.0, KprM = 1000;
  73.        
  74.     tidTim = (double)aMotion.timeantal;
  75.     tidMin = ((double)aMotion.minutantal / a );
  76.     tidSek = ((double)aMotion.sekundantal / b);
  77.        
  78.     tidTimer = tidTim + (tidMin + tidSek);
  79.    
  80.     *dHast = ((((double)aMotion.distance)/KprM) / tidTimer);
  81. }
  82.  
  83. // 1.2 printer i'te struct i array
  84. void fPrintloeb(struMotion loeb)
  85. {
  86.  
  87.     printf ("navn: %s\nugedag: %s\ndato: %s %d, 2011\nstarttidspunkt: %d:%d\ndistance: %d\ntid: %d:%d:%d\n\n",
  88.         loeb.navn, loeb.ugedag, loeb.maaned,
  89.         loeb.dato, loeb.timestart, loeb.minutstart,
  90.         loeb.distance, loeb.timeantal,
  91.         loeb.minutantal, loeb.sekundantal);
  92. }
  93.  
  94. // 2.1 laver ugedags-struct
  95. typedef struct
  96. {
  97.     int mandag,
  98.         tirsdag,
  99.         onsdag,
  100.         torsdag,
  101.         fredag,
  102.         loerdag,
  103.         soendag;
  104. } struUgedag;
  105.  
  106. // 2.2 laver lokal struct med værdier 0.
  107. void fClean_structUgedag(struUgedag *stru)
  108. {
  109.     int z = 0;
  110.  
  111.     (*stru).mandag = z;
  112.     (*stru).tirsdag = z;
  113.     (*stru).onsdag = z;
  114.     (*stru).torsdag = z;
  115.     (*stru).fredag = z;
  116.     (*stru).loerdag = z;
  117.     (*stru).soendag = z;
  118. }
  119.  
  120. // 2.3 funktion der tager distancen for specifik ugedag, og placerer i kopistruct
  121. void fUgedag(struMotion aMotion, struUgedag *aUgeloeb)
  122. {
  123.     int x = 0;
  124.  
  125.     x = aMotion.distance;
  126.  
  127.     if (strcmp(aMotion.ugedag, "Mon") == 0)
  128.         (*aUgeloeb).mandag = x;
  129.     else if (strcmp(aMotion.ugedag, "Tue") == 0)
  130.         (*aUgeloeb).tirsdag = x;
  131.     else if (strcmp(aMotion.ugedag, "Wed") == 0)
  132.         (*aUgeloeb).onsdag = x;
  133.     else if (strcmp(aMotion.ugedag, "Thu") == 0)
  134.         (*aUgeloeb).torsdag = x;
  135.     else if (strcmp(aMotion.ugedag, "Fri") == 0)
  136.         (*aUgeloeb).fredag = x;
  137.     else if (strcmp(aMotion.ugedag, "Sat") == 0)
  138.         (*aUgeloeb).loerdag = x;
  139.     else if (strcmp(aMotion.ugedag, "Sun") == 0)
  140.         (*aUgeloeb).soendag = x;
  141.  
  142. }
  143.  
  144. //4.1 funktion der cleaner struct
  145. void fClean_structKopi(struMotion *aMotionSort)
  146. {
  147.     int z = 0;
  148.    
  149.     strcpy((*aMotionSort).navn, "");
  150.     strcpy((*aMotionSort).ugedag, "");
  151.     strcpy((*aMotionSort).maaned, "");
  152.     (*aMotionSort).dato = z;
  153.     (*aMotionSort).timestart = z;
  154.     (*aMotionSort).minutstart = z;
  155.     (*aMotionSort).distance = z;
  156.     (*aMotionSort).timeantal = z;
  157.     (*aMotionSort).minutantal = z;
  158.     (*aMotionSort).sekundantal = z;
  159. }
  160.  
  161. // 4.2 funktion der regner hvornår det i'te loeb er sluttet
  162. void fSluttidspunkt(struMotion aMotion,int *iMotionsluttime, int *iMotionslutmin)
  163. {
  164.     int a = 60;
  165.     int b = 1;
  166.  
  167.     if ((aMotion.minutstart + aMotion.minutantal) < a)
  168.     {
  169.         *iMotionsluttime = aMotion.timestart + aMotion.timeantal;
  170.         *iMotionslutmin = aMotion.minutstart + aMotion.minutantal;
  171.     }
  172.     else
  173.     {
  174.         *iMotionslutmin = ((aMotion.minutstart + aMotion.minutantal) - a);
  175.         *iMotionsluttime = ((aMotion.timestart + aMotion.timeantal) + b);
  176.     }
  177. }
  178.  
  179. // 4.3 funktion der kopierer i aMotionkopi, hvis loebet er indenfor de angivne tider
  180. void fTidstjek(struMotion aMotion, int iStarttime, int iStartmin, int iSluttime,
  181.      int iSlutmin, int iMotionsluttime, int iMotionslutmin, struMotion *aMotionSort, int *iTjek)
  182. {
  183.     strcpy((*aMotionSort).navn, aMotion.navn);
  184.     strcpy((*aMotionSort).ugedag, aMotion.ugedag);
  185.     strcpy((*aMotionSort).maaned, aMotion.maaned);
  186.     (*aMotionSort).dato = aMotion.dato;
  187.     (*aMotionSort).timestart = aMotion.timestart;
  188.     (*aMotionSort).minutstart = aMotion.minutstart;
  189.     (*aMotionSort).distance = aMotion.distance;
  190.     (*aMotionSort).timeantal = aMotion.timeantal;
  191.     (*aMotionSort).minutantal = aMotion.minutantal;
  192.     (*aMotionSort).sekundantal = aMotion.sekundantal;
  193.    
  194.     if ((iStarttime < aMotion.timestart) && (iSluttime > iMotionsluttime))
  195.     {
  196.         *iTjek = 1;
  197.     }
  198.     else if ((iStarttime == aMotion.timestart) && (iSluttime > iMotionsluttime))
  199.     {
  200.         if (iStartmin < aMotion.minutstart)
  201.         {
  202.             *iTjek = 1;
  203.         }
  204.     }
  205.     else if ((iStarttime < aMotion.timestart) && (iSluttime == iMotionsluttime))
  206.     {
  207.         if (iSlutmin > iMotionsluttime)
  208.         {
  209.             *iTjek = 1;
  210.         }
  211.     }
  212.     else if ((iStarttime == aMotion.timestart) && (iSluttime == iMotionsluttime))
  213.     {
  214.         if ((iStartmin < aMotion.minutstart) && (iSlutmin > iMotionslutmin))
  215.         {
  216.             *iTjek = 1;
  217.         }
  218.     }
  219. }
  220.  
  221. // 4.4 funktion der cleaner aMotionSort
  222. void fClean_structKopia(struMotion *aMotionSort)
  223. {
  224.     int z = 0;
  225.    
  226.     strcpy((*aMotionSort).navn, "");
  227.     strcpy((*aMotionSort).ugedag, "");
  228.     strcpy((*aMotionSort).maaned, "");
  229.     (*aMotionSort).dato = z;
  230.     (*aMotionSort).timestart = z;
  231.     (*aMotionSort).minutstart = z;
  232.     (*aMotionSort).distance = z;
  233.     (*aMotionSort).timeantal = z;
  234.     (*aMotionSort).minutantal = z;
  235.     (*aMotionSort).sekundantal = z;
  236. }
  237.  
  238. // 4.5 funktion der bytter 2 structs plads i array aSort
  239. void fSwap(struMotion *aSort, struMotion *bSort)
  240. {
  241.     struMotion kopi;
  242.  
  243.     kopi = *aSort;
  244.     *aSort = *bSort;
  245.     *bSort = kopi;
  246. }
  247.  
  248. // 5.1
  249. void fKopier(struMotion a, struMotion *b)
  250. {
  251.     strcpy((*b).navn, a.navn);
  252.     (*b).distance += a.distance;
  253.     (*b).timeantal += a.timeantal;
  254.     (*b).minutantal += a.minutantal;
  255.     (*b).sekundantal += a.sekundantal;
  256. }
  257.  
  258. // printer fortsæt menuvalgmuligheder
  259. void fFortsaet();
  260.  
  261. // 1.0 delproblem 1 sættes igang
  262. void fprob1()
  263. {
  264.     int i = 0;
  265.     double x = 0.0, dHast[antalloeb];
  266.     struMotion aMotion[antalloeb];
  267.  
  268.     // kører laesdata, for at kalde arrayet
  269.     fLaesdata("runs", aMotion);
  270.  
  271.     // søger og printer den valgte hastighed
  272.     printf("skriv hvilken hastighed der søges efter, dette er angivet i km/t:");
  273.     scanf("%lf", &x);
  274.  
  275.     printf("Foelgende har loebet hurtigere end den indtastede hastighed:\n \n");
  276.  
  277.     // Kør loop, der tjekker om x <= end hastighed, hvis ja, så print.
  278.     for (i = 0; i < antalloeb; i++)
  279.     {
  280.         fRegnhast(aMotion[i], &dHast[i]);
  281.                 if (x <= dHast[i]) {
  282.                     fPrintloeb(aMotion[i]);    
  283.                     }
  284.     }
  285.  
  286.     fFortsaet();
  287. }
  288.  
  289. // 2.0 delproblem 2 sættes igang
  290. void fprob2()
  291. {
  292.     int i = 0, z = 0;
  293.     struMotion aMotion[antalloeb];
  294.     struUgedag aUgeloeb;
  295.  
  296.     aUgeloeb.mandag = z;
  297.     aUgeloeb.tirsdag = z;
  298.     aUgeloeb.onsdag = z;
  299.     aUgeloeb.torsdag = z;
  300.     aUgeloeb.fredag = z;
  301.     aUgeloeb.loerdag = z;
  302.     aUgeloeb.soendag = z;
  303.  
  304.     //struUgedag struUgekopi;
  305.     struUgedag aUgelokal;
  306.  
  307.     // funktion 2.2, der sætter structens værdier til 0.
  308.     fClean_structUgedag(&aUgelokal);
  309.  
  310.     // kører laesdata, for at kalde arrayet
  311.     fLaesdata("runs", aMotion);
  312.  
  313.         for (i = 0; i < antalloeb; i++)
  314.         {
  315.             fUgedag(aMotion[i], &aUgeloeb);
  316.            
  317.             aUgelokal.mandag += aUgeloeb.mandag;
  318.             aUgelokal.tirsdag += aUgeloeb.tirsdag;
  319.             aUgelokal.onsdag += aUgeloeb.onsdag;
  320.             aUgelokal.torsdag += aUgeloeb.torsdag;
  321.             aUgelokal.fredag += aUgeloeb.fredag;
  322.             aUgelokal.loerdag += aUgeloeb.loerdag;
  323.             aUgelokal.soendag += aUgeloeb.soendag;
  324.            
  325.             fClean_structUgedag(&aUgeloeb);
  326.            
  327.         }
  328.  
  329.         //mandag
  330.         if (aUgelokal.mandag > aUgelokal.tirsdag && aUgelokal.mandag > aUgelokal.onsdag &&
  331.             aUgelokal.mandag > aUgelokal.torsdag && aUgelokal.mandag > aUgelokal.fredag &&
  332.             aUgelokal.mandag > aUgelokal.loerdag && aUgelokal.mandag > aUgelokal.soendag)
  333.         {
  334.             printf("Mandag er dagen hvor der blev loebest mest\n\n", aUgelokal.mandag);
  335.         }
  336.         //tirsdag
  337.         else if  (aUgelokal.tirsdag > aUgelokal.mandag && aUgelokal.tirsdag > aUgelokal.onsdag &&
  338.             aUgelokal.tirsdag > aUgelokal.torsdag && aUgelokal.tirsdag > aUgelokal.fredag &&
  339.             aUgelokal.tirsdag > aUgelokal.loerdag && aUgelokal.tirsdag > aUgelokal.soendag)
  340.         {
  341.             printf("Tirsdag er dagen hvor der blev loebest mest\n\n", aUgelokal.mandag);
  342.         }
  343.         //onsdag
  344.         else if  (aUgelokal.onsdag > aUgelokal.tirsdag && aUgelokal.onsdag > aUgelokal.mandag &&
  345.             aUgelokal.onsdag > aUgelokal.torsdag && aUgelokal.onsdag > aUgelokal.fredag &&
  346.             aUgelokal.onsdag > aUgelokal.loerdag && aUgelokal.onsdag > aUgelokal.soendag)
  347.         {
  348.             printf("Onsdag er dagen hvor der blev loebest mest\n\n", aUgelokal.mandag);
  349.         }
  350.         //torsdag
  351.         else if  (aUgelokal.torsdag > aUgelokal.mandag && aUgelokal.torsdag > aUgelokal.tirsdag &&
  352.             aUgelokal.torsdag > aUgelokal.onsdag && aUgelokal.torsdag > aUgelokal.fredag &&
  353.             aUgelokal.torsdag > aUgelokal.loerdag && aUgelokal.torsdag > aUgelokal.soendag)
  354.         {
  355.             printf("Torsdag er dagen hvor der blev loebest mest\n\n", aUgelokal.mandag);
  356.         }
  357.         //fredag
  358.         else if  (aUgelokal.fredag > aUgelokal.tirsdag && aUgelokal.fredag > aUgelokal.onsdag &&
  359.             aUgelokal.fredag > aUgelokal.torsdag && aUgelokal.fredag > aUgelokal.mandag &&
  360.             aUgelokal.fredag > aUgelokal.loerdag && aUgelokal.fredag > aUgelokal.soendag)
  361.         {
  362.             printf("Fredag er dagen hvor der blev loebest mest\n\n", aUgelokal.mandag);
  363.         }
  364.         //loerdag
  365.         else if  (aUgelokal.loerdag > aUgelokal.mandag && aUgelokal.loerdag > aUgelokal.onsdag &&
  366.             aUgelokal.loerdag > aUgelokal.torsdag && aUgelokal.loerdag > aUgelokal.fredag &&
  367.             aUgelokal.loerdag > aUgelokal.tirsdag && aUgelokal.loerdag > aUgelokal.soendag)
  368.         {
  369.             printf("Loerdag er dagen hvor der blev loebest mest\n\n", aUgelokal.mandag);
  370.         }
  371.         //soendag
  372.         else
  373.         {
  374.             printf("Soendag er dagen hvor der blev loebest mest \n\n", aUgelokal.mandag);
  375.         }
  376.            
  377.     fFortsaet();
  378. }
  379.  
  380. // 3.0 - delproblem 3 sættes igang
  381. void fprob3()
  382. {
  383.     int z = 0;
  384.     int y = 0;
  385.     int iDagmax = 0;
  386.     int iDag = 0;
  387.     int iMaaned;
  388.     int iTaelloeb[antal_maaneder][antal_dageprmaaned];
  389.     struMotion aMotion[antalloeb];
  390.     char sTjekunikke[antal_maaneder][antal_dageprmaaned][antal_unikkeloebere][100];
  391.  
  392.     // nulstiller iTaelloeb, således arrayet er tomt og klar til count.
  393.     for (int q = 0; q < antal_maaneder; q++)
  394.     {
  395.         for (int c = 0; c < antal_dageprmaaned; c++)
  396.         {
  397.                 iTaelloeb[q][c] = 0;
  398.         }
  399.     }
  400.  
  401.     // laeser filen ind i aMotion.
  402.     fLaesdata("runs", aMotion);
  403.    
  404.     // looper aMotion-struct, og taeller antal loeb pr. dag, mens samme
  405.     // loeber kun bliver registreret én gang pr dag.
  406.     for (int i = 0; i < antalloeb; i++)
  407.     {
  408.         int iTjekmaaned = 0;
  409.  
  410.         if (strcmp(aMotion[i].maaned, "September") == 0)
  411.         {
  412.             iTjekmaaned = 1;
  413.         }
  414.  
  415.         int iTjek = 0;
  416.         for (int j = 0; j < antal_unikkeloebere; j++)
  417.         {
  418.             if (strcmp(aMotion[i].navn, sTjekunikke[iTjekmaaned][aMotion[i].dato][j]) == 0)
  419.             {
  420.                 iTjek = 1;
  421.                 break;
  422.             }
  423.         }
  424.  
  425.         if (iTjek == 0)
  426.         {
  427.             int iGemtloeb = iTaelloeb[iTjekmaaned][aMotion[i].dato];
  428.             strcpy(sTjekunikke[iTjekmaaned][aMotion[i].dato][iGemtloeb], aMotion[i].navn);
  429.             iTaelloeb[iTjekmaaned][aMotion[i].dato]++;
  430.         }
  431.     }          
  432.  
  433.     // tjekker den  hoejest værdi af antal loeb i periode
  434.     int iHoejest = 0;
  435.     int k = 0;
  436.     int l = 0;
  437.     for (int q = 0; q < antal_maaneder; q++)
  438.     {
  439.         for (int c = 1; c < antal_dageprmaaned; c++)
  440.         {
  441.             if (iTaelloeb[q][c] > iHoejest)
  442.             {
  443.                 iHoejest = iTaelloeb[q][c];
  444.                 k = q;
  445.                 l = c;
  446.             }
  447.         }
  448.     }
  449.  
  450.     if (k = 0)
  451.     printf("Der blev loebet flest loeb d. %d. August, hvor der blev loebet %d loeb\n \n", l, iHoejest);
  452.     else
  453.     printf("Der blev loebet flest loeb d. %d. September, hvor der blev loebet %d loeb\n \n", l, iHoejest);
  454.    
  455.     fFortsaet();
  456. }
  457.  
  458. // 4.0 - delproblem 4 sættes igang
  459. void fprob4()
  460. {
  461.     struMotion aMotion[antalloeb];
  462.     struMotion aMotionSort;
  463.     struMotion aSort[antalloeb];
  464.     int z = 0;
  465.     int iStarttime = 0,
  466.         iStartmin = 0,
  467.         iSluttime = 0,
  468.         iSlutmin = 0,
  469.         iMotionsluttime = 0,
  470.         iMotionslutmin = 0;
  471.    
  472.     fLaesdata("runs", aMotion);
  473.  
  474.    
  475.     fClean_structKopi(&aMotionSort);
  476.  
  477.     for (int i = 0; i < antalloeb; i++)
  478.     {
  479.         fClean_structKopia(&aSort[i]);
  480.     }
  481.    
  482.     printf("Indtast oenskede klokkesletsstart\n");
  483.     scanf("%d:%d", &iStarttime, &iStartmin);
  484.     printf("Indtast oenskede klokkesletsstop\n");
  485.     scanf("%d:%d", &iSluttime, &iSlutmin);
  486.  
  487.     int iTael = 0;
  488.     int iTjek = 0;
  489.  
  490.     // tjekker hvilke loeb der er i intervallet
  491.     for (int i = 0; i < antalloeb; i++)
  492.     {
  493.         fSluttidspunkt(aMotion[i], &iMotionsluttime, &iMotionslutmin);
  494.         fTidstjek(aMotion[i], iStarttime, iStartmin, iSluttime, iSlutmin,
  495.         iMotionsluttime, iMotionslutmin, &aMotionSort, &iTjek);
  496.         if (iTjek == 1)
  497.         {
  498.             aSort[iTael] = aMotionSort;
  499.             iTael++;
  500.         }
  501.             iTjek = 0;
  502.         fClean_structKopi(&aMotionSort);
  503.     }
  504.  
  505.     // Sorterer aSort
  506.     for (int i = 0; i < antalloeb; i++)
  507.     {
  508.         for (int j = 0; j < (iTael-1); j++)
  509.         {
  510.             if (aSort[j].distance < aSort[(j+1)].distance)
  511.             fSwap(&aSort[j], &aSort[(j+1)]);
  512.         }
  513.     }
  514.  
  515.     printf("Foelgende loeber har loebet indenfor det valgte tidsinterval:\n");
  516.  
  517.     // printer loebene der er i intervallet, sorteret efter distance
  518.     for (int i = 0; i < iTael; i++)
  519.     {
  520.     printf("%s %s %s %d, 2011 %d:%d %d %d:%d:%d\n", aSort[i].navn, aSort[i].ugedag, aSort[i].maaned, aSort[i].dato,
  521.         aSort[i].timestart, aSort[i].minutstart, aSort[i].distance, aSort[i].timeantal, aSort[i].minutantal,
  522.         aSort[i].sekundantal);
  523.     }
  524.  
  525.     fFortsaet();
  526. }
  527.  
  528. // 5.0 - delproblem 5 sættes igang
  529. void fprob5()
  530. {
  531.     int c = 0;
  532.     int i = 0;
  533.     int j = 0;
  534.     struMotion aMotion[antalloeb];
  535.     struMotion aMotionkopi[antalloeb];
  536.  
  537.     // nulstiller aMotionkopi, således arrayet er tomt og klar til count.
  538.     for (i = 0; i < antalloeb; i++)
  539.     {
  540.         fClean_structKopia(&aMotionkopi[i]);
  541.     }
  542.  
  543.     /*printf("navn: %s\ndistance: %d\ntimeantal: %d\nminutantal: %d\nsekundantal: %d\n", aMotionkopi[0].navn, aMotionkopi[0].distance,
  544.         aMotionkopi[0].timeantal, aMotionkopi[0].minutantal, aMotionkopi[0].sekundantal);*/
  545.  
  546.     // laeser filen ind i aMotion.
  547.     fLaesdata("runs", aMotion);
  548.    
  549.     int p = 0;
  550.     int iTaelNavn = 0;
  551.     int iTjek = 0;
  552.     int iResult = 0;
  553.  
  554.     // looper aMotion-struct, og taeller antal loeb pr. dag, mens samme
  555.     // loeber kun bliver registreret én gang pr dag.
  556.  
  557.     for (i = 0; i < antalloeb; i++)
  558.     {
  559.         iTjek = 0;
  560.         for (p = 0; p < iResult; p++)
  561.         {
  562.             if (strcmp(aMotion[i].navn, aMotionkopi[p].navn) == 0)     
  563.             {
  564.                 iTjek = p;
  565.                 break;
  566.             }  
  567.         }
  568.         if (iTjek == 0)
  569.         {
  570.             aMotionkopi[i].distance += aMotion[iResult].distance;
  571.  
  572.             iResult++;
  573.         }
  574.         else
  575.         {
  576.             aMotionkopi[i].distance += aMotion[iTjek].distance;
  577.         }
  578.     }  
  579.  
  580.     // timeantal: %d\nminutantal: %d\nsekundantal: %d\n         navn: %s\n
  581.     // aMotionkopi[9].navn,     aMotionkopi[9].timeantal, aMotionkopi[9].minutantal, aMotionkopi[9].sekundantal
  582.     printf("distance: %d\n", aMotionkopi[0].distance);
  583.  
  584.     printf("navn: %s\ndistance: %d\ntimeantal: %d\nminutantal: %d\nsekundantal: %d\n", aMotion[0].navn, aMotion[0].distance,
  585.         aMotion[0].timeantal, aMotion[0].minutantal, aMotion[0].sekundantal);
  586.  
  587.  
  588.  
  589.     fFortsaet();
  590. }
  591.  
  592. // Laver protokoller af menu og errorcall, som laves efter main
  593. void ferrorcall();
  594. void fmenu();
  595.  
  596. int main(void)
  597. {
  598.    
  599.     // menu-visning
  600.     printf("Menu:\n");
  601.     printf("Delproblem 1\n");
  602.     printf("Delproblem 2\n");
  603.     printf("Delproblem 3\n");
  604.     printf("Delproblem 4\n");
  605.     printf("Delproblem 5\n");
  606.     printf("indtast talvaerdi fra 1 til 5 efter hvilket delproblem der skal loeses:\n");
  607.     printf("- for quit, skriv 'q'");
  608.    
  609.     // kalder menuen
  610.     fmenu();
  611.  
  612.     printf("Programmet lukker nu...\n");
  613.     return 0;
  614. }
  615.  
  616. void fFortsaet()
  617. {
  618.     printf("indtast nu nummer paa det naeste problem der skal loeses, eller quit program:\n");
  619. }
  620.  
  621. // laver et kald af fejlindtastning
  622. void ferrorcall()
  623. {
  624.     printf("Ugyldig vaerdig indtastet, prøv igen\n");
  625. }
  626.  
  627. // funktion-menu, kører i loop, indtil 'q' bliver indtastet
  628. void fmenu()
  629. {
  630.     // initialisering af variable
  631.     char x;
  632.  
  633.     // menu-kør
  634.     do
  635.     {
  636.         printf("\n");
  637.  
  638.         // scan valg af delproblem
  639.         scanf(" %c", &x);
  640.  
  641.         if (x == '1')
  642.         {
  643.             fprob1();
  644.         }
  645.         else if (x == '2')
  646.         {
  647.             fprob2();
  648.         }
  649.         else if (x == '3')
  650.         {
  651.             fprob3();
  652.         }
  653.         else if (x == '4')
  654.         {
  655.             fprob4();
  656.         }
  657.         else if (x == '5')
  658.         {
  659.             fprob5();
  660.         }
  661.         else if (x == 'q');
  662.  
  663.         else
  664.             ferrorcall();
  665.     }
  666.     while(x != 'q');
  667. }
Add Comment
Please, Sign In to add comment