Build a cricket game application using the C++ programming language.
There should be two teams: TeamA and TeamB
a. Each team will have 4 players.
b. The players for each team will be selected by the user from the given pool of 11
players. You can assign the names to those 11 players yourself.
c. The sequence in which the players are selected for each team will decide the
batting and bowling sequence for that team. For example, if Team A has Virat,
Rohit, Dhawan, and Rahul; Virat will be the first player to bat or ball.
2. There should be two innings.
a. Each innings will be of 6 balls.
b. In each innings, only one bowler from the bowling team will bowl all the 6
deliveries and at a time one batsman from the batting team will bat until he is
declared out.
c. The first player from the bowling team will be always selected to bowl first and
the first player from the batting team will be always selected to bat first.
d. When a batsman is OUT, the next batsman from the batting team in sequence
will start batting.
3. There should be a toss functionality.
a. The team who wins the toss will decide to either bat or bowl first.
4. In each delivery, possible runs can be scored from 0 to 6.
5. OUT criteria: If a batsman scores 0 runs he will be declared OUT and the next batsman in
sequence will start batting.
6. Match End criteria
a. If runs scored by TeamA is greater than the opponent TeamB, then TeamA will
win the game or vice-versa.
b. If runs scored by TeamA and TeamB are the same then the match will draw.
7. Improve user experience by adding functions to display the pool of all the 11 players,
display players of each team after team selection, display game scorecard after each
delivery and display the match summary when the match ends.
Answers
Answered by
5
Answer:
Explanation:// C++ implementation of the approach
#include <cmath>
#include <iostream>
using namespace std;
// Function to return the number of teams
int number_of_teams(int M)
{
// To store both roots of the equation
int N1, N2, sqr;
// sqrt(b^2 - 4ac)
sqr = sqrt(1 + (8 * M));
// First root (-b + sqrt(b^2 - 4ac)) / 2a
N1 = (1 + sqr) / 2;
// Second root (-b - sqrt(b^2 - 4ac)) / 2a
N2 = (1 - sqr) / 2;
// Return the positive root
if (N1 > 0)
return N1;
return N2;
}
// Driver code
int main()
{
int M = 45;
cout << number_of_teams(M);
return 0;
}
Similar questions
English,
4 months ago
Geography,
4 months ago
Political Science,
9 months ago
Math,
9 months ago
Math,
1 year ago