Advertisement
skb50bd

Cricketer

May 20th, 2015
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.90 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. #include <iomanip>
  5. using namespace std;
  6.  
  7. struct Cric
  8. {
  9.     string name, country;
  10.     double inn, noinn, runs, ballf, batav, strr;
  11. };
  12.  
  13.  
  14. double calcav (struct Cric X);
  15. double calcstrr (struct Cric X);
  16. void printinfo (struct Cric X);
  17. struct Cric getcric();
  18.  
  19.  
  20. int main ()
  21. {
  22.     int n, i;
  23.     string line;
  24.  
  25.     cout << "How many cricketers? ";
  26.     getline (cin, line);
  27.     stringstream (line) >> n;
  28.  
  29.     struct Cric X[n];
  30.  
  31.     for (i = 0; i < n; i++)
  32.     {
  33.         cout << "Enter information for Entry " << i+1 << endl;
  34.         X[i] = getcric();
  35.     }
  36.  
  37.     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;
  38.     for (i = 0; i < n; i++)
  39.         printinfo (X[i]);
  40.  
  41.     return 0;
  42. }
  43.  
  44.  
  45.  
  46.  
  47.  
  48. double calcav (struct Cric X)
  49. {
  50.     return (X.runs / (X.inn - X.noinn));
  51. }
  52.  
  53. double calcstrr (struct Cric X)
  54. {
  55.     return ((X.runs * 100) / X.ballf);
  56. }
  57.  
  58. struct Cric getcric()
  59. {
  60.  
  61.     struct Cric X;
  62.     string line;
  63.  
  64.     getline (cin, X.name);
  65.  
  66.     getline (cin, X.country);
  67.  
  68.     getline (cin, line);
  69.     stringstream (line) >> X.inn;
  70.  
  71.     getline (cin, line);
  72.     stringstream (line) >> X.noinn;
  73.  
  74.     getline (cin, line);
  75.     stringstream (line) >> X.runs;
  76.  
  77.     getline (cin, line);
  78.     stringstream (line) >> X.ballf;
  79.  
  80.     X.batav = calcav (X);
  81.  
  82.     X.strr = calcstrr (X);
  83.  
  84.     return X;
  85. }
  86.  
  87. void printinfo (struct Cric X)
  88. {
  89.     cout.setf (ios :: fixed);
  90.     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;
  91.     return;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement