Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This should be a C++ program The Bumpkins of Bumpus 1. (Borrowed from ACM progra

ID: 3802610 • Letter: T

Question

This should be a C++ program

The Bumpkins of Bumpus 1. (Borrowed from ACM programming team 2002) Create a program file named bumpkin. cpp to solve the following problem The people of Bumpus (Bumpkins) are a fun, happy, peace loving people who have a big problem. They have very little depth perception and are constantly running into doors They've asked you to write a program to let them know when they should duck going through a doorway Since Bumpkins love fun, some of their doorways have been made intentionally short of force other Bumpkins to either crawl or limbo through the door Unfortunately, the Bumpkins don't all use the same set of measurements so some heights are measured in inches, others in feet, others in yards, others in centimeters, and others in meters. To do the conversions recall that: 1 inch 2.52 cm yard 3 ft 1 foot. 12 inches 1 meter 100 cm Input The input file, bumpkin data. txt, will begin with a single line, telling you how many Bumpkins want help. Then, for each Bumpkin, there will be data about the Bumpkin and the doorways they reach. The first line of each dataset will give you the Bumpkin's name (all Bumpkins have names of exactly 6 characters) an integer n the number of doors to process for this Bumpkin (n 0), and the Bumpkin's height, a floating point number followed by exactly one blank and then one of 'i', 'f', 'y', 'c', or 'm' representing inches feet, yards, centimeters, and meters). The next n lines will have the height of the doorways in the bumpkin's life, one per line Each height will be a floating point number followed by exactly one blank and one of 'i', 'f' y 'c', or 'm' (representing inches, feet, yards cm, and meters Output. For each bumpkin, print the name of the Bumpkin on one line and then for each door print the way the Bumpkin should travel through the door Decide on a mode of travel based on the table below where b is the height of the Bumpkin, d is the height of the door expressed in the same units) Door Height Travel Method d b 1.25 Stilts b 25 a b 1.05 Walk b 05 d b 0.65 Duck b 0.65 d b 0.40 Crawl

Explanation / Answer

#include<iostream>
#include<fstream>
#include<string>
#define MAX 100
#define MAX_DOORS 50
using namespace std;

struct bumkin
{
   string name;
   //no of door
   int n;
   float height;
   float door_height[MAX];
   //number of bumkin
   int no_bumpkin;
   char height_unit;
   char door_height_unit[MAX_DOORS];
};
//function declaration
void display(struct bumkin[], int n);
string calculate(float h, float d_height, char door_unit, char height_unit);
int main()
{
   //local variable declaration
   string name[MAX];
   struct bumkin bumpkin[MAX];
   ifstream in;
   //open file
   in.open("bumpkin.txt");
   if (!in)
   {
       cout << "Not able to open file bumpkin, check if file exists" << endl;
   }
   int i = 0, n;
   in >> bumpkin[i].no_bumpkin;
   n = bumpkin[i].no_bumpkin;
   for (int i = 0; i < n;i++)
   {
       in >> bumpkin[i].name >> bumpkin[i].n>>bumpkin[i].height >> bumpkin[i].height_unit;
       for (int j = 0; j < bumpkin[i].n;j++)
           in >> bumpkin[i].door_height[j] >> bumpkin[i].door_height_unit[j];
      
   }
   //display result
   display(bumpkin, n);
}

void display(struct bumkin b[], int n)
{
   for (int i = 0; i < n; i++)
   {
       cout << b[i].name << endl;
       for (int j = 0; j < b[i].n; j++)
       {
           cout << "Doorway " << j + 1 << " : " << calculate(b[i].height, b[i].door_height[j], b[i].door_height_unit[j], b[i].height_unit) << endl;
       }
   }
}

string calculate(float b, float d,char door_unit,char height_unit)
{
   //convert height to lowest unit c
   string s;
   switch (height_unit)
   {
   case 'i':
       b = b*2.52;
       break;
   case 'y':
       b *= 36 * 2.52; //as y = 3ft and 1 foot = 12 in
       break;
   case 'f':
       b *= 12 * 2.52;
       break;
   case 'm':
       b *= 100;
       break;
   case 'c':
   default:
       //no need to convert
       break;
   }
   //convert door_height to lowest unit c
   switch (door_unit)
   {
   case 'i':
       d = d*2.52;
       break;
   case 'y':
       d *= 36 * 2.52; //as y = 3ft and 1 foot = 12 in
       break;
   case 'f':
       d *= 12 * 2.52;
       break;
   case 'm':
       d *= 100;
       break;
   case 'c':
   default:
       //no need to convert
       break;
   }

   if (d > b*1.25)
   {
       s = "Stilts";
       return s;
   }
   float b1, b2, b3;
   b1 = b* 1.25;
   b2 = b*1.05;
   b3 = b *0.65;
   if (b3 >= (d > (b*0.40)))
   {
       s = "Crawl";
       return s;
   }
   if ( b1 >= (d > (b*1.05)))
   {
       s = "Walk";
       return s;
   }
   if (b2 >= (d > (b*0.65)))
   {
       s = "Duck";
       return s;
   }
  
   if ((b*0.40) >= (d > (b*0.25)))
   {
       s = "Limbo";
       return s;
   }
   if ((b*0.25) >= d )
   {
       s = "Blocked";
       return s;
   }
   else
       return "";
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote