Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Programming Exercise 2 Mighty Casey plays centerfield for the Toledo Mudhens

ID: 3598515 • Letter: C

Question

C++ Programming

Exercise 2 Mighty Casey plays centerfield for the Toledo Mudhens and has the following lifetime hitting percentages Out Walk Single Double Triple Home Run 5% 35% 16% 20% 15% 9% The above is called a probability distribution. A probability distribution is used in predicting the likelihood of an event occurring. See the following explanation of probability distributions using the example of flipping a coin at: http://stattrek. com/Lesson2 ProbabilityDistribution.aspx. Notice the distribution adds up to 100% Write a program to simulate a large number of times at bat (1000 or more) for Mighty Casey counting the number of outs, walks, singles, etc. to predict Mighty Casey's batting average for next season and slugging percentage. This means you have to generate a random number (hint: between 1 and 100) and based upon the value (i.e. probability) will determine if Mighty Casey gets a hit or an out. If it is a hit, then your program needs to determine what type of hit was based upon the probabilities given in the table above Use the formulas below to calculate the batting average and slugging percentage of Mighty Casey batting average number of hits / (number of times at bat-number of walks) slugging percentage = (number of singles + number of doubles * 2 + number of triples * 3 + number of homeruns * 4) /(number of times at bat - number of walks) Copy and paste your program into your word document. Capture the output window and paste it below your program.

Explanation / Answer

package com.one;
class DList<T> {
private DNode<T> header, trailer;
private int size;
public DList() {
size = 0;
header = new DNode<T>(null, null, null);
trailer = new DNode<T>(null, header, null);
header.setNext(trailer);
}
public int size() {
return size;
}
public boolean isEmpty() {
return size == 0;
}
// give clients access to nodes, but not to the header or trailer
public DNode<T> getFirst() throws Exception {
if (isEmpty())
throw new Exception("Empty");
return header.getNext();
}
public DNode<T> getLast() throws Exception {
if (isEmpty())
throw new Exception("Empty");
return trailer.getPrev();
}
public DNode<T> getNext(DNode<T> v) throws Exception {
DNode<T> ans = v.getNext();
if (ans == null || ans == trailer)
throw new Exception("No such node");
return ans;
}
public DNode<T> getPrev(DNode<T> v) throws Exception {
DNode<T> ans = v.getPrev();
if (ans == null || ans == header)
throw new Exception("No such node");
return ans;
}
// methods to change the list
public void addBefore(T d, DNode<T> v) {
DNode<T> u = v.getPrev();
DNode<T> x = new DNode<T>(d, u, v);
u.setNext(x);
v.setPrev(x);
size++;
}
public void addAfter(T d, DNode<T> v) {
DNode<T> w = v.getNext();
DNode<T> x = new DNode<T>(d, v, w);
v.setNext(x);
w.setPrev(x);
size++;
}
public void addFirst(T d) {
addAfter(d, header);
}
public void addLast(T d) {
addBefore(d, trailer);
}
public T remove(DNode<T> v) throws Exception {
if (v == header || v == trailer)
throw new Exception("Sentinel");
DNode<T> u = v.getPrev();
DNode<T> w = v.getNext();
w.setPrev(u);
u.setNext(w);
size--;
return v.getData();
}
// LinkedList testing methods:
public String toString() {
String ans = "";
DNode<T> n = header;
ans += "(H)<-->";
do {
n = n.getNext();
if (n == trailer)
ans += "(T)";
else
ans += (n.getData() + "<-->");
} while (n != trailer);
return ans;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote