SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 304 Weeks Ago, 1 Day Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 11 Dec 2017 My Price 10.00

changes are much cleaner than what I had initially

Your changes are much cleaner than what I had initially.  The issue now is that it isn't selecting the players which have the highest projected point value for their team.  I started trying to create a max function.  I am getting errors that I don't really have time to work through.  Can you show me how to implement a max function for each position in your new code?

#include <iostream>
#include <string>
#include <fstream>
#include "Player.h"
using namespace std;

int main(){

    ifstream inData;                //declare input file stream
    ofstream outData;                //declare output file stream
    inData.open("players.txt");        //open input file
   
    //Check for error in opening file
    if (inData.fail())
    {
        cerr << "Error opening file" << endl;
        exit(1);
    }

    Player players[500];
   
    // titular players
    Player PG;
    Player SG;
    Player SF;
    Player PF;
    Player C;
    Player G;
    Player F;
    Player U;
   
    string fname;
    string lname;
    string team;
    string position;
    int salary;
    float valuePoints;
    float projPoints;
    float pointCost;
    int i = 0;

    string header;
    getline(inData, header);

   
    int teamsalary = 50000;
   
    //positioncounters
    int countPG = 0;
    int countSG = 0;
    int countSF = 0;
    int countPF = 0;
    int countC = 0;
    int countG = 0;
    int countF = 0;
    int countU = 0;
   
    bool isPG = false;
    bool isSG = false;
    bool isSF = false;
    bool isPF = false;
    bool isC = false;
    bool isG = false;
    bool isF = false;
    bool isU = false;

    // collect the data
    while (inData.good())
    {       
        inData >> fname;
        inData >> lname;
        inData >> team;
        inData >> position;
        inData >> salary;
        inData >> valuePoints;
        inData >> projPoints;
        inData >> pointCost;
       
        Player player1(fname + " " + lname, team, position, salary, valuePoints, projPoints, pointCost);
        players[i] = player1;
        i++;
    }
   
   
    int list = i; //number of players
    i = 0; // traverse the array
   
    // while the team is not full
    while ( !isPG || !isSG ||  !isSF ||  !isPF  ||  !isC || !isG ||  !isF || !isU || teamsalary < 0 ){
       
        //get point guard
         if (players[i].isPG(position) && (( teamsalary > 0 && !isPG ) || (teamsalary <= 0 && isPG)) )
         {
             if ( teamsalary > 0 )
            {
                if (!isPG)
                {
                    //assign the player
                    PG = players[i];
                    teamsalary = teamsalary - players[i].getSalary();
                    isPG = true;
                    //players[i].printPlayer();
                    //countPG++;
                    //PG.printPlayer();
                   
                }
            }
            else
            {
                if (isPG)
                {
                    if (PG.getSalary() > players[i].getSalary()  )
                    {
                        teamsalary = teamsalary + PG.getSalary();
                        teamsalary = teamsalary - players[i].getSalary();
                        PG = players[i];
                        //PG.printPlayer();
                       
   
                    }
                }
            }
         }
         
       

         //get shooting guard
         else if (players[i].isSG(position) && (( teamsalary > 0 && !isSG ) || (teamsalary <= 0 && isSG)))
         {
             if ( teamsalary > 0 )
            {
                if (!isSG)
                {
                    //assign the player
                    SG = players[i];
                    teamsalary = teamsalary - players[i].getSalary();
                    isSG = true;
                    //SG.printPlayer();
                }
            }
            else
            {
                if (isSG)
                {
                    if (SG.getSalary() > players[i].getSalary())
                    {
                        teamsalary = teamsalary + SG.getSalary();
                        teamsalary = teamsalary - players[i].getSalary();
                        SG = players[i];
                       
                        //SG.printPlayer();
   
                    }
                }
            }
         }
         

         //get small forward
         else if (players[i].isSF(position) && (( teamsalary > 0 && !isSF ) || (teamsalary <= 0 && isSF)))
         {
             if ( teamsalary > 0 )
            {
                if (!isSF)
                {
                    //assign the player
                    SF = players[i];
                    teamsalary = teamsalary - players[i].getSalary();
                    isSF = true;
                    //SF.printPlayer();
                }
            }
            else
            {
                if (isSF)
                {
                    if (SF.getSalary() > players[i].getSalary())
                    {
                        teamsalary = teamsalary + SF.getSalary();
                        teamsalary = teamsalary - players[i].getSalary();
                        SF = players[i];
                        //SF.printPlayer();
   
                    }
                }
            }
         }
         
         
         //get power forward
         else if (players[i].isPF(position) && (( teamsalary > 0 && !isPF ) || (teamsalary <= 0 && isPF)))
         {
             if ( teamsalary > 0 )
            {
                if (!isPF)
                {
                    //assign the player
                    PF = players[i];
                    teamsalary = teamsalary - players[i].getSalary();
                    isPF = true;
                    //PF.printPlayer();
                }
            }
            else
            {
                if (isPF)
                {
                    if (PF.getSalary() > players[i].getSalary())
                    {
                        teamsalary = teamsalary + PF.getSalary();
                        teamsalary = teamsalary - players[i].getSalary();
                        PF = players[i];
                        //PF.printPlayer();
   
                    }
                }
            }
         }
         
         //get center
         else if (players[i].isC(position) && (( teamsalary > 0 && !isC ) || (teamsalary <= 0 && isC)) )
         {
             if ( teamsalary > 0 )
            {
                if (!isC)
                {
                    //assign the player
                    C = players[i];
                    teamsalary = teamsalary - players[i].getSalary();
                    isC = true;
                    //C.printPlayer();
                }
            }
            else
            {
                if (isC)
                {
                    if (C.getSalary() > players[i].getSalary())
                    {
                        teamsalary = teamsalary + C.getSalary();
                        teamsalary = teamsalary - players[i].getSalary();
                        C = players[i];
                        //C.printPlayer();
   
                    }
                }
            }
         }
         

         //get point guard or shooting guard
         else if (players[i].isG(position) && (( teamsalary > 0 && !isG ) || (teamsalary <= 0 && isG)) )
         {
             if ( teamsalary > 0 )
            {
                if (!isG)
                {
                    //assign the player
                    G = players[i];
                    teamsalary = teamsalary - players[i].getSalary();
                    isG = true;
                    //G.printPlayer();
                }
            }
            else
            {
                if (isG)
                {
                    if (G.getSalary() > players[i].getSalary())
                    {
                        teamsalary = teamsalary + G.getSalary();
                        teamsalary = teamsalary - players[i].getSalary();
                        G = players[i];
                        //G.printPlayer();
   
                    }
                }
            }
         }
         

         //get small forward or power forward
         else if (players[i].isF(position) && (( teamsalary > 0 && !isF ) || (teamsalary <= 0 && isF)) )
         {
             if ( teamsalary > 0 )
            {
                if (!isF)
                {
                    //assign the player
                    F = players[i];
                    teamsalary = teamsalary - players[i].getSalary();
                    isF = true;
                    //F.printPlayer();
                }
            }
            else
            {
                if (isF)
                {
                    if (F.getSalary() > players[i].getSalary())
                    {
                        teamsalary = teamsalary + F.getSalary();
                        teamsalary = teamsalary - players[i].getSalary();
                        F = players[i];
                        //F.printPlayer();
   
                    }
                }
            }
         }
         

         //get players from any position
         else if (players[i].isU(position) && (( teamsalary > 0 && !isU ) || (teamsalary <= 0 && isU)) )
         {
             if ( teamsalary > 0 )
            {
                if (!isU)
                {
                    //assign the player
                    U = players[i];
                    teamsalary = teamsalary - players[i].getSalary();
                    isU = true;
                    //U.printPlayer();
                }
            }
            else
            {
                if (isU)
                {
                    if (U.getSalary() > players[i].getSalary())
                    {
                        teamsalary = teamsalary + U.getSalary();
                        teamsalary = teamsalary - players[i].getSalary();
                        U = players[i];
                        //U.printPlayer();
   
                    }
                }
            }
         }
         


        i++;
        // if exceed then travrerse again
        if (i >= list-1) i = 0;
        //    break;
    }
    PG.printPlayer();
    SG.printPlayer();
    SF.printPlayer();
    PF.printPlayer();
    C.printPlayer();
    G.printPlayer();
    F.printPlayer();
    U.printPlayer();
    cout << teamsalary << endl;
return 0;
}

Answers

(5)
Status NEW Posted 11 Dec 2017 08:12 AM My Price 10.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)