Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #define WEEKS 10
- #define MAXCHARGE 3
- int menu();
- int weather();
- int startWeek(int current_week);
- void status(int current_week, int robot_charge);
- int update_charge(int robot_charge, int weather_status, int weekly_task,
- int success);
- int is_complete(int habitat_flag, int hydrofarm_flag, int chargestation_flag,
- int elecfarm_flag, int water_flag);
- void final_report(int habitat_flag, int hydrofarm_flag, int chargestation_flag,
- int elecfarm_flag, int water_flag);
- int build_habitat(int habitat_flag, int weather_status, int robot_charge,
- int hydrofarm_flag, int elecfarm_flag);
- int build_hydrofarm(int hydrofarm_flag, int weather_status, int robot_charge,
- int water_flag, int elecfarm_flag);
- int build_chargestation(int chargestation_flag, int weather_status,
- int robot_charge, int elecfarm_flag);
- int build_elecfarm(int elecfarm_flag, int weather_status, int robot_charge);
- int build_waterpipes(int water_flag, int weather_status, int robot_charge);
- int recharge(int elecfarm_flag, int chargestation_flag);
- int main(void) {
- // Variables to store the current week, weather, task, success flag
- int current_week, weather_status, weekly_task, success;
- // Flags to denote whether or not critical buildings have been built yet
- // Robots begin with maximum charge
- int habitat_flag = 0, hydrofarm_flag = 0, chargestation_flag = 0;
- int elecfarm_flag = 0, water_flag = 0, robot_charge = MAXCHARGE;
- srand(time(0));
- // Week Loop
- // At the beginning of each week, prompt the user with the weather
- // And request task to be performed
- for(current_week = 1; current_week <= WEEKS; current_week++) {
- weather_status = startWeek(current_week);
- weekly_task = menu();
- // Call the function that matches the task and check to see if the
- // Robots are successful. When successful, update the building flag
- switch (weekly_task) {
- case 1:
- success = build_habitat(habitat_flag, weather_status,
- robot_charge, hydrofarm_flag, elecfarm_flag);
- if (habitat_flag == 0 && success == 1)
- habitat_flag = 1;
- break;
- case 2:
- success = build_hydrofarm(hydrofarm_flag, weather_status,
- robot_charge, water_flag, elecfarm_flag);
- if (hydrofarm_flag == 0 && success == 1)
- hydrofarm_flag = 1;
- break;
- case 3:
- success = build_chargestation(chargestation_flag,
- weather_status, robot_charge, elecfarm_flag);
- if (chargestation_flag == 0 && success == 1)
- chargestation_flag = 1;
- break;
- case 4:
- success = build_elecfarm(elecfarm_flag, weather_status,
- robot_charge);
- if (elecfarm_flag == 0 && success == 1)
- elecfarm_flag = 1;
- break;
- case 5:
- success = build_waterpipes(water_flag, weather_status,
- robot_charge);
- if (water_flag == 0 && success == 1)
- water_flag = 1;
- break;
- case 6:
- success = recharge(elecfarm_flag, chargestation_flag);
- break;
- default:
- printf("You have chosen to do nothing this week.\n");
- break;
- }
- // Check to see if the colony is complete
- if(is_complete(habitat_flag, hydrofarm_flag, chargestation_flag,
- elecfarm_flag, water_flag))
- break;
- // At the end of the week, update the robot's charge and
- // Print the end of week status report
- robot_charge = update_charge(robot_charge, weather_status,
- weekly_task, success);
- status(current_week, robot_charge);
- }
- // When all the week are complete - or if is_complete causes
- // the loop to terminate early, print the final report
- final_report(habitat_flag, hydrofarm_flag, chargestation_flag,
- elecfarm_flag, water_flag);
- return 0;
- }
- // Pre-condition: None
- // Post-condition: The weather report for the day is printed and the
- // corresponding weather status in between 1 and 10,
- // inclusive, is returned.
- int weather() {
- // Generate weather status value.
- int retval = rand() % 10 + 1;
- printf("Here is the weather forecast:\n");
- // Print out the appropriate forecast for that status.
- switch (retval) {
- case 1:
- case 2:
- case 3:
- case 4:
- printf("It is clear and calm this week.\n");
- break;
- case 5:
- case 6:
- printf("Meteor showers are expected this week.\n");
- break;
- case 7:
- case 8:
- printf("A wind storm is expected this week.\n");
- break;
- case 9:
- case 10:
- printf("A solar flare is expected this week.\n");
- break;
- }
- // Return this status value.
- return retval;
- }
- // Pre-condition: current_week is an integer representing the current week
- // Post-condition: returns the weather status value for the current week
- int startWeek(int current_week) {
- }
- // Pre-condition: current_week is an integer representing the current week
- // robot_charge is an integer representing the current charge
- // of the building robots
- // Post-condition: print the status report for the end of the week
- // What to do in this function: Tell the user how many weeks remain and how
- // much charge the robots currently have
- // Note: Please see the output specification text document for exact
- // output formats
- void status(int current_week, int robot_charge) {
- }
- // Pre-condition: robot_charge is an integer representing the current charge
- // of the building robots, weather status is an integer
- // representing the weather for this week
- // weekly_task is an integer representing the task the robots
- // undertook for the week.
- // success is flag that indicates whether or not the robots
- // were successful in their weekly task
- // Post-condition: return the updated charge for the robots
- // What to do in this function: By default, the robot's charge should go down
- // by 1 if they were successful this week. If they
- // were not successful or if there was no task to
- // be completed, their charge should not change.
- // If they were successful and there is a solar
- // flare happening, the charge should go to 0.
- // If the robots are charging, the charge should be
- // reset to the maximum charge.
- // At no point should the charge be reduced below 0
- int update_charge(int robot_charge, int weather_status, int weekly_task, int success) {
- }
- // Pre-condition: none
- // Post-condition: return the user's choice of task for the week
- // What to do in this function: Prompt the user with the menu and
- // read in their response. Ensure that their
- // response is a valid menu option and reprompt
- // them if their response is not valid. Return
- // their response once it is verified.
- // Note: Please see the output specification text document for exact
- // output formats
- int menu() {
- }
- // Pre-condition: habitat_flag is an integer that represents whether or not
- // the colony habitat has been built
- // hydrofarm_flag is an integer that represents whether or not
- // the colony hydroponics farm has been built
- // chargestation_flag is an integer that represents whether or
- // not the colony charging station has been built
- // elecfarm_flag is an integer that represents whether or not
- // the colony wind and solar farm has been built
- // water_flag is an integer that represents whether or not
- // the colony water pipes have been built
- // Post-condition: return 1 for true if all the buildings have been built, and
- // 0 for false if any building has not been build yet.
- int is_complete(int habitat_flag, int hydrofarm_flag, int chargestation_flag,
- int elecfarm_flag, int water_flag) {
- }
- // Pre-condition: habitat_flag is an integer that represents whether or not
- // the colony habitat has been built
- // hydrofarm_flag is an integer that represents whether or not
- // the colony hydroponics farm has been built
- // chargestation_flag is an integer that represents whether or
- // not the colony charging station has been built
- // elecfarm_flag is an integer that represents whether or not
- // the colony wind and solar farm has been built
- // water_flag is an integer that represents whether or not
- // the colony water pipes have been built
- // Post-condition: print a final report for the colony, based on whether the
- // colony is complete or not
- // Note: Please see the output specification text document for exact
- // output formats
- void final_report(int habitat_flag, int hydrofarm_flag, int chargestation_flag,
- int elecfarm_flag, int water_flag) {
- }
- // Pre-condition: habitat_flag is an integer that represents whether or not
- // the colony habitat has been built
- // weather status is an integer representing the weather
- // robot_charge is an integer representing the current charge
- // of the building robots,
- // hydrofarm_flag is an integer that represents whether or not
- // the colony hydroponics farm has been built
- // elecfarm_flag is an integer that represents whether or not
- // the colony wind and solar farm has been built
- // Post-condition: return 1 if the robots are able to successfully build a
- // habitat and 0 if the robots are unsuccessful
- // What to do in this function: Based on the input parameters check for:
- // if the habitat already exists, if the robots
- // have enough charge to build, and if the weather
- // is favorable for building a habitat.
- // Habitats cannot be built during a meteor shower
- // or a wind storm.
- // Check to see if the habitat has the needed
- // support structures: hydroponics farm and
- // wind and solar farm and print warnings if either
- // is not present.
- // When the habitat is successfully built, inform
- // the user.
- // Note: Please see the output specification text document for exact
- // output formats
- int build_habitat(int habitat_flag, int weather_status, int robot_charge,
- int hydrofarm_flag, int elecfarm_flag) {
- }
- // Pre-condition: hydrofarm_flag is an integer that represents whether or not
- // the colony hydroponics farm has been built
- // weather status is an integer representing the weather
- // robot_charge is an integer representing the current charge
- // of the building robots,
- // water_flag is an integer that represents whether or not
- // the colony water pipes have been built
- // elecfarm_flag is an integer that represents whether or not
- // the colony wind and solar farm has been built
- // Post-condition: return 1 if the robots are able to successfully build a
- // hydroponics farm and 0 if the robots are unsuccessful
- // What to do in this function: Based on the input parameters check for:
- // if the hydroponic farm already exists, if the
- // robots have enough charge to build, and if the
- // weather is favorable for building a hydroponic
- // farm. Hydroponic farms cannot be built during a
- // meteor shower or a wind storm.
- // Check to see if the hydroponic farm has the
- // needed support structures: water pipes and a
- // wind and solar farm and print warnings if
- // either is not present.
- // When the hydroponic farm is successfully built,
- // inform the user.
- // Note: Please see the output specification text document for exact
- // output formats
- int build_hydrofarm(int hydrofarm_flag, int weather_status, int robot_charge,
- int water_flag, int elecfarm_flag) {
- }
- // Pre-condition: chargestation_flag is an integer that represents whether or
- // not the colony charging station has been built
- // weather status is an integer representing the weather
- // robot_charge is an integer representing the current charge
- // of the building robots,
- // elecfarm_flag is an integer that represents whether or not
- // the colony wind and solar farm has been built
- // Post-condition: return 1 if the robots are able to successfully build a
- // charging station and 0 if the robots are unsuccessful
- // What to do in this function: Based on the input parameters check for:
- // if the charging station already exists, if the
- // robots have enough charge to build, and if the
- // weather is favorable for building a charging
- // station. Charging stations cannot be built
- // during a meteor shower.
- // Check to see if the charging station has the
- // needed support structure: a wind and solar farm
- // and print a warning if it is not present.
- // When the charing station is successfully built,
- // inform the user.
- // Note: Please see the output specification text document for exact
- // output formats
- int build_chargestation(int chargestation_flag, int weather_status,
- int robot_charge, int elecfarm_flag) {
- }
- // Pre-condition: elecfarm_flag is an integer that represents whether or not
- // the colony wind and solar farm has been built
- // weather status is an integer representing the weather
- // robot_charge is an integer representing the current charge
- // of the building robots,
- // Post-condition: return 1 if the robots are able to successfully build a
- // wind and solar farm and 0 if the robots are unsuccessful
- // What to do in this function: Based on the input parameters check for:
- // if the wind and solar farm already exists, if
- // the robots have enough charge to build, and if
- // the weather is favorable for building a wind
- // and solar farm. Wind and solar farms cannot
- // be built during a meteor shower, wind storm,
- // or solar flare.
- // When the wind and solar farm is successfully
- // built, inform the user.
- // Note: Please see the output specification text document for exact
- // output formats
- int build_elecfarm(int elecfarm_flag, int weather_status, int robot_charge) {
- }
- // Pre-condition: water_flag is an integer that represents whether or not
- // the colony water pipes have been built
- // weather status is an integer representing the weather
- // robot_charge is an integer representing the current charge
- // of the building robots,
- // Post-condition: return 1 if the robots are able to successfully build
- // water pipes and 0 if the robots are unsuccessful
- // What to do in this function: Based on the input parameters check for:
- // if the water pipes already exists and if
- // the robots have enough charge to build.
- // When the water pipes are successfully
- // built, inform the user.
- // Note: Please see the output specification text document for exact
- // output formats
- int build_waterpipes(int water_flag, int weather_status, int robot_charge) {
- }
- // Pre-condition: elecfarm_flag is an integer that represents whether or not
- // the colony wind and solar farm has been built
- // chargestation_flag is an integer that represents whether or
- // not the colony charging station has been built
- // Post-condition: return 1 if the robots are able to successfully recharge
- // and 0 if the robots are unsuccessful
- // What to do in this function: Based on the input parameters check for:
- // if the wind and solar farm exists and if
- // the charging station exists. Both are
- // needed to recharge the robots. If either is
- // missing, inform the user and return 0.
- // Note: Please see the output specification text document for exact
- // output formats
- int recharge(int elecfarm_flag, int chargestation_flag) {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement