Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <sstream>
- #include <iomanip>
- using namespace std;
- struct Cric
- {
- string name, country;
- double inn, noinn, runs, ballf, batav, strr;
- };
- double calcav (struct Cric X);
- double calcstrr (struct Cric X);
- void printinfo (struct Cric X);
- struct Cric getcric();
- int main ()
- {
- int n, i;
- string line;
- cout << "How many cricketers? ";
- getline (cin, line);
- stringstream (line) >> n;
- struct Cric X[n];
- for (i = 0; i < n; i++)
- {
- cout << "Enter information for Entry " << i+1 << endl;
- X[i] = getcric();
- }
- cout << left << setw(30) << "Player Name" << left << setw(15) << "Country" << right << setw(10) << "Innings" << right << setw(7) << "Runs" << right << setw(10) << "Average" << right << setw(13) << "Strike Rate" << endl;
- for (i = 0; i < n; i++)
- printinfo (X[i]);
- return 0;
- }
- double calcav (struct Cric X)
- {
- return (X.runs / (X.inn - X.noinn));
- }
- double calcstrr (struct Cric X)
- {
- return ((X.runs * 100) / X.ballf);
- }
- struct Cric getcric()
- {
- struct Cric X;
- string line;
- getline (cin, X.name);
- getline (cin, X.country);
- getline (cin, line);
- stringstream (line) >> X.inn;
- getline (cin, line);
- stringstream (line) >> X.noinn;
- getline (cin, line);
- stringstream (line) >> X.runs;
- getline (cin, line);
- stringstream (line) >> X.ballf;
- X.batav = calcav (X);
- X.strr = calcstrr (X);
- return X;
- }
- void printinfo (struct Cric X)
- {
- cout.setf (ios :: fixed);
- cout << left << setw(30) << X.name << left << setw(15) << X.country << right << setw(10) << setprecision(0) << X.inn << right << setw(7) << setprecision(0) << X.runs << right << setw(10) << setprecision(2) << X.batav << right << setw(13) << setprecision(2) << X.strr << endl;
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement