I need help with this sample problem because a question like this will be on my test, i am so lost, can someone show me how you would even do this.
Arthur, King of the Britons, has tasked you with figuring out the amount of time it would take his
faithful messenger birds to carry messages (which may or may not be in coconuts) across certain
distances. His assistant, Patsy, has provided you with a table that contains the speed of the birds,
and the letter with which the birds will be referred to. Use the table to calculate the times.
Call this file timer.cpp
Bird Speed (m/s) Reference Letter
African Swallow 12.3 S
African Swallow + Coconut 10.97 A
European Swallow 12.8 U
European Swallow + Coconut 10.73 C
Barn Swallow 10.64 B
Barn Swallow + Coconut 9.2 W
1. Print a menu for the user. In the menu, display the birds and their
reference letters. (7
points).
2. Prompt the user the enter the bird in question. Read in the reference
letter. (5 points)
3. Prompt the user to enter the distance (in kilometers) and read in the value (5 points).
4. Use a switch statement on the reference letter to figure out the speed. If the reference letter
is invalid, print an error message. (15 points).
5. Calculate the time taken by the bird and print it, accurate to 4 digits after the decimal point.
(8 points).
6. If the reference letter entered doesn’t match any bird, print an error message (5 points)
7. Add comments wherever appropriate to explain your logic. (5 points)
8. You can assume that the user will only enter the proper type of data, an uppercase character
for the reference letter and a floating point number for the distance
Please note that this is not a homework site. We won't do your homework for you. The purpose of homework is that you learn by doing. However we are always willing to help solve problems you encountered, correct mistakes you made in your code and answer your questions.
We didn't see your attempts to solve this problem yourself and so we cannot correct mistakes you didn't made and answer questions you didn't ask. To get help you should do something yourself and get real problems with something. If your problem is "I don't understand a thing", then you should go back to basics and study again.
Or say that you do not understand the instructions or how to figure them out.
// <--- Most comon includes.
#include <iostream>
#include <iomanip>
#include <string>
#include <limits>
#include <chrono>
#include <thread>
// Extras.
#include <cctype>
#include <map>
#include "Struct Table.hpp"
// --- Add any header files you create.
// <--- Constant global variables.
// <--- Prototypes.
char MainMenu();
double GetDistance();
int main()
{
// <--- Define variables
char choice{};
double distance{};
std::map<char, double> birds;
Bird bird;
// <--- Your code here.
choice = MainMenu();
bird.LoadMap(birds);
switch (choice)
{
case'A':
distance = GetDistance();
break;
case'B':
break;
case'C':
break;
case'S':
break;
case'U':
break;
case'W':
break;
default:
break;
}
// <--- Keeps console window open when running in debug mode on Visual Studio.
// The next line may not be needed. If you have to press enter to see the prompt it is not needed.
//std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // <--- Requires header file <limits>.
std::cout << "\n\n Press Enter to continue";
std::cin.get();
return 0;
}
My first thoughts, but still working on it. There is a big difference between what I know and what you know. This makes it hard roe me to figure out what you can do.
2) You've defined the variables S, A etc to be int, and yet you're trying to assign floating-point values to them. What do you think is going to happen there?
3) You've defined x as a double. However, you're using it to store the thing the user types in in response to the "Enter Bird:" prompt. Presumably, you're actually expecting them to enter a letter there?
4) You're trying to base your switch statement on 'x'. It should be x