Question
C++ programming assignment help Page of 9 ZOOM EECE1080C/CS1021CLab -LoopsLab Due Date -Feb17, 2021(Wed) at 11:59PM1ObjectiveThe objective of this assignment is to practice using loops.
C++ programming assignment help
Page
of 9
ZOOM
EECE1080C/CS1021CLab -LoopsLab Due Date -Feb17, 2021(Wed) at 11:59PM1ObjectiveThe objective of this assignment is to practice using loops. You will create several short programming assignments to get more familiar with C++ looping concepts.Please read the full document carefully before starting.Requirements and DeliverablesThis lab has three elements (A C). Required actions include:Develop, build and execute the code for each elementUpload your final source code for each lab element to the appropriate CANVAS upload site. Use the following names for your source files:Lab ElementSource filenameAlogtable.cppBrolldice.cppClookoutbelow.cppLab Element A ---Calculate and Display a Logarithm TableWrite a program that uses a loop to produce the following logarithm table on screen. Note that the value xstarts at 1, and the step (the difference of x between two rows) is determined by the value of x; that is the step size, s = f(x). For example,when19,()=1when 1099,()=10when100999,()=100and so forthSee table below for further illustration.When the program starts, it should promptthe user how many rows it will calculate. Once the user enters thisinformation, the table will be calculated and displayed on screen. NOTES:You donothave to use subscript fonts for the table header. For example, log10(x) can be displayed as log10(x)To calculate the step size, s(x), it is recommended that you utilize the properties of logarithms. For example, for the base 10 logarithm, it follows that when x = 120:10(120)=10(1.2102)=10(1.2)+10(102)=2+0.07918=2.07918
EECE1080C/CS1021CLab -LoopsLab Due Date -Feb17, 2021(Wed) at 11:59PM2For x = 120, you want s(x) = 2. Think about how you can obtain thisin your C++ code.What happens if, say, x = 12orx = 1200?You can use the following C++ functions:log(x) natural logarithmlog2(x) log base 2log10(x) log base 10NOTE you must #include header file to access these functions in your codeSample input/outputThis program calculates and displays a tableof logarithm values.As noted above, your program should prompt the user for the number of rows to compute. Something like...int nrows;// number of table rowscout << Enter the number of table rows: ;cin >> nrows; // write from input stream tonrowsYour output should look something likethe following...x log10(x) log2(x) ln(x)1 0.00000000 0.00000000 0.000000002 0.30103000 1.00000000 0.693147183 0.47712125 1.58496250 1.098612294 0.60205999 2.00000000 1.386294365 0.69897000 2.32192809 1.609437916 0.77815125 2.58496250 1.791759477 0.84509804 2.80735492 1.945910158 0.90308999 3.00000000 2.079441549 0.95424251 3.16992500 2.1972245810 1.00000000 3.32192809 2.3025850920 1.30103000 4.32192809 2.9957322730 1.47712125 4.90689060 3.4011973840 1.60205999 5.32192809 3.6888794550 1.69897000 5.64385619 3.9120230160 1.77815125 5.90689060 4.0943445670 1.84509804 6.12928302 4.2484952480 1.90308999 6.32192809 4.3820266390 1.95424251 6.49185310 4.49980967100 2.00000000 6.64385619 4.60517019200 2.30103000 7.64385619 5.29831737
EECE1080C/CS1021CLab -LoopsLab Due Date -Feb17, 2021(Wed) at 11:59PM3To control table formatting, consider using selected C++ stream manipulators. To access these, you must #include header file. You can control both the table column widths and the number of digits used for the values in the table cellsby applying the setwand setprecisionstream manipulators, respectively(for example, see: https://www.cplusplus.com/reference/iomanip/setw).Observe that in the table above all floating-point values display8 digits after the decimal point.Think about how to utilize thesemanipulatorsin your code to control table formatting and arrangement.Lab Element B ---Dice Game using SimulationThis is a two die game using random numbers for input. Generate a seed using srand( )and your computers system time. You will need to do the following in your code:o#include // include ctime header fileotime_t seed = time(0); // define & initializeseedvariableosrand(seed);// seed random no. generatorofor grins, you can see what happens if you do NOT seed the random no. generator. Comment out the line srand(seed);and run your code several times. Observe the output of the call to rand()Generate random numbers between 1 and 6 to simulate rolls of 2 dice[rand()%6 + 1;// forces random valuesbetween 1 and 6...why?]Add the sum of the 2 dice and compare the sum to the Winning, Losing, and Play Again conditions given belowDisplay appropriate text (see examples).You will need to keep rolling the dice until you either reach a winning or losing condition. Note:if you need to roll again, the variable in your code representing the sum of the two die should be reset to0Condition TableWinning Conditions: 7, 9, and 11Losing Conditions:2, 3, and 5Roll again conditions:4, 6, and 12.
EECE1080C/CS1021CLab -LoopsLab Due Date -Feb17, 2021(Wed) at 11:59PM4Sample Program OutputSample 1Sample 2Sample 3
EECE1080C/CS1021CLab -LoopsLab Due Date -Feb17, 2021(Wed) at 11:59PM5Sample 4Lab Element C ---Using a Water Balloon to Strike Your FriendThere is one day after you finish the C++ labthatyou go to the top of Old Chemistry. You hold a water balloon and be ready to strike your friend who will pass by. You cannot wait.BackgroundThis lab element introduces you to a fundamental computational solution approachcalled explicittime-steppingwhich isused for numerically solvingscientific and engineering problems. You have learned or will shortly learn about a specific type of analysis referred to as particle kinematics. In summary, this basically states fundamental, calculus-based relationships for particle motion:()particle displacement at time, t(ft or m)()=particle velocity at time, t(ft/sec or m/sec)()==()=22particle acceleration at time, t(ft/sec2or m/sec2)In calculus, you learn that the derivativeisdefined as: ()==lim0.However, if you use a sufficiently small timestepvalue(), you can accurately approximate, ()=or,(+)(). Note, the units of the numerator are ftand the units of the denominator are sec. The resultant units are ft/secwhich is correct for velocity. The net result is that in your C++ code you will implement calculus relationshipsas algebraic relationships. Of course, to represent real world motionsyou need more than kinematics;you also need to include accelerations due to forces(Newtons 2ndLaw). This part is known as particle kineticsordynamics.
EECE1080C/CS1021CLab -LoopsLab Due Date -Feb17, 2021(Wed) at 11:59PM6SpecificationTo compute the position of your water balloon you need to account forboth balloonkinematics and kineticsin your code. The forces that you need to account forare: gravitational force and aerodynamic drag. In your code, you need to include the accelerations associated with these forces. The acceleration due to gravity is easy. It is a constant, =32/2. The effect of aerodynamic dragonballoon accelerationis a little trickier. It willbe implemented using asimplified model, =(/2), where,=0.00121constantdrag coefficient.With these implementations, themodel forballoon motionis given by,==22=()+,2It is applied subject to the following definitions and constraints:In this expression, balloon displacement, ()and velocity, ()are taken as positive downwards andnegative upwards.Since you are dropping the balloon from the top of Old Chem(=0), your calculations for balloon displacement and velocity should be >0for >0Acceleration due to gravity is always downward; aerodynamic drag acts opposite to ()It is assumed that you simply let go of the balloon from the top of Old Chem. As a result, the initial balloon velocityis(=0)=0The solution process uses a multistage, time-stepping algorithm. You will solve the balloon equation at discrete time intervals, 1,2,3,...,,...,, where =,in multiple stepsstarting at =0(=0):Step 1Solve for +1=(), for =0,1,2,...(0)=0,(0)=0Step 2Solve for +1=++1, for =0,1,2,...+1Repeat Step 1Set the time step interval to, =0.001constantAssume that you know how highyou are above the top of your friends head, and you know the walking speedand the walking distanceof your friend.Based on the walking distance and walking speed of your friend, you can predict how many seconds (or minutes) your friendwilltake toreach the strikepoint. This time interval is referred to astime1. Next, the most important thingis to predict how longit will take for the balloon to fall onthe head of your friend. Refer to this time interval as time2. For this simulation neglect your friendsphysical height.
EECE1080C/CS1021CLab -LoopsLab Due Date -Feb17, 2021(Wed) at 11:59PM7Your program will prompt the user for the following information:The height verDist(in feet) you are above the top of your friends headThe walking speed in (ft/sec) of your friendThe walking distance (in feet) you see your friend (from the initial location to the strike point)Define the value of drag coefficient,in the global namespace as:double cD =0.0012; // units are sec^-1You now have everything you need to iterate through steps 1 and 2 above. The first two iterations should look like the following.Initial and other values:v(0) = x(0) = 0,cD= 0.0012 sec-1, g = 32ft/sec2, tk= ktsecIterationv value [vk=v(tk)], ft/secx value [xk=x(tk)], ftk=01=0(0.0012032)0.001=0.0321=0+0.0320.001=0.000032k=12=0.032(0.00120.03232)0.001=0.06399996162=0.000032+0.06399996160.001=0.0000959999616Continue iteratinguntil you compute ()verDistto find how long (i.e., time2) it takes the water balloon to fall. You can easily calculate how long (i.e., time1) it takes for your friend to reach the strikepoint. In your code, you should define the variables,time1and time2in the global namespace as:double time1, time2;Also,define a tolerance value (,)in the global namespace as:const double epsilon = 0.01; // toleranceA successful strike is assumed to occur when, |12|
EECE1080C/CS1021CLab -LoopsLab Due Date -Feb17, 2021(Wed) at 11:59PM8Program InputThe height verDist(in feet) you are above the top of your friends head;The walking speed in (feet/second) of your friend;The walking distance (in feet) you see your friend (from the initial location to the strikepoint);Example Program OutputHow far away is your friend(feet)? 200How fast are they walking(feet/sec)? 3How high are you before dropping your balloon(feet)? 100It will take 66.66 seconds for them to reach the balloon pointIt will take 2.50seconds for your balloon to travel to the groundIf you wait 64.16seconds, you will hit them-----------------------------------------------------------------------How far away is your friend(feet)? 10How fast are they walking(feet/sec)? 3How high are you before dropping your balloon(feet)? 200It will take 3.33seconds for them to reach the balloon pointIt will take 3.53seconds for your balloon to travel to the groundIt is too late to drop your balloon----------------------------------------------------------------------How far away is your friend(feet)? 10.6How fast are they walking(feet/sec)? 3How high are you before dropping your balloon(feet)? 200It will take 3.53seconds for them to reach the balloon pointIt will take 3.53seconds for your balloon to travel to the groundBingo, you hit your friend successfullyIMPORTANTIt is REQUIREDthat you output exactly two digitsfollowing the decimal point for the values of the time1and time2variables (see values highlighted in REDintheExample Program Output section above).You can accomplish this by adaptingthe followingexcerptin the development ofyour lab code#include // std::cout, std::fixed#include // std::setprecisionusing namespace std;double x = 1.235678901;. . .. . .cout << x= << setprecision(2)<< fixed << x;// prints x = 1.24On the CANVAS site for this lab, a demo C++ program is posted (FIXED3.cpp)which you should download, compile and run to further familiarize yourself with the manipulators setprecisionand fixed.
EECE1080C/CS1021CLab -LoopsLab Due Date -Feb17, 2021(Wed) at 11:59PM9Lab Grading Metrics and RubricLab Element A25%Lab Element B25%Lab Element C40%Code Style, Commentingand Formatting10%
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started