In C++ please write a Pseudo code for the following program explain each step thoroughly #include #include

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

In C++ please write a Pseudo code for the following program explain each step thoroughly #include #include

Post by answerhappygod »

In C++ please write a Pseudo code for the following program
explain each step thoroughly
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <climits>
#include <vector>
#include <algorithm>
#include <array>
#include <string>
using namespace std;
// creating structure
struct Teams
{
string name;
double score = 0;
};
struct WinLoseCount
{
string teamName;
int reps;
int lossesInARow;
};
//function to check stored values in array
void arrayPrinter(Teams array[][2], int rowTracker);
//function for finding the average winning teams' score
double averageWinning(Teams array[][2], int rows);
//function for finding the average losing teams' score
double averageLosing(Teams array[][2], int rows);
//function for computing the maximum score
int maxScore(Teams array[][2], int rows);
//function for computing the minimum score
int minScore(Teams array[][2], int rows);
int rowTracker;
int columnTracker;
int main()
{
ifstream gameRecords;
gameRecords.open("SuperBowlData.txt");
// Checks if the file is open
/*if (gameRecords.is_open())
{
cout << "The file is open"
<< endl;
}*/

int count = 1;
char ch;
//counts the amount of rows in SBD
while(!gameRecords.fail()) {
gameRecords.get(ch);
if(ch == '\n') {
count++;
}
}
gameRecords.clear();
gameRecords.seekg(0, gameRecords.beg);

//array for structure
Teams array[count][2]; //2 teams

string line;
string checker;
int lineCounter = 0;
int winningOrLosingTeam = 0; // 0 is winning and 1 is
losing
while (getline(gameRecords, line)) // need to use
getline to get file stored line
{
istringstream values;
values.str(line); //we get each line of
the code
while (values >> checker) // we
put each line of the code into a word and check that
{
if (isdigit(checker[0])
&& winningOrLosingTeam == 0)
{

array[lineCounter][winningOrLosingTeam].score =
stod(checker);

winningOrLosingTeam = 1;
}
else if
(winningOrLosingTeam == 0)
{

array[lineCounter][winningOrLosingTeam].name =
array[lineCounter][winningOrLosingTeam].name + " " + checker;
}
else if
(isdigit(checker[0]) && winningOrLosingTeam == 1)
{

array[lineCounter][winningOrLosingTeam].score =
stod(checker);

winningOrLosingTeam = 0;
}
else if
(winningOrLosingTeam == 1)
{

array[lineCounter][winningOrLosingTeam].name =
array[lineCounter][winningOrLosingTeam].name + " " + checker;
}
}
rowTracker++; //keeps track of the
rows
lineCounter++; //adds lines
}
//First Super Bowl Winner
string firstSuperBowlWinner = array[0][0].name;
cout << "First Super Bowl winner: " <<
firstSuperBowlWinner << ", score: " <<
array[0][0].score << "\n" << endl;
//Most recent super bowl winner
cout << "Most Recent Super Bowl winner: " <<
array[rowTracker-1][0].name << ", score: " <<
array[rowTracker-1][0].score << "\n" << endl;

//Print maximum score
cout << "Maximum score from any Super Bowl team: "
<< maxScore(array, rowTracker) << "\n" <<
endl;

//Print minimum score
cout << "Minimum score from any Super Bowl team: "
<< minScore(array, rowTracker) << "\n" <<
endl;

//Print average winning teams' score
cout << "Average winning score from Super Bowl teams:
" << fixed << setprecision(2) <<
averageWinning(array, rowTracker) << "\n" <<
endl;

//Print average losing teams' score
cout << "Average losing score from Super Bowl teams: "
<< fixed << setprecision(2) <<
averageLosing(array, rowTracker) << "\n" << endl;

//arrayPrinter(array, rowTracker);
cout << endl;
//start of counting reps
string winningTeams[count];
for(int i = 0; i < count; i++) {
winningTeams = array[0].name;
}
//int WinSize =
sizeof(winningTeams)/sizeof(winningTeams[0]);
//sort(winningTeams, winningTeams+WinSize);
string losingTeams[count];
for(int i = 0; i < count; i++) {
losingTeams = array[1].name;
}

vector<WinLoseCount> Wins;
vector<WinLoseCount> Losses;
vector<WinLoseCount> totLosses;
//Wins
int place = 0;
for(int i = 0; i < count; i++) {
int rep = 1;
while(winningTeams == winningTeams[i+1]) {
rep++;
i++;
}
if(winningTeams != winningTeams[i+1]) {
Wins.push_back(WinLoseCount());
Wins[place].teamName = winningTeams;
Wins[place].reps = rep;
place++;
}
}/*
for(int i = 0; i < Wins.size(); i++) {
cout << Wins.teamName << " " <<
Wins.reps << endl;
}*/
//for finding team(s) that won the most
int maxwins = Wins[0].reps;
for(int i = 1; i < Wins.size(); i++) {
if(maxwins < Wins.reps) {
maxwins = Wins[i].reps;
}
}
cout << "The team(s) that has/have won the most times
in a row is/are: " << endl;
int num = 0;
bool check = true;
for(int i = 0; i < Wins.size(); i++)
{
if(Wins[i].reps == maxwins)
{
check = true;
for (int j = 0 ; j < i ; j++)
{
if (Wins[j].reps == maxwins)
{
if (Wins[i].teamName ==
Wins[j].teamName)
{
check = false;
break;
}
}
}
if (check)
{
if (num > 0) {cout << ",
";}
cout << Wins[i].teamName;
num++;
}
}
}
cout << "\nThey won " << maxwins << "
times in a row.\n";
cout << endl;
//Losses
int spot = 0;
for(int i = 0; i < count; i++) {
int streak = 1;
while(losingTeams[i] == losingTeams[i+1]) {
streak++;
i++;
}
if(losingTeams[i] != losingTeams[i+1]) {
Losses.push_back(WinLoseCount());
Losses[spot].teamName = losingTeams[i];
Losses[spot].reps = streak;
spot++;
}
}/*
for(int i = 0; i < Wins.size(); i++) {
cout << Wins[i].teamName << " " <<
Wins[i].reps << endl;
}*/
int maxlosses = Losses[0].reps;
for(int i = 1; i < Losses.size(); i++) {
if(maxlosses < Losses[i].reps) {
maxlosses = Losses[i].reps;
}
}
cout << "The team(s) that have lost the most times in
a row is/are: " << endl;
for(int i = 0; i < Losses.size(); i++) {
if(Losses[i].reps == maxlosses) {
cout << Losses[i].teamName <<
endl;
}
}
cout << "They lost " << maxlosses << "
times in a row.\n";
cout << endl;
int LossSize =
sizeof(losingTeams)/sizeof(losingTeams[0]);
sort(losingTeams, losingTeams+LossSize);
//Total Losses by a team
int marker = 0;
for(int i = 0; i < count; i++) {
int L = 1;
while(losingTeams[i] == losingTeams[i+1]) {
L++;
i++;
}
for(int j = 0; j < count; j++) {
if(losingTeams[i] == winningTeams[j]) {
L = 0;
}
}
if(losingTeams[i] != losingTeams[i+1]) {
totLosses.push_back(WinLoseCount());
totLosses[marker].teamName =
losingTeams[i];
totLosses[marker].reps = L;
marker++;
}
}
int totMaxLosses = totLosses[0].reps;
for(int i = 1; i < totLosses.size(); i++) {
if(totMaxLosses < totLosses[i].reps) {
totMaxLosses = totLosses[i].reps;
}
}
cout << "The team(s) that have lost the most times but
never won is/are: " << endl;
for(int i = 0; i < totLosses.size(); i++) {
if(totLosses[i].reps == totMaxLosses) {
cout << totLosses[i].teamName <<
endl;
}
}
cout << "They lost " << totMaxLosses << "
times .\n";
cout << endl;

}
//end of main function
void arrayPrinter(Teams array[][2], int rowTracker)
{
for (int i = 0; i < rowTracker; i++)
{
for (int j = 0; j < 2; j++)
{
cout <<
array[i][j].name << " " << array[i][j].score << "
";
}
cout << endl;
}
}
//function for finding the average winning teams' score
double averageWinning(Teams array[][2], int rows)
{
double average = 0.0;
for (int i = 0 ; i < rows ; i++)
{
average+= array[i][0].score;
}
return (average/rows);
}
//function for finding the average losing teams' score
double averageLosing(Teams array[][2], int rows)
{
double average = 0.0;
for (int i = 0 ; i < rows ; i++)
{
average+= array[i][1].score;
}
return (average/rows);
}
//function for computing the maximum score
int maxScore(Teams array[][2], int rows)
{
int maximumScore = INT_MIN;
for (int i = 0 ; i < rows ; i++)
{
if (array[i][0].score > maximumScore)
{maximumScore = array[i][0].score;}
if (array[i][1].score > maximumScore)
{maximumScore = array[i][1].score;}
}
return maximumScore;
}
//function for computing the minimum score
int minScore(Teams array[][2], int rows)
{
int minimumScore = INT_MAX;
for (int i = 0 ; i < rows ; i++)
{
if (array[i][0].score < minimumScore)
{minimumScore = array[i][0].score;}
if (array[i][1].score < minimumScore)
{minimumScore = array[i][1].score;}
}
return minimumScore;
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply