Question

In: Computer Science

Write up to 10 lines to explain the logic used behind this code pls!!!!! *****************************************/ #include...

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;

}

Solutions

Expert Solution

HERE IS THE EXPLANATION FOR EACH LINE OF CODE

  • Arrays played crucial role in this code. Array is a data structure which stores fixed-size sequential collection of data.
  • To declare an array, we need specify the "type" of array and number of elements storing.
  • We can initialize array elements either one by one (as in this code) or as whole in '{}' seperated by commas.
  • Data inside array is accessed by index number which starts at 0 upto array size - 1.
  • After arrays, a for loop is used to iterate among the elements of array.
  • In for loop, updation of MatchesPlayed and TotalPoints are done through each iteration.
  • Also, calculation of Total played, won, loss, draw and points are done inside the for loop only.
  • Finally, printed the all values of arrays in a specific format to print as a table. Spaces are used to line up every value under each header.
  • See the pictures of editor and output, the way table was printed only with the spaces in output.

#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 :)


Related Solutions

Write up to 10 lines to explain the logic used behind this code pls!!!!! #include <iostream>...
Write up to 10 lines to explain the logic used behind this code pls!!!!! #include <iostream> #include <iomanip> #include<cmath> #include<AclUI.h> using namespace std; int main() {     int array[][2] = { {29,60} , {33,80} , {45,90} , {57,52} , {12,44} , {21,78} , {32,64} , {17,59} }; //given values     int Totalstudents = 0,TotalPass = 0, Average = 0;     for (int i = 0; i < 8; i++)      //students enrooled     {          Totalstudents += array[i][0];     }    ...
Write up to 10 lines to each code explain the logic used behind these code pls!!!!!...
Write up to 10 lines to each code explain the logic used behind these code pls!!!!! (10 lines for each please) 1. #include<iostream> using namespace std; int main() {        int id, reverse[20], count = 0, min = 0, max = 0;        cout << "\nStudent ID Number is \n";        cin >> id;        while (id != 0)        {              reverse[count] = id % 10;              if (count == 0)              {                     min = reverse[count];                     max...
Write up to 4 or 5 lines to explain the logic used behind those codes. Separately...
Write up to 4 or 5 lines to explain the logic used behind those codes. Separately for each please 1) #include <iostream> #include <string> #include <fstream> #include <vector> #include <sstream> using namespace std; int main() {         ifstream infile("worldpop.txt");         vector<pair<string, int>> population_directory;         string line;         while(getline(infile, line)){                 if(line.size()>0){                         stringstream ss(line);                         string country;                         int population;                         ss>>country;                         ss>>population;                         population_directory.push_back(make_pair(country, population));                 }         }         cout<<"Task 1"<<endl;         cout<<"Names of countries with population>=1000,000,000"<<endl;...
List and explain the logic behind the “four functions of money.” Then, consider the following: In...
List and explain the logic behind the “four functions of money.” Then, consider the following: In many prisons, cigarettes are used as money. Do cigarettes in prison have the ability to satisfy these four functions? Explain.
write a java program. 10-20 lines of code You are a landscaper, one of your first...
write a java program. 10-20 lines of code You are a landscaper, one of your first tasks is to determine the cost of landscaping a yard. You charge a flat fee of $40 to landscape a yard, and an extra $10 a bag for raking leaves. Not all yards you work on have leaves that need to be raked. Houses without any leaves will be discounted $5. Using your program, use the JOption Pane to ask the homeowner to enter...
1. Explain the logic behind the application purchasing power price theory to explain changes in the...
1. Explain the logic behind the application purchasing power price theory to explain changes in the spot exchange rate. 2. Assume US interest rates are generally above foreign interest rates. a. what does this sideway about the future strength or weakness of the dollar based on the IFE (international Fisher effect)? b. should US investors invest in foreign securities if they believe in the IFE? c. should foreign investors invest in US securities if they believe in the IFE?
Can someone explain the logic behind this question? The addition of 1 g of which of...
Can someone explain the logic behind this question? The addition of 1 g of which of the following compounds to distilled water would cause the least change in pH? a) Cs(OH) b)HCl c) LiH d) LiOH I know that HCL is a strong acid which elimates that since it will affect PH. In class we had to memorize that group I metals with OH are strong bases making which LiOH and CsOH follow. The answer is A. The solution to...
Please Explain each of them in 10 lines: Please !!! If you write it in your...
Please Explain each of them in 10 lines: Please !!! If you write it in your handwriting, please be clear. answer all questions :) § how a changing magnetic field produces an electric field §Inductance and give examples of applications and relevance § the concept of electro magnetic field in self induction, how is it generated thank you,
Explain the logic behind the net present value decision rule and the internal rate of return...
Explain the logic behind the net present value decision rule and the internal rate of return decision rule.
Explain the logic behind the Bass diffusion model. How is the model useful to marketing managers?...
Explain the logic behind the Bass diffusion model. How is the model useful to marketing managers? What are the managerial implications of the model?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT