Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
CHALLENGE 12: PROJECT 2
//Project 2: Implement the Code for controlling the retraction and extension of Airplane’s landing gear//
Overview of the Project: (5 to 6 lines)
That's a high-level overview of the program. It provides a basic framework for controlling the retraction and extension of an airplane's landing gear using a simple command-line interface. This code provides a basic command-line interface where you can enter 'E' to extend the landing gear, 'R' to retract it, and 'Q' to quit the program.
Goals (2 to 3 points)
The goal of this program is to provide a basic simulation of controlling the retraction and extension of an airplane's landing gear. It allows the user to interact with the program through a command-line interface and provides options to extend or retract the landing gear.
While the program itself does not include the actual code to control the landing gear (as indicated by the TODO comments), it serves as a framework that can be expanded upon. The functions extendLandingGear() and retractLandingGear() can be modified to include the appropriate code to interface with the airplane's landing gear control system.
Key Highlights of the Project: (4 to 5 point)
Command-Line Interface: The program provides a simple command-line interface where the user can interact by entering commands to extend or retract the landing gear.
State Tracking: The program uses the boolean variable landingGearExtended to track the current state of the landing gear. This variable is updated accordingly when the gear is extended or retracted.
Error Handling: The program includes error handling for invalid user inputs. If the user enters an invalid command, an appropriate error message is displayed.
Modular Structure: The program follows a modular structure by defining separate functions extendLandingGear() and retractLandingGear() for simulating the actions of extending and retracting the landing gear. This structure allows for easy modification and expansion of the codebase.
Placeholder Functions: The program includes placeholder functions extendLandingGear() and retractLandingGear() that can be replaced with the actual code to control the landing gear in a real application. These functions serve as a starting point for integrating the program with the hardware or software system responsible for managing the landing gear.
Looping Execution: The program utilizes an infinite loop to continuously prompt the user for input until the user chooses to quit. This ensures that the program remains interactive and responsive.
Deliverables of this project: (4 to 5 points)
C code: The main deliverable is the C code provided earlier, which implements the basic functionality of controlling the retraction and extension of the landing gear. This code serves as a starting point for further development and integration into a larger system.
Command-line interface: The program provides a command-line interface that allows users to interact with the landing gear control system by entering commands to extend or retract the landing gear. The interface provides feedback messages based on the current state of the landing gear.
Placeholder functions: The code includes placeholder functions extendLandingGear() and retractLandingGear() that simulate the actions of extending and retracting the landing gear. These functions can be replaced with the actual code to control the landing gear in a real application.
Modular structure: The program follows a modular structure by separating the code into functions. This allows for easier maintenance, expansion, and integration with other components of a larger system.
Error handling: The program includes error handling for invalid user inputs. If the user enters an invalid command, the program displays an appropriate error message, ensuring a more robust user experience.
Simulated behavior: The program simulates the actions of extending and retracting the landing gear by displaying messages indicating the status of the gear. While it does not include the actual control code for the landing gear, it provides a framework for integrating that functionality.
Expected Outcomes: (4 to 5 points)
Command Prompt: The program will display a command prompt asking the user to enter a command: 'E' to extend the landing gear, 'R' to retract it, or 'Q' to quit.
User Input: The program will wait for the user to input a valid command.
Extend Landing Gear: If the user enters 'E' and the landing gear is not already extended, the program will display a message indicating that it is extending the landing gear.
Retract Landing Gear: If the user enters 'R' and the landing gear is not already retracted, the program will display a message indicating that it is retracting the landing gear.
Error Handling: If the user enters an invalid command or tries to extend/retract the landing gear when it is already in the desired position, the program will display an appropriate error message.
Loop: After processing a command, the program will return to the command prompt and wait for the next user input. This loop will continue until the user chooses to quit by entering 'Q'.
Program:
#include <stdio.h>
#include <stdbool.h>
// Function prototypes
void extendLandingGear();
void retractLandingGear();
// Variable to track the current state of the landing gear
bool landingGearExtended = false;
int main()
{
char input;
while (1)
{
printf("\n\nEnter 'E' to extend landing gear, \n'R' to retract landing gear, or \n'Q' to quit: ");
scanf(" %c", &input);
switch (input)
{
case 'E':
if (!landingGearExtended)
{
extendLandingGear();
landingGearExtended = true;
} else {
printf("\nLanding gear is already extended.\n");
}
break;
case 'R':
if (landingGearExtended)
{
retractLandingGear();
landingGearExtended = false;
} else {
printf("\nLanding gear is already retracted.\n");
}
break;
case 'Q':
printf("\nExiting...\n");
return 0;
default:
printf("\nInvalid input. Try again.\n");
break;
}
}
return 0;
}
// Function to simulate extending the landing gear
void extendLandingGear()
{
printf("\nExtending landing gear...\n");
// TODO: Add actual code to control the landing gear
}
// Function to simulate retracting the landing gear
void retractLandingGear()
{
printf("\nRetracting landing gear...\n");
// TODO: Add actual code to control the landing gear
}
Output:
Enter 'E' to extend landing gear,
'R' to retract landing gear, or
'Q' to quit: E
Extending landing gear...
Enter 'E' to extend landing gear,
'R' to retract landing gear, or
'Q' to quit: R
Retracting landing gear...
Enter 'E' to extend landing gear,
'R' to retract landing gear, or
'Q' to quit: Q
Exiting...