include \"Team.h\" using namespace std; Team::Team(){ name = \"\"; numMembers =
ID: 3822861 • Letter: I
Question
include "Team.h"
using namespace std;
Team::Team(){
name = "";
numMembers = 0;
}
Team::Team(string n){
name = n;
numMembers = 0;
}
Team::Team(string na, int n){
name = na;
numMembers = n;
}
ostream &operator<<( ostream &output, const Team &team ){
output << "Name : " << team.name << ", Number of members : " << team.numMembers<<endl;
return output;
}
istream &operator>>( istream &input, Team &team ){
getline(cin, team.name);
cin>>team.numMembers;
return input;
}
// overloaded prefix ++ operator
Team Team::operator++ (){
++numMembers;
return Team(name, numMembers);
}
Team Team::operator++( int x){
Team t(name, numMembers);
++numMembers;
return t;
}
bool Team::operator==(const Team& other) {
if(name == other.name && numMembers == other.numMembers)
return true;
else
return false;
}
bool Team::operator!=(const Team& other) {
return !(*this == other);
}
(file .cpp what is the getline call ? the over loaded prefix operator does what and its giving me errors
Explanation / Answer
istream &operator>>( istream &input, Team &team ){
getline(cin, team.name);
cin>>team.numMembers;
return input;
}
getline is used to read a line from given istream, in this case cin and save it in team.name;
/ overloaded prefix ++ operator
Team Team::operator++ (){
++numMembers;
return Team(name, numMembers);
}
Prefix +++ is supposed to increment numMembers but it is returing a new Team object, ideally it should return *this
/ overloaded prefix ++ operator
Team Team::operator++ (){
++numMembers;
return *this;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.