Question

C++ Create a .h file, .cpp file, and main file and zip them together, try not to use structs.Create a simulation of a game call target darts. The target has a center at 0,0 and there are concentric circles around tha

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the C++ code for each file:

TargetDarts.h:

#ifndef REPLACE_TARGETDARTS_H #define REPLACE_TARGETDARTS_H class TargetDarts { private: double d1,d2,d3,d4; int s1,s2,s3,s4; public: void simulate(); void print(); }; #endif 

Screenshot:

#ifndef REPLACE_TARGETDARTS_H #define REPLACE_TARGETDARTS_H class TargetDarts { pvate: double d1, d2, d3, d4; int 51, 52, 53,

TargetDarts.cpp:

#include <random> #include <iomanip> #include "TargetDarts.h" using namespace std; void TargetDarts::simulate() { normal_distribution<double> dis(0.0,3.0); default_random_engine gen; d1 = abs(dis(gen)); d2 = abs(dis(gen)); d3 = abs(dis(gen)); d4 = abs(dis(gen)); s1 = floor(d1); s2 = floor(d2); s3 = floor(d3); s4 = floor(d4); if(s1%2 == 1) s1-=1; if(s2%2 == 1) s2-=1; if(s3%2 == 1) s3-=1; if(s4%2 == 1) s4-=1; } void TargetDarts::print() { cout<<setprecision(2); int totalScore = 40 - (s1+s2+s3+s4); cout<<"Dart#\tDistance\tNext Circle\tScore"<<endl; cout<<"1 "<<d1<<"\t\t"<<s1<<"\t\t"<<10-s1<<endl; cout<<"2 "<<d2<<"\t\t"<<s2<<"\t\t"<<10-s2<<endl; cout<<"3 "<<d3<<"\t\t"<<s3<<"\t\t"<<10-s3<<endl; cout<<"4 "<<d4<<"\t\t"<<s4<<"\t\t"<<10-s4<<endl; cout<<"_________________________________________________________________________________"<<endl; cout<<"Total Score "<<totalScore<<endl; } 

4 5 # #include <random> #include <iomanip> #include TargetDarts.h using namespace std; void TargetDarts :: simulate() { nor

main.cpp:

#include <iostream> using namespace std; #include "TargetDarts.cpp" int main(){ TargetDarts targ; targ.simulate(); targ.print(); }

3 #include <iostream> using namespace std; #include TargetDarts.cpp int main() { TargetDarts targ; targ. simulate(); targ.p

Here is the OUTPUT for the same:
Dart# Next Circle Score 0 - 2 3 4 Distance 0.37 3.3 2.1 3.2 3 2 0 | Total Score

P.S. You can comment below the answer, for any doubts, and I will be happy to help!

Please give a thumbs up if my answer could be of help!

All the best!

Add a comment
Know the answer?
Add Answer to:
C++ Create a .h file, .cpp file, and main file and zip them together, try not...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. A train at a constant 62.0 km/h moves east for 32.0 min, then in a...

    1. A train at a constant 62.0 km/h moves east for 32.0 min, then in a direction 46.0° east of due north for 29.0 min, and then west for 42.0 min. What are the (a) magnitude and (b) angle (relative to east) of its average velocity during this trip? 2. A cart is propelled over an XX plane with acceleration components ax 5.5 m/s2 and ay = -2.3 m/s. Its initial velocity has components vox = 9.3 m/s and voy...

  • Java BlackJack Game: Help with 1-4 using the provided code below Source code for Project3.java: import...

    Java BlackJack Game: Help with 1-4 using the provided code below Source code for Project3.java: import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.io.*; public class Project3 extends JFrame implements ActionListener { private static int winxpos = 0, winypos = 0; // place window here private JButton exitButton, hitButton, stayButton, dealButton, newGameButton; private CardList theDeck = null; private JPanel northPanel; private MyPanel centerPanel; private static JFrame myFrame = null; private CardList playerHand = new CardList(0); private CardList dealerHand = new CardList(0);...

  • Game Description: Most of you have played a very interesting game “Snake” on your old Nokia...

    Game Description: Most of you have played a very interesting game “Snake” on your old Nokia phones (Black & White). Now it is your time to create it with more interesting colors and features. When the game is started a snake is controlled by up, down, left and right keys to eat food which appears on random locations. By eating food snake’s length increases one unit and player’s score increases by 5 points. Food disappears after 15 seconds and appears...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT