In: Computer Science
Write a C++ program to open and read a text file and count each unique token (word) by creating a new data type, struct, and by managing a vector of struct objects, passing the vector into and out of a function.
Declare a struct TokenFreq that consists of two data members: (1) string value; and (2) int freq; Obviously, an object of this struct will be used to store a specific token and its frequency. For example, the following object word stores the token "dream" and its frequency 100:
TokenFreq word;
word.value="dream";
word.freq=100;
Implement the function vector<TokenFreq> getTokenFreq( string inFile_name); This function reads the specified input file line by line, identifies all the unique tokens in the file and the frequency of each token. It stores all the identified (token, freq) pairs in a vector and returns this vector to the calling function. Don't forget to close the file before exiting the function.
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <cstring>
using namespace std;
struct TokenFreq
{
string value;
int freq;
};
vector<TokenFreq> getTokenFreq(string inFile_Name)
{
}
int main()
{
}
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
/*
* Node Declaration
*/
struct node
*start, *last;
int counter = 0;
/*
* category Declaration
*/
class double_clist
begin = NULL;
last = NULL;
}
};
/*
* Main: Contains Menu
*/
int main()
worker = new(struct node);
temp->info = value;
temp->next = NULL;
temp->prev = NULL;
come back temp;
}
/*
*INSERTS component AT starting
*/
void double_clist::insert_begin()
{
int value;
cout<<endl<<"Enter the component to be
inserted: ";
cin>>value;
struct node *temp;
temporary worker = create_node(value);
if (start == last && begin == NULL)
{
cout<<"Element inserted in empty
list"<<endl;
begin = last = temp;
start->next = last->next = NULL;
start->prev = last->prev = NULL;
}
else
{
temp->next = start;
start->prev = temp;
begin = temp;
start->prev = last;
last->next = start;
cout<<"Element inserted"<<endl;
}
}
/*
*INSERTS ELEMNET eventually
*/
void double_clist::insert_last()
{
int value;
cout<<endl<<"Enter the component to be
inserted: ";
cin>>value;
struct node *temp;
temporary worker = create_node(value);
if (start == last && begin == NULL)
{
cout<<"Element inserted in empty
list"<<endl;
begin = last = temp;
start->next = last->next = NULL;
start->prev = last->prev = NULL;
}
else
}
/*
*INSERTS component AT POSITION
*/
void double_clist::insert_pos()
{
int value, pos, i;
cout<<endl<<"Enter the component to be
inserted: ";
cin>>value;
cout<<endl<<"Enter the postion of
component inserted: ";
cin>>pos;
struct node *temp, *s, *ptr;
temporary worker = create_node(value);
if (start == last && begin == NULL)
{
if (pos == 1)
{
begin = last = temp;
start->next = last->next = NULL;
start->prev = last->prev = NULL;
}
else
ptr->next = s->next;
s->next->prev = ptr;
if (pos == counter)
counter--;
free(s);
cout<<"Element Deleted"<<endl;
}
/*
* Update worth of a selected node
*/
void double_clist::update()
{
int value, i, pos;
if (start == last && begin == NULL)
s->info = value;
cout<<"Node Updated"<<endl;
}
/*
* Search component within the list
*/
void double_clist::search()
zero, value, i;
bool flag = false;
struct node *s;
if (start == last && begin == NULL)