Skip to content

anonymous /compiler.cpp
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
// Filename: compiler.cpp
#include <iostream>
#include <cstdlib>
#include <fstream>
#include "compiler.h"
using namespace std;
Compiler::Compiler()
{
current = NULL;
//manynodes = 0;
}
bool Compiler::search_list(string item)
{
nodeType *p, *first;
p=first; //
do {
if(first->word==item)
{
return true;
}
p=p->link;
}
while (first->link!=NULL);
return false;
}
void Compiler::head_insert()
{
}
void Compiler::add_to_count()
{
}
ostream& operator<< (ostream & outfile, const Compiler & mylist)
{
nodeType* head_ptr = mylist.current;
while (head_ptr != NULL) //outputs the info of each node in list
{
outfile << head_ptr->word<<" ";
head_ptr = head_ptr->link;
}
outfile << endl; //creates nwln for each list
return outfile;
}
// Filename: compiler.h
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
struct nodeType
{
string word;
int count;
nodeType *link;
};
class Compiler
{
public:
Compiler();
bool search_list(string item); // Tells the client whether a spcific value is
//in the list.
// Calls a function search
void head_insert(); // Should be a member function
void add_to_count(); // Accesses the "current" pointer (in the private section)
// to update the count field of the node
// if the search is successful
friend ostream & operator<< (ostream &outfile, const Compiler & mylist);
// Overloaded operator to print both the data and the count field for each node
//int size()const; // yields manynodes
//void bubblesort();
protected:
nodeType *search1_list; // Called by the public function search_list
// sets the private member current to the node to be
// updated, or is NULL if the value is not there
//int manynodes;
private:
nodeType *current; // Add to the bag class.
// This pointer will be used in the search and again
// used to update the node if the data is already present
};
//void list_clear(nodeType*& head_ptr);
//void list_copy(const nodeType*source_ptr, nodeType*& head_ptr, nodeType*& tail_ptr);
educe
line
educe
primrose
depart
line
thwart
line
grand
cellular
line
educe
depart
manage
depart
headline
empire
torch
headline
line
myth
deposit
balance
cellular
educe
distance
#include <fstream>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <string>
#include "compiler.h"
using namespace std;
nodeType* CreateList(string);
void outputlist(nodeType* , string);
int main ()
{
ifstream infile;
ofstream outfile;
string inputfile, outputfile;
nodeType* head;
Compiler mylist;
/*infile.open ("input.txt");
if(!infile)
{
cout<<"Failure to open unsorted.txt."<<endl;
system("pause");
return 1;
}
outfile.open ("output.txt");
if(!outfile)
{
cout<<"Failure to open sorted.txt."<<endl;
system("pause");
return 1;
}*/
//getline(infile, mylist);
cout<<"Input file name:"<<endl;
getline(cin,inputfile);
head = CreateList(inputfile);
cout<<"Enter name of output file: ";
getline(cin, outputfile);
outputlist(head,outputfile);
//outfile << mylist;
//outfile <<endl<<endl;
/*mylist.search_list();
while (!infile.eof())
{
cout<<mylist<<endl;
infile>>mylist;
}*/
//out4<<hashtable[i]; // out4 is an ofstream object
infile.close();
outfile.close();
return 0;
}
nodeType* CreateList(string filename)
{
ifstream infile;
infile.open(filename.c_str());
nodeType* head = NULL;
nodeType* compiled;
compiled = new nodeType;
while(infile && compiled != NULL)
{
getline(infile, compiled -> word);
compiled->link = head;
head = compiled;
compiled = new nodeType;
}
delete compiled;
infile.close();
return head;
}
void outputlist(nodeType* head, string outputfile)
{
ofstream outfile;
outfile.open(outputfile.c_str());
nodeType* compiled;
compiled = head;
while(outfile && compiled !=NULL)
{
outfile << compiled -> word;
outfile << endl;
compiled = compiled -> link;
}
outfile.close();
}
/*void load()
{
ifstream infile("input.txt");
struct Compiler *temp, *head, *link;
if(infile.is_open())
{
string line, name;
while (infile.good()) {
{
temp = (Compiler*)malloc(sizeof(Compiler));
temp->link = head;
head = temp;
infile.getline(temp->name,1024);
//infile>>temp->compiling;
//getline(infile,line);
//infile.getline(temp->
}
}
infile.close();
}
else cout<<"Unable to open file.";
}*/
distance
educe
cellular
balance
deposit
myth
line
headline
torch
empire
headline
depart
manage
depart
educe
line
cellular
grand
line
thwart
line
depart
primrose
educe
line
educe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.