Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.37 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #include <stdlib.h>
  4.  
  5. #include <time.h>
  6.  
  7. #define WEEKS 10
  8.  
  9. #define MAXCHARGE 3
  10.  
  11. int menu();
  12.  
  13. int weather();
  14.  
  15. int startWeek(int current_week);
  16.  
  17. void status(int current_week, int robot_charge);
  18.  
  19. int update_charge(int robot_charge, int weather_status, int weekly_task,
  20.  
  21. int success);
  22.  
  23. int is_complete(int habitat_flag, int hydrofarm_flag, int chargestation_flag,
  24.  
  25. int elecfarm_flag, int water_flag);
  26.  
  27. void final_report(int habitat_flag, int hydrofarm_flag, int chargestation_flag,
  28.  
  29. int elecfarm_flag, int water_flag);
  30.  
  31. int build_habitat(int habitat_flag, int weather_status, int robot_charge,
  32.  
  33. int hydrofarm_flag, int elecfarm_flag);
  34.  
  35. int build_hydrofarm(int hydrofarm_flag, int weather_status, int robot_charge,
  36.  
  37. int water_flag, int elecfarm_flag);
  38.  
  39. int build_chargestation(int chargestation_flag, int weather_status,
  40.  
  41. int robot_charge, int elecfarm_flag);
  42.  
  43. int build_elecfarm(int elecfarm_flag, int weather_status, int robot_charge);
  44.  
  45. int build_waterpipes(int water_flag, int weather_status, int robot_charge);
  46.  
  47. int recharge(int elecfarm_flag, int chargestation_flag);
  48.  
  49. int main(void) {
  50.  
  51. // Variables to store the current week, weather, task, success flag
  52.  
  53. int current_week, weather_status, weekly_task, success;
  54.  
  55. // Flags to denote whether or not critical buildings have been built yet
  56.  
  57. // Robots begin with maximum charge
  58.  
  59. int habitat_flag = 0, hydrofarm_flag = 0, chargestation_flag = 0;
  60.  
  61. int elecfarm_flag = 0, water_flag = 0, robot_charge = MAXCHARGE;
  62.  
  63. srand(time(0));
  64.  
  65. // Week Loop
  66.  
  67. // At the beginning of each week, prompt the user with the weather
  68.  
  69. // And request task to be performed
  70.  
  71. for(current_week = 1; current_week <= WEEKS; current_week++) {
  72.  
  73. weather_status = startWeek(current_week);
  74.  
  75. weekly_task = menu();
  76.  
  77. // Call the function that matches the task and check to see if the
  78.  
  79. // Robots are successful. When successful, update the building flag
  80.  
  81. switch (weekly_task) {
  82.  
  83. case 1:
  84.  
  85. success = build_habitat(habitat_flag, weather_status,
  86.  
  87. robot_charge, hydrofarm_flag, elecfarm_flag);
  88.  
  89. if (habitat_flag == 0 && success == 1)
  90.  
  91. habitat_flag = 1;
  92.  
  93. break;
  94.  
  95. case 2:
  96.  
  97. success = build_hydrofarm(hydrofarm_flag, weather_status,
  98.  
  99. robot_charge, water_flag, elecfarm_flag);
  100.  
  101. if (hydrofarm_flag == 0 && success == 1)
  102.  
  103. hydrofarm_flag = 1;
  104.  
  105. break;
  106.  
  107. case 3:
  108.  
  109. success = build_chargestation(chargestation_flag,
  110.  
  111. weather_status, robot_charge, elecfarm_flag);
  112.  
  113. if (chargestation_flag == 0 && success == 1)
  114.  
  115. chargestation_flag = 1;
  116.  
  117. break;
  118.  
  119. case 4:
  120.  
  121. success = build_elecfarm(elecfarm_flag, weather_status,
  122.  
  123. robot_charge);
  124.  
  125. if (elecfarm_flag == 0 && success == 1)
  126.  
  127. elecfarm_flag = 1;
  128.  
  129. break;
  130.  
  131. case 5:
  132.  
  133. success = build_waterpipes(water_flag, weather_status,
  134.  
  135. robot_charge);
  136.  
  137. if (water_flag == 0 && success == 1)
  138.  
  139. water_flag = 1;
  140.  
  141. break;
  142.  
  143. case 6:
  144.  
  145. success = recharge(elecfarm_flag, chargestation_flag);
  146.  
  147. break;
  148.  
  149. default:
  150.  
  151. printf("You have chosen to do nothing this week.\n");
  152.  
  153. break;
  154.  
  155. }
  156.  
  157. // Check to see if the colony is complete
  158.  
  159. if(is_complete(habitat_flag, hydrofarm_flag, chargestation_flag,
  160.  
  161. elecfarm_flag, water_flag))
  162.  
  163. break;
  164.  
  165. // At the end of the week, update the robot's charge and
  166.  
  167. // Print the end of week status report
  168.  
  169. robot_charge = update_charge(robot_charge, weather_status,
  170.  
  171. weekly_task, success);
  172.  
  173. status(current_week, robot_charge);
  174.  
  175. }
  176.  
  177. // When all the week are complete - or if is_complete causes
  178.  
  179. // the loop to terminate early, print the final report
  180.  
  181. final_report(habitat_flag, hydrofarm_flag, chargestation_flag,
  182.  
  183. elecfarm_flag, water_flag);
  184.  
  185. return 0;
  186.  
  187. }
  188.  
  189. // Pre-condition: None
  190.  
  191. // Post-condition: The weather report for the day is printed and the
  192.  
  193. // corresponding weather status in between 1 and 10,
  194.  
  195. // inclusive, is returned.
  196.  
  197. int weather() {
  198.  
  199. // Generate weather status value.
  200.  
  201. int retval = rand() % 10 + 1;
  202.  
  203. printf("Here is the weather forecast:\n");
  204.  
  205. // Print out the appropriate forecast for that status.
  206.  
  207. switch (retval) {
  208.  
  209. case 1:
  210.  
  211. case 2:
  212.  
  213. case 3:
  214.  
  215. case 4:
  216.  
  217. printf("It is clear and calm this week.\n");
  218.  
  219. break;
  220.  
  221. case 5:
  222.  
  223. case 6:
  224.  
  225. printf("Meteor showers are expected this week.\n");
  226.  
  227. break;
  228.  
  229. case 7:
  230.  
  231. case 8:
  232.  
  233. printf("A wind storm is expected this week.\n");
  234.  
  235. break;
  236.  
  237. case 9:
  238.  
  239. case 10:
  240.  
  241. printf("A solar flare is expected this week.\n");
  242.  
  243. break;
  244.  
  245. }
  246.  
  247. // Return this status value.
  248.  
  249. return retval;
  250.  
  251. }
  252.  
  253. // Pre-condition: current_week is an integer representing the current week
  254.  
  255. // Post-condition: returns the weather status value for the current week
  256.  
  257. int startWeek(int current_week) {
  258.  
  259. }
  260.  
  261. // Pre-condition: current_week is an integer representing the current week
  262.  
  263. // robot_charge is an integer representing the current charge
  264.  
  265. // of the building robots
  266.  
  267. // Post-condition: print the status report for the end of the week
  268.  
  269. // What to do in this function: Tell the user how many weeks remain and how
  270.  
  271. // much charge the robots currently have
  272.  
  273. // Note: Please see the output specification text document for exact
  274.  
  275. // output formats
  276.  
  277. void status(int current_week, int robot_charge) {
  278.  
  279. }
  280.  
  281. // Pre-condition: robot_charge is an integer representing the current charge
  282.  
  283. // of the building robots, weather status is an integer
  284.  
  285. // representing the weather for this week
  286.  
  287. // weekly_task is an integer representing the task the robots
  288.  
  289. // undertook for the week.
  290.  
  291. // success is flag that indicates whether or not the robots
  292.  
  293. // were successful in their weekly task
  294.  
  295. // Post-condition: return the updated charge for the robots
  296.  
  297. // What to do in this function: By default, the robot's charge should go down
  298.  
  299. // by 1 if they were successful this week. If they
  300.  
  301. // were not successful or if there was no task to
  302.  
  303. // be completed, their charge should not change.
  304.  
  305. // If they were successful and there is a solar
  306.  
  307. // flare happening, the charge should go to 0.
  308.  
  309. // If the robots are charging, the charge should be
  310.  
  311. // reset to the maximum charge.
  312.  
  313. // At no point should the charge be reduced below 0
  314.  
  315. int update_charge(int robot_charge, int weather_status, int weekly_task, int success) {
  316.  
  317. }
  318.  
  319. // Pre-condition: none
  320.  
  321. // Post-condition: return the user's choice of task for the week
  322.  
  323. // What to do in this function: Prompt the user with the menu and
  324.  
  325. // read in their response. Ensure that their
  326.  
  327. // response is a valid menu option and reprompt
  328.  
  329. // them if their response is not valid. Return
  330.  
  331. // their response once it is verified.
  332.  
  333. // Note: Please see the output specification text document for exact
  334.  
  335. // output formats
  336.  
  337. int menu() {
  338.  
  339. }
  340.  
  341. // Pre-condition: habitat_flag is an integer that represents whether or not
  342.  
  343. // the colony habitat has been built
  344.  
  345. // hydrofarm_flag is an integer that represents whether or not
  346.  
  347. // the colony hydroponics farm has been built
  348.  
  349. // chargestation_flag is an integer that represents whether or
  350.  
  351. // not the colony charging station has been built
  352.  
  353. // elecfarm_flag is an integer that represents whether or not
  354.  
  355. // the colony wind and solar farm has been built
  356.  
  357. // water_flag is an integer that represents whether or not
  358.  
  359. // the colony water pipes have been built
  360.  
  361. // Post-condition: return 1 for true if all the buildings have been built, and
  362.  
  363. // 0 for false if any building has not been build yet.
  364.  
  365. int is_complete(int habitat_flag, int hydrofarm_flag, int chargestation_flag,
  366.  
  367. int elecfarm_flag, int water_flag) {
  368.  
  369. }
  370.  
  371. // Pre-condition: habitat_flag is an integer that represents whether or not
  372.  
  373. // the colony habitat has been built
  374.  
  375. // hydrofarm_flag is an integer that represents whether or not
  376.  
  377. // the colony hydroponics farm has been built
  378.  
  379. // chargestation_flag is an integer that represents whether or
  380.  
  381. // not the colony charging station has been built
  382.  
  383. // elecfarm_flag is an integer that represents whether or not
  384.  
  385. // the colony wind and solar farm has been built
  386.  
  387. // water_flag is an integer that represents whether or not
  388.  
  389. // the colony water pipes have been built
  390.  
  391. // Post-condition: print a final report for the colony, based on whether the
  392.  
  393. // colony is complete or not
  394.  
  395. // Note: Please see the output specification text document for exact
  396.  
  397. // output formats
  398.  
  399. void final_report(int habitat_flag, int hydrofarm_flag, int chargestation_flag,
  400.  
  401. int elecfarm_flag, int water_flag) {
  402.  
  403. }
  404.  
  405. // Pre-condition: habitat_flag is an integer that represents whether or not
  406.  
  407. // the colony habitat has been built
  408.  
  409. // weather status is an integer representing the weather
  410.  
  411. // robot_charge is an integer representing the current charge
  412.  
  413. // of the building robots,
  414.  
  415. // hydrofarm_flag is an integer that represents whether or not
  416.  
  417. // the colony hydroponics farm has been built
  418.  
  419. // elecfarm_flag is an integer that represents whether or not
  420.  
  421. // the colony wind and solar farm has been built
  422.  
  423. // Post-condition: return 1 if the robots are able to successfully build a
  424.  
  425. // habitat and 0 if the robots are unsuccessful
  426.  
  427. // What to do in this function: Based on the input parameters check for:
  428.  
  429. // if the habitat already exists, if the robots
  430.  
  431. // have enough charge to build, and if the weather
  432.  
  433. // is favorable for building a habitat.
  434.  
  435. // Habitats cannot be built during a meteor shower
  436.  
  437. // or a wind storm.
  438.  
  439. // Check to see if the habitat has the needed
  440.  
  441. // support structures: hydroponics farm and
  442.  
  443. // wind and solar farm and print warnings if either
  444.  
  445. // is not present.
  446.  
  447. // When the habitat is successfully built, inform
  448.  
  449. // the user.
  450.  
  451. // Note: Please see the output specification text document for exact
  452.  
  453. // output formats
  454.  
  455. int build_habitat(int habitat_flag, int weather_status, int robot_charge,
  456.  
  457. int hydrofarm_flag, int elecfarm_flag) {
  458.  
  459. }
  460.  
  461. // Pre-condition: hydrofarm_flag is an integer that represents whether or not
  462.  
  463. // the colony hydroponics farm has been built
  464.  
  465. // weather status is an integer representing the weather
  466.  
  467. // robot_charge is an integer representing the current charge
  468.  
  469. // of the building robots,
  470.  
  471. // water_flag is an integer that represents whether or not
  472.  
  473. // the colony water pipes have been built
  474.  
  475. // elecfarm_flag is an integer that represents whether or not
  476.  
  477. // the colony wind and solar farm has been built
  478.  
  479. // Post-condition: return 1 if the robots are able to successfully build a
  480.  
  481. // hydroponics farm and 0 if the robots are unsuccessful
  482.  
  483. // What to do in this function: Based on the input parameters check for:
  484.  
  485. // if the hydroponic farm already exists, if the
  486.  
  487. // robots have enough charge to build, and if the
  488.  
  489. // weather is favorable for building a hydroponic
  490.  
  491. // farm. Hydroponic farms cannot be built during a
  492.  
  493. // meteor shower or a wind storm.
  494.  
  495. // Check to see if the hydroponic farm has the
  496.  
  497. // needed support structures: water pipes and a
  498.  
  499. // wind and solar farm and print warnings if
  500.  
  501. // either is not present.
  502.  
  503. // When the hydroponic farm is successfully built,
  504.  
  505. // inform the user.
  506.  
  507. // Note: Please see the output specification text document for exact
  508.  
  509. // output formats
  510.  
  511. int build_hydrofarm(int hydrofarm_flag, int weather_status, int robot_charge,
  512.  
  513. int water_flag, int elecfarm_flag) {
  514.  
  515. }
  516.  
  517. // Pre-condition: chargestation_flag is an integer that represents whether or
  518.  
  519. // not the colony charging station has been built
  520.  
  521. // weather status is an integer representing the weather
  522.  
  523. // robot_charge is an integer representing the current charge
  524.  
  525. // of the building robots,
  526.  
  527. // elecfarm_flag is an integer that represents whether or not
  528.  
  529. // the colony wind and solar farm has been built
  530.  
  531. // Post-condition: return 1 if the robots are able to successfully build a
  532.  
  533. // charging station and 0 if the robots are unsuccessful
  534.  
  535. // What to do in this function: Based on the input parameters check for:
  536.  
  537. // if the charging station already exists, if the
  538.  
  539. // robots have enough charge to build, and if the
  540.  
  541. // weather is favorable for building a charging
  542.  
  543. // station. Charging stations cannot be built
  544.  
  545. // during a meteor shower.
  546.  
  547. // Check to see if the charging station has the
  548.  
  549. // needed support structure: a wind and solar farm
  550.  
  551. // and print a warning if it is not present.
  552.  
  553. // When the charing station is successfully built,
  554.  
  555. // inform the user.
  556.  
  557. // Note: Please see the output specification text document for exact
  558.  
  559. // output formats
  560.  
  561. int build_chargestation(int chargestation_flag, int weather_status,
  562.  
  563. int robot_charge, int elecfarm_flag) {
  564.  
  565. }
  566.  
  567. // Pre-condition: elecfarm_flag is an integer that represents whether or not
  568.  
  569. // the colony wind and solar farm has been built
  570.  
  571. // weather status is an integer representing the weather
  572.  
  573. // robot_charge is an integer representing the current charge
  574.  
  575. // of the building robots,
  576.  
  577. // Post-condition: return 1 if the robots are able to successfully build a
  578.  
  579. // wind and solar farm and 0 if the robots are unsuccessful
  580.  
  581. // What to do in this function: Based on the input parameters check for:
  582.  
  583. // if the wind and solar farm already exists, if
  584.  
  585. // the robots have enough charge to build, and if
  586.  
  587. // the weather is favorable for building a wind
  588.  
  589. // and solar farm. Wind and solar farms cannot
  590.  
  591. // be built during a meteor shower, wind storm,
  592.  
  593. // or solar flare.
  594.  
  595. // When the wind and solar farm is successfully
  596.  
  597. // built, inform the user.
  598.  
  599. // Note: Please see the output specification text document for exact
  600.  
  601. // output formats
  602.  
  603. int build_elecfarm(int elecfarm_flag, int weather_status, int robot_charge) {
  604.  
  605. }
  606.  
  607. // Pre-condition: water_flag is an integer that represents whether or not
  608.  
  609. // the colony water pipes have been built
  610.  
  611. // weather status is an integer representing the weather
  612.  
  613. // robot_charge is an integer representing the current charge
  614.  
  615. // of the building robots,
  616.  
  617. // Post-condition: return 1 if the robots are able to successfully build
  618.  
  619. // water pipes and 0 if the robots are unsuccessful
  620.  
  621. // What to do in this function: Based on the input parameters check for:
  622.  
  623. // if the water pipes already exists and if
  624.  
  625. // the robots have enough charge to build.
  626.  
  627. // When the water pipes are successfully
  628.  
  629. // built, inform the user.
  630.  
  631. // Note: Please see the output specification text document for exact
  632.  
  633. // output formats
  634.  
  635. int build_waterpipes(int water_flag, int weather_status, int robot_charge) {
  636.  
  637. }
  638.  
  639. // Pre-condition: elecfarm_flag is an integer that represents whether or not
  640.  
  641. // the colony wind and solar farm has been built
  642.  
  643. // chargestation_flag is an integer that represents whether or
  644.  
  645. // not the colony charging station has been built
  646.  
  647. // Post-condition: return 1 if the robots are able to successfully recharge
  648.  
  649. // and 0 if the robots are unsuccessful
  650.  
  651. // What to do in this function: Based on the input parameters check for:
  652.  
  653. // if the wind and solar farm exists and if
  654.  
  655. // the charging station exists. Both are
  656.  
  657. // needed to recharge the robots. If either is
  658.  
  659. // missing, inform the user and return 0.
  660.  
  661. // Note: Please see the output specification text document for exact
  662.  
  663. // output formats
  664.  
  665. int recharge(int elecfarm_flag, int chargestation_flag) {
  666.  
  667. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement