Hi all,
So i'm creating a program that will read a file into a linked list. And the user will be able to add, remove and display the list. Im suppose to create a search function in order to find the link to remove or add or display.
Here is what i did so far:
Header file:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
struct NodeType
{
long Id_Num;
string Name;
string Phone;
char Status;
float Income;
NodeType* Next; //Pointer to the next link
NodeType(NodeType newelement, long id, string nam, string pho, char stats, float inc) : Id_Num(id), Name(nam),
Phone(pho), Status(stats), Income(inc){ };
};
class ClubMember
{
private:
NodeType* first; //pointer to first link
public:
ClubMember()
{
first = NULL;
}
void add(long Id, string name, string phone, char stats, float inc);
void remove(long Id);
void input();
void display();
};
//clubmembership.cpp
#include <iostream>
#include <fstream>
#include <string>
#include "clubmembership.h"
using namespace std;
NodeType search(long id);
void ClubMember::input()
{
ifstream infile("member.dat");
long id;
string name;
string phone;
char stats;
float income;
while(!infile.eof())
{
infile >> id >> name >> phone >> stats >> income;
add(id,name,phone,stats,income);
}
}
/*void ClubMember::display()
{
int idnum;
cout << "Enter ID Number: ";
cin >> idnum;
cout << endl;
NodeType result;
result = search(idnum);
if(result.Id_Num != 0000)
{
cout << "Id Number: " << result.Id_Num << endl;
cout << "Name: " << result.Name << endl;
cout << "Phone: " << result.Phone << endl;
cout << "Status: " << result.Status << endl;
cout << "Income: " << result.Income << endl;
cout << endl;
}
else
{
cout << "ID Number not found. Please make another selection." << endl << endl;
}
}//*/
void ClubMember::add(long Id, string name, string phone, char stats, float inc)
{
NodeType* temp;
NodeType* newItem = new NodeType(Id, name, phone,stats, inc);
temp = newItem;
temp->Next = first;
first = temp;
}
void ClubMember::remove(long Id)
{
if(first->Id_Num == Id)
{
first = first->Next;
first->Next = NULL;
}
NodeType *current = first;
NodeType *previous;
while(current->Next != NULL)
{
previous = current;
current = current->Next;
if(current->Id_Num==Id)
{
previous->Next = current->Next;
current->Next = NULL;
}
}
}
NodeType search(long id)
{
NodeType *temp;
NodeType invalid;
invalid.Id_Num = 0000;
invalid.Name = "Invalid";
invalid.Phone = "000-0000";
invalid.Status = 0;
invalid.Income = 0000000;
while(temp != NULL)
{
if(temp->Id_Num == id)
{
return *temp;
}
else
{
temp = temp->Next;
}
}
return invalid;
}
// main.cpp
#include <iostream>
#include "clubmembership.h"
using namespace std;
int main()
{
ClubMember zoop;
zoop.input();
zoop.display();
zoop.add(123,"maws","mom",'m',1238);
zoop.display();
zoop.remove(123);
zoop.display();
return 0;
}
So the compiler is giving me this error:
: error C2512: 'NodeType' : no appropriate default constructor available
Thanks for the help,
Doug