Sep 1, 2012 at 11:58pm UTC
So I am writing a program. I ahven't programed in a year do to a medical issue but I am back in it. WE have to write a word counter program that reads the words in a file whose name is given through the command line. We then have to output it in alphabetical order and say how many times a word appears. WE have to use STL map and use OO. I have most of it written out but im not understanding it. someone help?
Sep 2, 2012 at 2:55am UTC
*Confused* :/
How can u have most of it written out but not understand what u wrote ? Know the design before coding it...
Last edited on Sep 2, 2012 at 2:56am UTC
Sep 2, 2012 at 3:03am UTC
Well there a some parts I've written. It's just instantiating my class in main
Sep 2, 2012 at 4:34am UTC
Show your code(use code tags PLEASE), and comment out the spots you cant understand. We need something to work with.
Sep 2, 2012 at 4:42am UTC
absolutely.
My Header File:
#ifndef WORDCOUNTER_H
#define WORDCOUNTER_H
#include <map>
#include <string>
using namespace std;
class WordCounter
{
public:
map<string, int>* my_map;
string tempstr;
WordCounter();// constructor set tempstr to ' '
void ReadChar();// use map here to read in words and print
};
#endif
My .cpp file for my header:
#include "lab1.h"
#include <iostream>
#include <map>
#include <string>
#include<stdio.h>
#include<string.h>
using namespace std;
//sets value of value to 0
WordCounter::WordCounter()//DONE
{
my_map = new map<string, int>;
tempstr = "";
}
int WordCounter::ReadChar()
{
//map<string, int> my_map;
string my_word;// This is an input buffer for the word
my_map.insert(pair<string,int>(my_word,1));
pair< map<string,int>::iterator , bool> > my_return;
// May fail
my_return = my_map.insert(pair<string,int>(my_word,1));
// Return failed
if(ret.second == false)
{
// increment the value of the map element
}
map<string, WordCounter,less<string> >::iterator it;
for ( it = counter.begin();it != counter.end(); it++ )
{
cout << it.first() << ' ' << it.second() << endl;
}
}
My Main.cpp:
int main(int argc, char *argv[])
{
WordCounter word_count;
string buffer, my_word;
//ifstream my_ifile;
ifstream my_ifile(argv[1], ios::in);//reads file from input line
my_ifile.open();
if(!my_ifile)
{
return 1;
}
while (my_ifile.getline(buffer) != false)
{
word_count.insert(pair<string,int>(my_word,1))
}
}
Most of this im sure is wrong :/
Sep 5, 2012 at 6:14am UTC
Hey why not try in scripting, like batch script or shell scripts ? That would be much helpful in it..