Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Basically, I just need the second part (the overloading) done. NOTE: The data type for project 1 is referring to a class I created called

image text in transcribed

Basically, I just need the second part (the overloading) done.

NOTE: The data type for project 1 is referring to a class I created called Combine. In this class, I wrote code that takes a text file containing information on different football players and their combine results and stores those players as a vector of objects of the class. The code is below

CODE FROM PROJECT 1:

Combine.h:

#ifndef COMBINE_H_ #define COMBINE_H_  #include  #include  #include  #include  #include  #include   using namespace std; class Combine { private: string name, college, pos; int height, weight; float dash, bench; public: //CONSTRUCTORS  Combine() { name = "John Smith"; college = "University"; pos = "player"; height = 0; weight = 0; dash = 0; bench = 0; } Combine(string name, string college, string pos, int height, int weight, float dash, float bench) { this->name = name; this->college = college; this->pos = pos; setHeight(height); setWeight(weight); setDash(dash); setBench(bench); } //GETTERS  string getName() const  { return name; } string getCollege() const  { return college; } string getPos() const  { return pos; } int getHeight() const  { return height; } int getWeight() const  { return weight; } float getDash() const  { return dash; } float getBench() const  { return bench; } //SETTERS  void setName(string name) { this->name = name; } void setCollege(string college) { this->college = college; } void setPos(string pos) { this->pos = pos; } void setHeight(int height) { if (height //Default value  this->height = 0; } else  { this->height = height; } } void setWeight(int weight) { if (weight //Default value  this->weight = 0; } else  { this->weight = weight; } } void setDash(float dash) { if (dash //Default value  this->dash = 0; } else  { this->dash = dash; } } void setBench(float bench) { if (bench //Default value  this->bench = 0; } else  { this->bench = bench; } } // Overloaded operators  friend ostream& operatorconst Combine &com) { outs return outs; } friend bool operator == (const Combine &player1, const Combine &player2) { return player1.getName() == player2.getName(); } }; /* getPlayersFromFile reads the file containing the dataset in and assigns each entry its attributes.  * The function is similar to what we looked at in class; however, I made one major change which was including stringstream  * simply for better handling of values  */ void getPlayersFromFile(string filename, vector &players) { ifstream inFile; // Use ../ to get out of the cmake-build-debug folder to find the file  inFile.open("../" + filename); // inFile.open(filename);  string name = "", college = "", pos = "", header = ""; string temp; int height = 0, weight = 0; float dash = 0, bench = 0; char comma = ','; // check that the file is in a good state  if (inFile) { // read in the header line  getline(inFile, header); // loop through all the data in the file  while (inFile && inFile.peek() != EOF) { // read line  getline(inFile,temp); // pass it to string stream  stringstream ss(temp); // get name  getline(ss,name,','); // get college  getline(ss,college,','); // get POS  getline(ss,pos,','); // get height  getline(ss,temp,','); height = atoi(temp.c_str()); // get weight  getline(ss,temp,','); weight = atoi(temp.c_str()); if(ss.good()) { // get 40 yard  getline(ss,temp,','); dash = atof(temp.c_str()); } else{ dash=0; } if(ss.good()) { // get bench press  getline(ss,temp,','); bench = atof(temp.c_str()); } else{ bench=0; } // create a Combine object and put it on the back of the vector  players.push_back(Combine(name, college, pos, height, weight, dash, bench)); } } else  { cerr "File not found" /*  * avgWeight simply accepts the vector of the Combine class from main and iterates through each object, adding the each entry's (player's) weight to the get the sum before  * dividing by the size of the vector to calculate the average.  */ float avgWeight(vector &players) { float total = 0; getPlayersFromFile("CombinePlayers.txt", players); for (int i = 0; i //cout  } cout "The average weight of a player is: " "lbs" return (total/players.size()); }

Main.cpp:

#include "Combine.h" #include  using namespace std; int main() { vector players; getPlayersFromFile("CombinePlayers.txt", players); 

}

- You will want to start at the end of Project 1. You should have a vector of 1000+ objects in your main function. - You will need to overload the , =, and == operators of your class from Project 1. Use a unique field to compare objects of your class. - You will want to start at the end of Project 1. You should have a vector of 1000+ objects in your main function. - You will need to overload the , =, and == operators of your class from Project 1. Use a unique field to compare objects of your class

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions