-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathProblem 05.cpp
More file actions
97 lines (79 loc) · 1.84 KB
/
Problem 05.cpp
File metadata and controls
97 lines (79 loc) · 1.84 KB
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
97
#include<iostream>
using namespace std;
class Player
{
string name;
int runs;
public:
void setName(string a) {name = a;}
string getName() {return name;}
void addRuns(int a) {runs += a;}
int getRuns() {return runs;}
Player() : runs(0) {}
};
class Team
{
string highestScorer;
string teamName;
public:
Player a[11];
void setTeamName(string a) {teamName = a;}
string getTeamName() {return teamName;}
int getHighestScore()
{
int highestScore = 0;
for (int i=0; i<11; i++)
{
if (a[i].getRuns() > highestScore)
{
highestScore = a[i].getRuns();
highestScorer = a[i].getName();
}
}
return highestScore;
}
string getHighestScorer() {return highestScorer;}
int getTotal()
{
int totalRuns = 0;
for (int i=0; i<11; i++) totalRuns += a[i].getRuns();
return totalRuns;
}
Team() : highestScorer(""), teamName("") {}
};
class Match
{
string winner;
public:
Team b[2];
string getManOfMatch()
{
if (b[0].getHighestScore() > b[1].getHighestScore()) return b[0].getHighestScorer();
else return b[1].getHighestScorer();
}
string getWinner()
{
if (b[0].getTotal() > b[1].getTotal()) winner = b[0].getTeamName();
else winner = b[1].getTeamName();
return winner;
}
};
int main()
{
Match m1;
for (int i=0; i<11; i++)
{
m1.b[0].a[i].addRuns(1);
}
m1.b[0].a[0].addRuns(1);
for (int i=0; i<11; i++)
{
m1.b[1].a[i].addRuns(2);
}
m1.b[1].a[0].addRuns(2);
m1.b[0].a[0].setName("A");
m1.b[1].a[0].setName("B");
m1.b[1].setTeamName("Team B");
cout<<m1.getWinner()<<endl;
cout<<m1.getManOfMatch();
}