In: Computer Science
Write up to 10 lines to explain the logic used behind this code pls!!!!!
*****************************************/
#include <iostream>
#include <string>
#include <iomanip>
#include<activaut.h>
#include<activdbg.h>
using namespace std;
int main()
{
int MatchesPlayed[6], MatchesWon[6], MatchesLost[6], MatchesDraw[6], MatchesPoints[6], TotalPoints[6];
MatchesWon[0] = 3; MatchesLost[0] = 0; MatchesDraw[0] = 1; //India
MatchesWon[1] = 2; MatchesLost[1] = 0; MatchesDraw[1] = 1; //NZ
MatchesWon[2] = 0; MatchesLost[2] = 3; MatchesDraw[2] = 0; //Australia
MatchesWon[3] = 1; MatchesLost[3] = 2; MatchesDraw[3] = 1; //West Indies
MatchesWon[4] = 1; MatchesLost[4] = 0; MatchesDraw[4] = 1; //SA
MatchesWon[5] = 1; MatchesLost[5] = 3; MatchesDraw[5] = 0; //England
int TotalPlayed = 0, TotalWon = 0, TotalLost = 0, TotalDraw = 0, TP = 0;
for (int i = 0; i < 6; i++)
{
MatchesPlayed[i] = MatchesWon[i] + MatchesLost[i] + MatchesDraw[i]; //MATCHES FOR EACH TEAM
TotalPoints[i] = 2 * MatchesWon[i] - 1 * MatchesLost[i] + 1 * MatchesDraw[i]; //POINTS FOR TEAMS
TotalPlayed = TotalPlayed + MatchesPlayed[i];
TotalWon = TotalWon + MatchesWon[i];
TotalLost = TotalLost + MatchesLost[i];
TotalDraw = TotalDraw + MatchesDraw[i];
TP = TP + TotalPoints[i];
}
cout << " 2019 Cricket WorldCup \n ";
cout << "Countries Matches_Played Matches_Won Matches_Lost Draw/Rain Total_Points\n";
cout << "--------- -------------- ----------- ------------ --------- ------------\n";
cout << "INDIA " << MatchesPlayed[0] << " " << MatchesWon[0] << " " << MatchesLost[0] << " " << MatchesDraw[0] << " " << TotalPoints[0] << "\n";
cout << "NZ " << MatchesPlayed[1] << " " << MatchesWon[1] << " " << MatchesLost[1] << " " << MatchesDraw[1] << " " << TotalPoints[1] << "\n";
cout << "AUSTRALIA " << MatchesPlayed[2] << " " << MatchesWon[2] << " " << MatchesLost[2] << " " << MatchesDraw[2] << " " << TotalPoints[2] << "\n";
cout << "WEST INDIES " << MatchesPlayed[3] << " " << MatchesWon[3] << " " << MatchesLost[3] << " " << MatchesDraw[3] << " " << TotalPoints[3] << "\n";
cout << "SA " << MatchesPlayed[4] << " " << MatchesWon[4] << " " << MatchesLost[4] << " " << MatchesDraw[4] << " " << TotalPoints[4] << "\n";
cout << "ENGLAND " << MatchesPlayed[5] << " " << MatchesWon[5] << " " << MatchesLost[5] << " " << MatchesDraw[5] << " " << TotalPoints[5] << "\n";
cout << "TOTAl " << TotalPlayed << " " << TotalWon << " " << TotalLost << " " << TotalDraw << " " << TP << "\n";
return 0;
}
HERE IS THE EXPLANATION FOR EACH LINE OF CODE
#include <iostream>
#include <string>
#include <iomanip>
#include<activaut.h>
#include<activdbg.h>
using namespace std;
int main()
{
// Declaration of arrays with array_size of 6(Number of
teams).
int MatchesPlayed[6], MatchesWon[6], MatchesLost[6],
MatchesDraw[6], MatchesPoints[6], TotalPoints[6];
// Initialization(assigning) of values for each
team.
MatchesWon[0] = 3; MatchesLost[0] = 0; MatchesDraw[0] = 1; //India
MatchesWon[1] = 2; MatchesLost[1] = 0; MatchesDraw[1] = 1; //NZ
MatchesWon[2] = 0; MatchesLost[2] = 3; MatchesDraw[2] = 0; //Australia
MatchesWon[3] = 1; MatchesLost[3] = 2; MatchesDraw[3] = 1; //West Indies
MatchesWon[4] = 1; MatchesLost[4] = 0; MatchesDraw[4] = 1; //SA
MatchesWon[5] = 1; MatchesLost[5] = 3; MatchesDraw[5] = 0;
//England
// Declaration and Initialization of totals.
int TotalPlayed = 0, TotalWon = 0, TotalLost = 0, TotalDraw = 0,
TP = 0;
// for-loop to calculate the total matches played by each
team and total points for each team.
for (int i = 0; i < 6; i++)
{
MatchesPlayed[i] = MatchesWon[i] + MatchesLost[i] + MatchesDraw[i]; //MATCHES FOR EACH TEAM
TotalPoints[i] = 2 * MatchesWon[i] - 1 * MatchesLost[i] + 1 *
MatchesDraw[i]; //POINTS FOR TEAMS
// updating the totals for each match
TotalPlayed = TotalPlayed + MatchesPlayed[i];
TotalWon = TotalWon + MatchesWon[i];
TotalLost = TotalLost + MatchesLost[i];
TotalDraw = TotalDraw + MatchesDraw[i];
TP = TP + TotalPoints[i];
}
// format to print results as a table
cout << " 2019 Cricket WorldCup \n ";
cout << "Countries Matches_Played Matches_Won Matches_Lost Draw/Rain Total_Points\n";
cout << "--------- -------------- ----------- ------------ --------- ------------\n";
cout << "INDIA " << MatchesPlayed[0] << " " << MatchesWon[0] << " " << MatchesLost[0] << " " << MatchesDraw[0] << " " << TotalPoints[0] << "\n";
cout << "NZ " << MatchesPlayed[1] << " " << MatchesWon[1] << " " << MatchesLost[1] << " " << MatchesDraw[1] << " " << TotalPoints[1] << "\n";
cout << "AUSTRALIA " << MatchesPlayed[2] << " " << MatchesWon[2] << " " << MatchesLost[2] << " " << MatchesDraw[2] << " " << TotalPoints[2] << "\n";
cout << "WEST INDIES " << MatchesPlayed[3] << " " << MatchesWon[3] << " " << MatchesLost[3] << " " << MatchesDraw[3] << " " << TotalPoints[3] << "\n";
cout << "SA " << MatchesPlayed[4] << " " << MatchesWon[4] << " " << MatchesLost[4] << " " << MatchesDraw[4] << " " << TotalPoints[4] << "\n";
cout << "ENGLAND " << MatchesPlayed[5] << " " << MatchesWon[5] << " " << MatchesLost[5] << " " << MatchesDraw[5] << " " << TotalPoints[5] << "\n";
cout << "TOTAl " << TotalPlayed << " " << TotalWon << " " << TotalLost << " " << TotalDraw << " " << TP << "\n";
return 0;
}
SCREEN SHOTS OF CODE IN EDITER:
OUTPUT:
IF YOU HAVE ANY QUERIES FEEL FREE TO ASK AT COMMENTS
PLEASE DO LIKE :)