// ********************************************************************* // Description: Land Area // ********************************************************************* #include //Preprocessor directive to be able to use cout. #include //Preprocessor directive to be able to use setprecision. #include //Preprocessor directive to be ablt to output to file. using namespace std; //Uses standard namespace. //Function prototypes void showMenu(); float getFeet(); float getMiles(); float getYards(); float getFurlong(); void printOut(float); int main () //Main function { int choice; //To hold menu choice //Constants for the menu choice const int FEET_CHOICE = 1, MILES_CHOICE = 2, YARDS_CHOICE = 3, FURLONG_CHOICE = 4, QUIT_CHOICE = 5; do { //Display menu and get user's choice showMenu(); cin >> choice; //Validate menu selection while (choice < FEET_CHOICE || choice > QUIT_CHOICE) { cout << "Please entere a valid menu choice:"; cin >> choice; } if (choice != QUIT_CHOICE) { switch(choice) { case FEET_CHOICE: printOut(getFeet()); break; case MILES_CHOICE: printOut(getMiles()); break; case YARDS_CHOICE: printOut(getYards()); break; case FURLONG_CHOICE: printOut(getFurlong()); break; } } } while (choice != QUIT_CHOICE); return 0; } //************************************************************* // Definition of function showMenu which displays the menu. * //************************************************************* void showMenu() { cout << "\n\t\tMenu\n\n" << "1. Input Feet\n" << "2. Input Miles\n" << "3. Input Yards\n" << "4. Input Furlong\n" << "5. Quit\n" << "Enter your choice: "; } //************************************************************** // Definition of function getFeet which gets length and width. * //************************************************************** float getFeet() { float width; float length; cout << "\nPlease input width in feet: "; cin >> width; cout << "\nPlease input length in feet: "; cin >> length; fstream outputFile; outputFile.open("LandAreaOutput.txt", ios::out | ios::app); outputFile << "Width of " << width << " feet and length of " << length << " feet is "; outputFile.close(); return (width*length); } //************************************************************** // Definition of function getMiles which gets length and width.* //************************************************************** float getMiles() { float width; float length; cout << "\nPlease input width in miles: "; cin >> width; cout << "\nPlease input length in miles: "; cin >> length; fstream outputFile; outputFile.open("LandAreaOutput.txt", ios::out | ios::app); outputFile << "Width of " << width << " miles and length of " << length << " miles is "; outputFile.close(); return (width*length*27878400); } //************************************************************** // Definition of function getYards which gets length and width.* //************************************************************** float getYards() { float width; float length; cout << "\nPlease input width in yards: "; cin >> width; cout << "\nPlease input length in yards: "; cin >> length; fstream outputFile; outputFile.open("LandAreaOutput.txt", ios::out | ios::app); outputFile << "Width of " << width << " yards and length of " << length << " yards is "; outputFile.close(); return (width*length*9); } //**************************************************************** // Definition of function getFurlong which gets length and width.* //**************************************************************** float getFurlong() { float width; float length; cout << "\nPlease input width in furlongs: "; cin >> width; cout << "\nPlease input length in furlongs: "; cin >> length; fstream outputFile; outputFile.open("LandAreaOutput.txt", ios::out | ios::app); outputFile << "Width of " << width << " furlongs and length of " << length << " furlongs is "; outputFile.close(); return (width*length*435600); } //************************************************************** // Definition of function feetOut which outputs conversions .* //************************************************************** void printOut(float sqFeet) { fstream outputFile; outputFile << fixed << showpoint; outputFile << setprecision(2); outputFile.open("LandAreaOutput.txt", ios::out | ios::app); outputFile << sqFeet << " sq feet, " << sqFeet/43560 << " Eng acres, " << sqFeet/55321 << " Scot acres, " << sqFeet/70560 << " Irish acres, " << sqFeet/107639 << " Hectares, " << sqFeet/26910 << " Morgen (metric), " << sqFeet/5227200 << " Hides(std). " << "\n"; outputFile.close(); }