C++ Create a .h file, .cpp file, and main file and zip them together, try not to use structs.
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:
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; }
main.cpp:
#include <iostream> using namespace std; #include "TargetDarts.cpp" int main(){ TargetDarts targ; targ.simulate(); targ.print(); }
Here is the OUTPUT for the same:
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!
C++ Create a .h file, .cpp file, and main file and zip them together, try not...
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 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 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...