-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path11_Cricket.cpp
executable file
·96 lines (82 loc) · 1.37 KB
/
11_Cricket.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <iostream>
using namespace std;
class Player{
char name[20];
static int num;
int runs, matches, out;
float batting_avg;
bool e;
public:
Player(){
num = 0;
runs = 0;
matches = 0;
e = 0;
batting_avg = 0;
}
void add();
void display();
void avg();
bool exist();
static int status();
};
int Player::num;
int main(){
int c, i;
Player list[20];
do{
i = 0;
cout<<"\n1. Add\n2. View\n0. Exit\n:";
cin>>c;
switch(c){
case 1:
if(Player::status() == 20){
cout<<"List Full\n";
}else{
while((i < 20) & list[i].exist()) i++;
list[i].add();
}
break;
case 2:
if(Player::status() == 0){
cout<<"List Empty\n";
}else{
while(i < 20){
if(list[i].exist())
list[i].display();
i++;
}
}
break;
case 0:break;
default :cout<<"Invalid option\n";
}
}while(c != 0);
return 0;
}
void Player::add(){
cout<<"Name : ";
cin>>name;
cout<<"Runs : ";
cin>>runs;
cout<<"Matches : ";
cin>>matches;
cout<<"Number of out : ";
cin>>out;
batting_avg = (float)runs/out;
num++;
e = 1;
}
void Player::display(){
cout<<"Name : "<<name<<"\n";
cout<<"Runs : "<<runs<<"\n";
cout<<"Matches : "<<matches<<"\n";
cout<<"Number of out : "<<out<<"\n";
cout<<"Batting Averege : "<<batting_avg<<"\n";
}
bool Player::exist(){
return e;
}
int Player::status(){
return num;
}