must be done in 2013 microsoft visual studio c++ Rock Throw Write a program that
ID: 3719240 • Letter: M
Question
must be done in 2013 microsoft visual studio c++
Rock Throw
Write a program that uses methods and simulates throwing a rock in a basket in a straight line. Each time the program is run, the program should randomly calculate and tell the user the distance to the basket between 20 and 100 feet. Each time the program is run, the program should randomly calculate the wind speed between 0 and 50 mph. Each time the program is run, the program should randomly say if the wind is blowing towards the basket or away from the basket. Allow for the gravitational pull of the Earth. The user should be able to adjust the strength of the throw as well as the angle of the throw. The program should tell the user the distance of the throw. The program should give the user multiple attempts at the throw without changing the distance or wind speed to the basket. The program should count how many attempts it takes the user to put the rock in the basket. Assume that the user always throws the rock in a perfect straight line. Assume that the basket is a three foot circle.
Explanation / Answer
Solution:
#include <string>
#include <iostream>
using namespace std;
class MyException{};
class Dummy
{
public:
Dummy(string s) : MyName(s) { PrintMsg("Created Dummy:"); }
Dummy(const Dummy& other) : MyName(other.MyName){ PrintMsg("Copy created Dummy:"); }
~Dummy(){ PrintMsg("Destroyed Dummy:"); }
void PrintMsg(string s) { cout << s << MyName << endl; }
string MyName;
int level;
};
void B(Dummy d, int i)
{
cout << "Entering FunctionB" << endl;
d.MyName = "B";
A(d, i + 1);
cout << "Exiting FunctionB" << endl;
}
void A(Dummy d, int i)
{
cout << "Entering FunctionA" << endl;
d.MyName = " A" ;
B(d, i + 1);
delete pd;
cout << "Exiting FunctionA" << endl;
}
int main()
{
cout << "Entering main" << endl;
try
{
Dummy d(" M");
A(d,1);
}
catch (MyException& e)
{
cout << "Caught an exception of type: " << typeid(e).name() << endl;
}
cout << "Exiting main." << endl;
char c;
cin >> c;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.