Question

team list The team list is a dynamic linked list of team objects. The only data needed is a head pointer for the linked list

readData: Reads data from a file called teams.txt and adds them to the linked list. The format of the input file is, for ea

Need help with this class and function please!!!

#include <iostream>

using namespace std;

class Team {

string teamId;

string name;

string coach;

Team *next;

friend class teamlist;

public:

Team * getNext();

return next;

void setNext(Team *r);

next=r;

  

string getTeamId();

return teamId;

  

void setTeamId(string aTeamId);

teamId = aTeamId;

  

string getName();

return name;

  

void setName(string aName);

name = aName;

  

string getCoach();

return coach;

void setCoach(string aCoach);

coach = aCoach;

}

team list The team list is a dynamic linked list of team objects. The only data needed is a head pointer for the linked list (optional: a tail pointer). The constructor should set the head (and tail) to NULL The methods that should be implemented include: addTeam: given a new team object Dynamically allocates a new team object and copies the data from the given object into the dynamic object. It should then add the new object to the front (head) of the linked list.
readData: Reads data from a file called "teams.txt" and adds them to the linked list. The format of the input file is, for each team: first line: the Team ld, a string with no spaces second line: the Team Name, a string with spaces - third line: the Coach, a string with spaces There is no "number of teams" nor a Sentinel value at the end of the data. Instead use the .eof() method of an ifstream to detect end of file. Ex: while (!f.eof)) .) A sample input file is provided on the course website. Here is one with two teams: UK Kentucky Wildcats Calipari LOU Louisville Cardinals Job Open printTeams: Prints the team list report as described above, based on data currently in the linked list of teams. getTeamRef given: a Team lod returns: a pointer to a team, or NULL Searches the current linked list for a team object that has a matching Team ld member. When found, return the pointer to the team object found; otherwise, return NULL for "not found" getNumTeams: returns: the number of teams in the list. Count and return the number of nodes in the list, which may be 0.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

PLEASE DON'T FORGET TO UPVOTE THE ANSWER, IF YOU LIKE IT.

As you have already written the class Team, I am answering the part of the ques asking for the class teamlist.

=========================================================

class teamlist{
Team* head;
Team* tail;
int noOfTeams;
public:
teamlist(){
head=NULL;
tail=NULL;
noOfTeams=0;
}
void addTeam(Team *t){
Team *team=new team(t);
if(head==NULL){
head=team;
tail=team;
}
else{
tail->next=team;
tail=tail->next;
}
noOfTeams++;
}
void readData(char* filename){
ifstream inFile;
inFile.open(filename);
while(!inFile.eof()){
noOfTeams++;
string id,name,coach;
inFile.getline(cin,id);
inFile.getline(cin,name);
inFile.getline(cin,coach);
Team* newteam=new Team();
newteam.setTeamId(id);
newteam.setName(name);
newteam.setCoach(coach);
if(head==NULL){
head=newteam;
tail=newteam;
}
else{
tail->next=newteam;
tail=tail->next;
}
}
}
void printTeams(){
Team* temp=head;
while(temp!=NULL){
cout<<temp->teamId<<endl<<temp->name<<endl<<temp->coach<<endl;
temp=temp->next;
}
}
Team* getTeamRef(string id){
Team* temp=head;
while(temp!=NULL){
if(id.compare(temp->teamId)==0) return temp;
temp=temp->next;
}
return NULL;
}
int getNumTeams(){
return noOfTeams;
}
};

Add a comment
Know the answer?
Add Answer to:
Need help with this class and function please!!! #include <iostream> using namespace std; c...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • USING THIS CODE: #include <iostream> #include <string> using namespace std; class Contact { //this class cannot...

    USING THIS CODE: #include <iostream> #include <string> using namespace std; class Contact { //this class cannot be viewed from outside of the private class. //only the class functions within the class can access private members. private: string name; string email; string phone; //the public class is accessible from anywhere outside of the class //however can only be within the program. public: string getName() const { return name; } void setName(string name) { this->name = name; } string getEmail() const {...

  • //LinkedList import java.util.Scanner; public class PoD {    public static void main( String [] args )...

    //LinkedList import java.util.Scanner; public class PoD {    public static void main( String [] args ) { Scanner in = new Scanner( System.in ); LinkedList teamList = new LinkedList(); final int TEAM_SIZE = Integer.valueOf(in.nextLine()); for (int i=0; i<TEAM_SIZE; i++) { String newTeamMember = in.nextLine(); teamList.append(newTeamMember); } while (in.hasNext()) { String removeMember = in.nextLine(); teamList.remove(removeMember); }    System.out.println("FINAL TEAM:"); System.out.println(teamList); in.close(); System.out.print("END OF OUTPUT"); } } =========================================================================================== //PoD import java.util.NoSuchElementException; /** * A listnked list is a sequence of nodes with...

  • #include "name.h" #include "contact.h" using namespace std; class ContactList; typedef class Node* NodePtr; class Node {...

    #include "name.h" #include "contact.h" using namespace std; class ContactList; typedef class Node* NodePtr; class Node {     Contact item;     NodePtr next;     friend class ContactList; }; class ContactList { public:     ContactList(char* clfile) ;     ~ContactList();     void display       (ostream & output) const;     int   insert        (Contact record_to_insert);     int   insert        (ContactList contact_list);     int   remove        (Contact record_to_delete);     int   size          () const;     int   save          () const;     void find_by_lname (ostream & output, string lname) const;     void...

  • could somone please help me to complete this ! public class MyLinkedList<AnyType> { private Node<AnyType> head,...

    could somone please help me to complete this ! public class MyLinkedList<AnyType> { private Node<AnyType> head, tail; private int size; public MyLinkedList() { this.head = null; this.tail = null; this.size = 0; } //1.Insert a node at the end of the list public void insert(AnyType data) { Node<AnyType> newNode = new Node(); newNode.data = data; if (head == null) { head = newNode; tail = newNode; head.next = null; tail.next = null; } else { tail.next = newNode; tail =...

  • #include <iostream> using namespace std; struct ListNode { float value; ListNode *next; }; ...

    #include <iostream> using namespace std; struct ListNode { float value; ListNode *next; }; ListNode *head; class LinkedList { public: int insertNode(float num); void deleteNode(float num); void destroyList(); void displayList(); LinkedList(void) {head = NULL;} ~LinkedList(void) {destroyList();} }; int LinkedList::insertNode(float num) { struct ListNode *newNode, *nodePtr = head, *prevNodePtr = NULL; newNode = new ListNode; if(newNode == NULL) { cout << "Error allocating memory for new list member!\n"; return 1; } newNode->value = num; newNode->next = NULL; if(head==NULL) { cout << "List...

  • Please rewrite this function using recursive function #include using namespace std; struct Node { char ch;...

    Please rewrite this function using recursive function #include using namespace std; struct Node { char ch; Node* next; }; class LinkedList { Node* head; public: LinkedList(); ~LinkedList(); void add(char ch); bool find(char ch); bool del(char ch); friend std::ostream& operator<<(std::ostream& out, LinkedList& list); }; LinkedList::LinkedList() { head = NULL; } LinkedList::~LinkedList() { Node* cur = head, * tmp; while (cur != NULL) { tmp = cur->next; delete cur; cur = tmp; } } void LinkedList::add(char ch) { Node* cur = head,...

  • Study the recursive instance method length()of MyLinkedList2 class and its associated auxiliary method. Then solve (a),...

    Study the recursive instance method length()of MyLinkedList2 class and its associated auxiliary method. Then solve (a), (b), and (c) below in a similar way: (a)   Convert the method public Element find(Object obj)of MyLinkedList2 class to a recursive one. Use an auxiliary private method. (b)   Convert the method public String toString( )of MyLinkedList2 class to a recursive one such that it returns the string representation of a linked list in the form: {ValueDatum1  valueDatum2 valueDatum3  . . .  valueDatumN-1   valueDatumN} Use an auxiliary private method....

  • #include <iostream> #include <fstream> using namespace std; //constants const int CAP = 100; //function prototypes bool...

    #include <iostream> #include <fstream> using namespace std; //constants const int CAP = 100; //function prototypes bool openFile(ifstream &); void readData(ifstream &, int [], int &); void printData(const int [], int); void sum(const int[], int); void removeItem(int[], int &, int); int main() { ifstream inFile; int list[CAP], size = 0; if (!openFile(inFile)) { cout << "Program terminating!! File not found!" << endl; return -1; } //read the data from the file readData(inFile, list, size); inFile.close(); cout << "Data in file:" <<...

  • PLEASE HELP WITH THE FIX ME'S #include #include #include #include "CSVparser.hpp" using namespace std; //==...

    PLEASE HELP WITH THE FIX ME'S #include #include #include #include "CSVparser.hpp" using namespace std; //============================================================================ // Global definitions visible to all methods and classes //============================================================================ // forward declarations double strToDouble(string str, char ch); // define a structure to hold bid information struct Bid { string bidId; // unique identifier string title; string fund; double amount; Bid() { amount = 0.0; } }; //============================================================================ // Linked-List class definition //============================================================================ /** * Define a class containing data members and methods to *...

  • a7q3.cc File #include <iostream> #include <cstring> #include "ArrayList.h" using namespace std; // Algorithm copy(s) // Pre:...

    a7q3.cc File #include <iostream> #include <cstring> #include "ArrayList.h" using namespace std; // Algorithm copy(s) // Pre: s :: refToChar // Post: memory allocated on heap to store a copy // Return: reference to new string char *copy(char *s) { char *temp = new char[strlen(s)+1]; strcpy(temp,s); return temp; } void test_ListOperations(){    cout << "testing createList" << endl;    List *myList = createList(10);    if (myList == NULL){ cout << "createList failed" << endl; return; } else{ cout << "createList succeeded"...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT