Extend the program so that if run with the u option (specified by the command-line argument -u), it displays the number of unique words. To count unique words, use the STL vector class to keep track of which words you've already seen. When each word is read, check to see if it's already in the vector; if it's not, insert it. The number of unique words will then be the size of the vector.
here is the main but i stuck on exapanding it to pass the level.
#include #include #include #include #include #include #include
using namespace std;
/* * */ int main(int argc, char** argv) { Vector vec_unique; enum { total, unique } mode = total; for (int c; (c = getopt(argc, argv, "tu"))!= -1;) { switch (c) { case 't': mode = total; break; case 'u' : mode = unique; break; } } argv -= optind; argv += optind; std:: string word; int count = 0; while (std::cin>>word) { count +=1; } switch (mode) {case total: std::cout Your task is to write a program, words, that reports information about the number of words read from its standard input. For example, if the file qbf.txt contains the text the quick brown fox jumps over the lazy dog then running the program with is input redirected to come from that file will report 9 words $ wordsqbf.txt Total 9 picture Automatic Testing This task is available for automatic testing using the name words. You can run the demo using demo words and you can test your work using try words > Background Use the following skeleton for the program: int main (int argc , char** argv) l enum total, unique modetotal; for (int c (c - getopt (argc, argv, "tu")) !-1:) switch (c) case 't': mode total; break case 'u': mode = unique ; break ; argc-= optind; argv +- optind,; string word; int count 0; while (cin >> word) i count 1; switch (mode) case total: cout ) provides a standard way of handling option values in command-line arguments to programs. It analyses the command-line parameters argc and argv, looking for arguments that begin with'-'. It then examines all such arguments for specified option letters, returning individual letters on successive calls and adjusting the variable optind to indicate which arguments it has processed. Consult getopt documentation for details. In this case, the option processing code is used to optionally modify a variable that determines what output the program should produce. By default, mode is set to total (indicating that it should display the total number of words read). The getopt code looks for the t and u options (which would be specified on the command line as -t or -u) and overwrites the mode variable accordingly. When there are no more options (indicated by getopt returning -1), argc and argv are adjusted to remove the option arguments that getopt has processed