home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / cplus / 11786 < prev    next >
Encoding:
Text File  |  1992-07-30  |  4.2 KB  |  171 lines

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!usc!rpi!bu.edu!transfer!ceylon!bunny!dwo1
  2. From: dwo1@gte.com (Donald W. Ottens)
  3. Newsgroups: comp.lang.c++
  4. Subject: read stdin & output list of unique words
  5. Message-ID: <18660@bunny.GTE.COM>
  6. Date: 28 Jul 92 20:36:46 GMT
  7. Organization: GTE Laboratories Incorporated, Waltham MA
  8. Lines: 161
  9.  
  10. Hi all,
  11.  
  12. I am new at c++ (and fairly new to c).  I wish to write a program
  13. that reads from standard input and outputs a list of all unique words
  14. from the input, ranked in lexical order, and preceded by a count of the 
  15. number of times the words occurred in the input stream. 
  16.  
  17. Obviously, I am stuck *disappointed that I can't get it*
  18.  
  19. I was wondering if anybody would be available for some
  20. help (tutoring via email), as this is a homework assignment, 
  21. and I need to get it done quickly.
  22.  
  23. I am new on newsnet, so please don't flame me if asking for tutoring
  24. in this manner is not right (I am basically in need of guidance, considering
  25. my limited time to get this done).  Just tell me if I am doing something
  26. wrong and I'll back off.
  27.  
  28. So far, this is what I have done (see following). I must add that I have
  29. plenty of text books, which I have referenced and they don't seem to
  30. clearly explain some basic concepts
  31.  
  32. If there is anyone out there that can assist, please respond, and I will
  33. be indebted to you (perhaps, one day I can return the help).
  34.  
  35. Thank you.
  36.  
  37. don o
  38. **********************
  39.  
  40. #include <string.h>
  41. #include "String.h"
  42. #include <iostream.h>
  43.  
  44.  
  45. class string {                     // class for holding words
  46.         char *p;
  47.         int size;
  48. public:
  49.         string(const char *str);
  50.         string(const string &o);
  51.         ~string();
  52.         print();
  53.         int rank(const string *);
  54.         int rank(const char *);
  55. };
  56.  
  57. string::string(const char *str)       // init using c-like quoted str
  58. {
  59.   size = strlen(str) + 1;    // room for null terminator
  60.   p = new char[size];
  61.   if(!p)  {
  62.     cout << "Allocation error\n";
  63.     exit(1);
  64.   }
  65.   strcpy(p, str);
  66. }
  67.  
  68. string::string(const string &o)      // init using a str object
  69. {
  70.   size = o.size;
  71.   p = new char[size];
  72.   if(!)  {
  73.     cout << "Allocation error\n";
  74.     exit(1);
  75.   }
  76.   strcpy(p, o.p);
  77. }
  78.  
  79. string::~string()
  80. {
  81.   delete p;                // frees memory pt-ed to by p
  82. }
  83.  
  84. void string::print();
  85. {
  86.  
  87. }
  88.  
  89. int string::rank(const string *)  // rank string objects
  90. {
  91.   int operator==(string &o)  {return !strcmp(p, o.p);}
  92.   int operator!=(string &o)  {return strcmp(p, o.p);}
  93.   int operator<(string &o)   {return strcmp(p, o.p);}
  94.   int operator>(string &o)   {return strcmp(p, o.p);}
  95.   int operator<=(string &o)  {return strcmp(p, o.p);}
  96.   int operator>=(string &o)  {return strcmp(p, o.p);}
  97. }
  98.  
  99. int string::rank(const char *)  // rank string objects & quoted strings
  100. {
  101.   int operator==(char *s)  {return !strcmp(p, s);}
  102.   int operator!=(char *s)  {return strcmp(p, s);}
  103.   int operator<(char *s)   {return strcmp(p, s) < 0;}
  104.   int operator>(char *s)   {return strcmp(p, s) > 0;}
  105.   int operator<=(char *s)  {return strcmp(p, s) <= 0;}
  106.   int operator>=(char *s)  {return strcmp(p, s) >=0;}
  107. }
  108.  
  109.  
  110. class string_list {                // class for maintaining list of words
  111.         *p1;
  112.         int size1;
  113. public:
  114.         string_list(string *, string_list *);
  115.         ~string_list();
  116.         insert(const char *);
  117.         get_next();
  118.         print();
  119. };
  120.  
  121. string_list::string_list(string *, string_list *)
  122. {
  123. }
  124.  
  125. string_list::~string_list()
  126. {
  127.   delete p1;
  128. }
  129.  
  130. string_list::insert(const char *)
  131. {
  132. }
  133.  
  134. string_list * string_list::get_next()
  135. {
  136. }
  137.  
  138. void string_list::print();
  139. {
  140. }
  141.  
  142. const BUFSIZE = 256;
  143. string str;
  144.  
  145. main()
  146. {
  147.  
  148.         cout << "\n****************************************************\n";
  149.         cout << "This program reads from standard input and outputs a  \n";
  150.         cout << "list of all unique words in the input, ranked in      \n";
  151.         cout << "lexical order, and preceded by a count of the number  \n";
  152.         cout << "of times the word occurred in the input stream.       \n";
  153.         cout << "****************************************************\n\n";
  154.  
  155.         printf("\nWelcome to the String Program!\n");
  156.  
  157.         char      buf[BUFSIZE];
  158.  
  159.         while(cin >> buf)  {
  160.  
  161.  
  162.  
  163.         }
  164.  
  165.  
  166.         printf("\nEnd of the String Program!\n");
  167.         printf("\n");
  168.  
  169.         return 0;
  170. }
  171.