I have a school project where we suppose to make a spell check using pthreads,
it is suppose to have customer.h using linked list, will have 3 member functions (misspelled list, task list, word count)
and will have Server.h, this one can point to the linked list of customer.h,
but it will store a dictionary(.csv file) about 16_millions.csv of words.
the task list will be populated with the list of words to be checked .And then under main.cpp, it will take in a word from task list (also about millions), it will take the strings one by one, it will check if the string is in the dictionary, if it is, it goes to the next one without doing anything with that one found in the dictionary.csv(server.h), if the word is misspelled, it saves it in the misspelled list. basically it will be comparing two lists.
Welcome to the forums. As per the rules on the forum, we don't just give people solutions to homework assignments.
You mention that you need a customer.h and server.h file, with specified functions and linked list.
Please make an attempt at writing those and come back to us with the code and any specific problems you are having.
If you need help getting started, just let us know and we'll take it step by step.
//this is my Server.h
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdlib.h>
#include <ctime>
#include <string>
#include "Customer.h"
usingnamespace std;
/*template <class Type>
struct nodeType
{
Type info;
nodeType<Type>*link;
};
template <class Type>
struct nodeTypeCount
{
Type info;
long counter;
nodeType<Type>*link;
};*/
template <class Type>
class Server
{
public:
Server();
void fill_Dictionary();
//int length const();
void fill_SpellingCheck();
private:
int sizeof_DicList;
nodeType<Type>*DictionaryList_first;
nodeType<Type>*DictionaryList_last;
nodeType<Type>*DictionaryList_newNode;
};
template <class Type>
Server<Type>::Server()
{
DictionaryList_first = NULL;
DictionaryList_last = NULL;
sizeof_DicList = NULL;
}
template <class Type>
void Server<Type>::fill_Dictionary()
{
nodeType<Type>*DictionaryList_first;
nodeType<Type>*DictionaryList_last;
nodeType<Type>*DictionaryList_newNode;
//Randomising Which File Is to be used to populate 'TaskList'.
//If choose == 0, populate with 'Dictionary1.csv'
//If choose == 1, populate with 'Dictionary2.csv'
int b;
string words_1;
srand (time(NULL));
b = rand()%2;
if (b == 0)
{
ifstream infile("Dictionary1.txt");
while (!infile.eof())
{
infile >> words_1;//read words from a file and store a them in words
DictionaryList_newNode = new nodeType<Type>; //allocate memory of type nodeType
//and store the address of the
//allocated memory in newNode
DictionaryList_newNode->info = words_1; //copy 'words' into the
//info field of newNode
DictionaryList_newNode->link = NULL; //initialize the link field of
//newNode to NULL
if (DictionaryList_first == NULL) //if first is NULL, the list is empty;
//make first and last point to newNode
{
DictionaryList_first = DictionaryList_newNode;
DictionaryList_last = DictionaryList_newNode;
sizeof_DicList = NULL;
}
else //list is not empty
{
DictionaryList_last->link = DictionaryList_newNode; //insert newNode at the end of the list
DictionaryList_last = DictionaryList_newNode; //set last so that it points to the
//actual last node in the list
sizeof_DicList++;
}
}//end of while loop
infile.close();//TaskList is filled
}
if(b == 1)
{
ifstream infile("Dictionary2.csv");
while(!infile.eof())
{
infile >> words_1;//read words from a file and store a them in words
DictionaryList_newNode = new nodeType<Type>; //allocate memory of type nodeType
//and store the address of the
//allocated memory in newNode_1
DictionaryList_newNode->info = words_1; //copy 'words' into the
//info field of newNode
DictionaryList_newNode->link = NULL; //initialize the link field of
//newNode to NULL
if (DictionaryList_first == NULL) //if first is NULL, the list is empty;
//make first and last point to newNode
{
DictionaryList_first = DictionaryList_newNode;
DictionaryList_last = DictionaryList_newNode;
sizeof_DicList = NULL;
}
else //list is not empty
{
DictionaryList_last->link = DictionaryList_newNode; //insert newNode at the end of the list
DictionaryList_last = DictionaryList_newNode; //set last so that it points to the
//actual last node in the list
sizeof_DicList++;
}
cout << sizeof_DicList << endl;
}//end of while
infile.close();
}//end of if statement
}
//This is my Customer.h
#ifndef CUSTOMER_H
#define CUSTOMER_H
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdlib.h>
#include <ctime>
#include <string>
#include "Server.h"
usingnamespace std;
template <class Type>
struct nodeType
{
Type info;
nodeType<Type>*link;
};
template <class Type>
struct nodeTypeCount
{
Type info;
long counter;
nodeTypeCount<Type>*link;
};
template <class Type>
class Customer
{
public:
Customer();
void fill_TaskList();
void fill_MisspelledList();
int size() const;
void fill_WordCountList();
protected:
private:
string words;
int counter;
// Pointers for linked list 'TaskList'
nodeType<Type>*TaskList_first;// Pointer to the first node
nodeType<Type>*TaskList_last;// Pointer to the last node
nodeType<Type>*TaskList_newNode;// Pointer to the newNode node
nodeType<Type>*TaskList_current;
// Pointers for linked list 'MisspelledList'
nodeTypeCount<Type>*MisspelledList_first;
nodeTypeCount<Type>*MisspelledList_last;
nodeTypeCount<Type>*MisspelledList_newNode;
// Pointers for linked list 'WordCountList'
nodeTypeCount<Type>*WordCountList_first;
nodeTypeCount<Type>*WordCountList_last;
nodeTypeCount<Type>*WordCountList_newNode;
};
template <class Type>
Customer<Type>::Customer()
{
TaskList_first = NULL;
TaskList_last = NULL;
counter = NULL;
fill_TaskList();
TaskList_current=TaskList_first;
while(TaskList_current->link!=NULL)
{
cout<< TaskList_current->info <<endl;
TaskList_current = TaskList_current->link;
}
}
template <class Type>
void Customer<Type>::fill_TaskList()
{
//Randomising Which File Is to be used to populate 'TaskList'.
//If choose == 0, populate with '1.csv'
//If choose == 1, populate with '2.csv'
int a;
string words;
srand (time(NULL));
//a = rand()%2+1;
a=0;
//if (first != NULL) // if the list is non-empty, make it empty
//destroyList();
if (a == 0)
{
ifstream infile("1.txt");
while (infile >> words)
{
//infile >> words;//read words from a file and store a them in words
TaskList_newNode = new nodeType<Type>; //allocate memory of type nodeType
//and store the address of the
//allocated memory in newNode
TaskList_newNode->info = words; //copy 'words' into the
//info field of newNode
TaskList_newNode->link = NULL; //initialize the link field of
//newNode to NULL
if (TaskList_first == NULL) //if first is NULL, the list is empty;
//make first and last point to newNode
{ ;
TaskList_first = TaskList_newNode;
TaskList_last = TaskList_newNode;
}
else //list is not empty
{
TaskList_last->link = TaskList_newNode; //insert newNode at the end of the list
TaskList_last = TaskList_newNode; //set last so that it points to the
//actual last node in the list
}
}//end of while loop
infile.close();//TaskList is filled
}
if(a == 1)
{
ifstream infile("2.txt");
while(!infile.eof())
{
infile >> words;//read words from a file and store a them in words
TaskList_newNode = new nodeType<Type>; //allocate memory of type nodeType
//and store the address of the
//allocated memory in newNode
TaskList_newNode->info = words; //copy 'words' into the
//info field of newNode
TaskList_newNode->link = NULL; //initialize the link field of
//newNode to NULL
if (TaskList_first == NULL) //if first is NULL, the list is empty;
//make first and last point to newNode
{
TaskList_first = TaskList_newNode;
TaskList_last = TaskList_newNode;
}
else //list is not empty
{
TaskList_last->link = TaskList_newNode; //insert newNode at the end of the list
TaskList_last = TaskList_newNode; //set last so that it points to the
//actual last node in the list
}
}//end of while
TaskList_last->link=NULL;
infile.close();
}//end of if statement
}
#endif // CUSTOMER_H
fortune@ubuntu:~/Desktop/coms$ make
g++ -pthread -O3 -lrt -g -c main.cpp -o main.o
In file included from Customer.h:10:0,
from main.cpp:7:
Server.h:37:5: error: ‘nodeType’ does not name a type
Server.h:38:5: error: ‘nodeType’ does not name a type
Server.h:39:5: error: ‘nodeType’ does not name a type
Server.h: In constructor ‘Server<Type>::Server()’:
Server.h:45:5: error: ‘DictionaryList_first’ was not declared in this scope
Server.h:46:5: error: ‘DictionaryList_last’ was not declared in this scope
Server.h: In member function ‘void Server<Type>::fill_Dictionary()’:
Server.h:53:5: error: ‘nodeType’ was not declared in this scope
Server.h:53:18: error: expected primary-expression before ‘>’ token
Server.h:53:20: error: ‘DictionaryList_first’ was not declared in this scope
Server.h:54:18: error: expected primary-expression before ‘>’ token
Server.h:54:20: error: ‘DictionaryList_last’ was not declared in this scope
Server.h:55:18: error: expected primary-expression before ‘>’ token
Server.h:55:20: error: ‘DictionaryList_newNode’ was not declared in this scope
Server.h:70:42: error: expected type-specifier before ‘nodeType’
Server.h:70:42: error: expected ‘;’ before ‘nodeType’
Server.h:102:42: error: expected type-specifier before ‘nodeType’
Server.h:102:42: error: expected ‘;’ before ‘nodeType’
In file included from main.cpp:8:0:
Server.h: At global scope:
Server.h:28:7: error: redefinition of ‘class Server<Type>’
Server.h:28:7: error: previous definition of ‘class Server<Type>’
Server.h:43:1: error: redefinition of ‘Server<Type>::Server()’
Server.h:43:1: error: ‘Server<Type>::Server()’ previously declared here
Server.h:51:6: error: redefinition of ‘void Server<Type>::fill_Dictionary()’
Server.h:51:6: error: ‘void Server<Type>::fill_Dictionary()’ previously declared here
make: *** [main.o] Error 1
fortune@ubuntu:~/Desktop/coms$ D^C
fortune@ubuntu:~/Desktop/coms$
I think the following will fix quite a few of those errors:
error: ‘nodeType’ does not name a type
Server.h has the nodeType struct commented out, so the compiler doesn't know it.
error: redefinition of ‘class Server<Type>’
Your Server.h has no include guards (#ifndef / #define / #endif), so if you include it in both main.cpp and customer.h, it gets included twice, hence "redefined".