Knowee
Questions
Features
Study Tools

A cricket has the following table of batting figures for a series of test matches:Player’s name Run Innings not outRohit 8430 230 18Dhawan 4200 130 15Write a C++ program to read the figures set out in the above forms, to calculate the batting arrangesand to print out the complete table including the averages.

Question

A cricket has the following table of batting figures for a series of test matches:Player’s name Run Innings not outRohit 8430 230 18Dhawan 4200 130 15Write a C++ program to read the figures set out in the above forms, to calculate the batting arrangesand to print out the complete table including the averages.

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a simple C++ program that reads the figures, calculates the batting averages and prints out the complete table including the averages.

#include<iostream>
#include<string>

using namespace std;

class Player {
    string name;
    int run;
    int innings;
    int notOut;
    float average;

public:
    void getData() {
        cout << "Enter player's name: ";
        cin >> name;
        cout << "Enter runs: ";
        cin >> run;
        cout << "Enter innings: ";
        cin >> innings;
        cout << "Enter not out: ";
        cin >> notOut;
    }

    void calculateAverage() {
        average = (float)run / (innings - notOut);
    }

    void displayData() {
        cout << "Player's name: " << name << endl;
        cout << "Runs: " << run << endl;
        cout << "Innings: " << innings << endl;
        cout << "Not out: " << notOut << endl;
        cout << "Batting Average: " << average << endl;
    }
};

int main() {
    Player p1, p2;

    cout << "Enter data for Rohit" << endl;
    p1.getData();
    p1.calculateAverage();

    cout << "Enter data for Dhawan" << endl;
    p2.getData();
    p2.calculateAverage();

    cout << "Displaying data for Rohit" << endl;
    p1.displayData();

    cout << "Displaying data for Dhawan" << endl;
    p2.displayData();

    return 0;
}

This program creates a class Player with the necessary data members and member functions. The getData() function is used to read the data, calculateAverage() is used to calculate the batting average and displayData() is used to print the data. In the main() function, two objects of the class Player are created for Rohit and Dhawan, and their data is read, average is calculated and data is printed.

This problem has been solved

Similar Questions

The following pie-charts show the run scored by a batsman against different countries in one-day internationals (ODI) and Twenty (T20) world cup matches. Runs scored by the batsman in ODI and T20 are 5600 and 3000 respectively.If the batsman played 14 innings against England in ODI and remained not out in 5 innings. Find his average runs scored against England

The runs scored in a cricket match by 11 players is as follows:7, 16, 121, 51, 101, 81, 1, 16, 9, 11, 16Find the median of this data.a. 16.5b. 16c. 39.1d. 39

Select the correct answerThe batting average of a cricket player for 64 innings is 62 runs. His highest score exceeds his lowest score by 180 runs. Excluding these two innings, the average of remaining innings becomes 60 runs. His highest score was?Options209180212214

The runs scored in a cricket match by 11 players is as follows: 7, 16, 121, 51, 101, 81, 1, 16, 9, 11, 16 Find the mean of this data.

The runs scored by a cricketer in ten matches are as follows: 47, 58, 96, 1, 6, 52, 6, 78, 102, and 1. The median is:a.47b.47.5c.49d.49.5

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.