Assigement No 1 .CPP
Assigement No 1 .CPP
Aleesha Kanwal
ID:BC230419288
Question:1
Q:1 You are required to write a C++ program to find the
performance of cricket players after a match. The detailed
requirements of assignment task are given below.
Solution:
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
class Player {
private:
string playerName;
int totalScore;
int ballsPlayed;
public:
Player() {
totalScore = 0;
ballsPlayed = 0;
}
int getScore() {
return totalScore;
}
int getBalls() {
return ballsPlayed;
}
while (true) {
int score = -1; // Initialize score to -1 (indicating OUT)
if (score == -1) {
cout << "OUT! " << playerName << " is out." << endl;
break;
} else {
totalScore += score;
cout << "Scored " << score << " runs." << endl;
}
}
}
};
int main() {
// Array of player names
string playerNames[11] = {"babar azam", "naseem shah",
"agha salman", "muhammad amir",
"shaheen afridi", "ahadab khan", "imad
wasim", "fakhar zaman",
"haris rauf", "muhammad rizwan", "iftikhar
ahmed"};
cout << endl << "Man of the Match: " << manOfTheMatch <<
endl;
return 0;
}