I need help writing this C++ code for my CS homework, I\'ve already tried it mys
ID: 3747223 • Letter: I
Question
I need help writing this C++ code for my CS homework, I've already tried it myself but am having no luck.
Summary: compute wing loading value based on aircraft's weight and wing area
An important design factor in aeronautical engineering is wing loading, defined as the weight of an airplane divided by its wing area. Low wing loading provides more maneuverability, but a bumpier, less comfortable flight; hang gliders have low wing loading. High wing loading is more fuel efficient and provides a more comfortable ride, but the plane is less maneuverable; commercial jetliners have high wing loading.
Write a C++ program to input two values, the weight of an airplane followed by its wing area, compute the wing loading value, and output two results: (1) the wing loading value, followed by (2) “low”, “average”, or “high” — low if the wing loading value is less than 20.0, high if the wing loading value is greater than 600.0, otherwise average. Assume the input units are kilograms for the weight, and meters squared for the area.
Example: suppose the inputs to the program are the following (weight then wing area):
The output should be:
There is one space following the ":", and the output should appear on a line by itself (i.e. follow with endl). It is possible for one or both inputs to be negative, in which case the computation makes no sense --- in this case output "invalid data!" at most once. For example, suppose the inputs are
The output should be
This implies the program has exactly one output: either "invalid data!", or the wing loading value followed by low, average, or high.
Explanation / Answer
#include <iostream>
using namespace std;
// main function definition
int main()
{
double weight, area, result;
// Accept weight
cout<<" Enter the aircraft's weight: ";
cin>>weight;
// Checks if weight is negative
if(weight < 0)
{
cout<<" Invalid data!";
return 0;
}// End of if condition
// Accept wing area
cout<<" Enter the wing area: ";
cin>>area;
// Checks if wing are is negative
if(area < 0)
{
cout<<" Invalid data!";
return 0;
}// End of if condition
// Calculate wing loading value
result = weight / area;
// Checks if result is less than 20.0
if(result < 20.0)
cout<<" The wing loading value "<<result<<": low.";
// Otherwise checks if result is less than 600.0
else if(result > 600.0)
cout<<" The wing loading value "<<result<<": high.";
// Otherwise
else
cout<<" The wing loading value "<<result<<": average.";
return 0;
}// End of main function
Sample Output 1:
Enter the aircraft's weight: 130.6
Enter the wing area: 13.7
The wing loading value 9.53285: low.
Sample Output 2:
Enter the aircraft's weight: 1200.50
Enter the wing area: -10.00
Invalid data!
Sample Output 3:
Enter the aircraft's weight: -12.23
Invalid data!