Background The following skeleton code for the program is provided in words.cpp, which will be located inside your worki

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Background The following skeleton code for the program is provided in words.cpp, which will be located inside your worki

Post by answerhappygod »

Background
The following skeleton code for the program is provided in
words.cpp, which will be located inside your working
copy
directory following the check out process described
above.
int main(int argc, char** argv)
{
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;
}
}
argc -= optind;
argv += optind;
string word;
int count = 0;
while (cin >> word) {
count += 1;
}
switch (mode) {
case total:
2
cout << "Total: " << count << endl;
break;
case unique:
cout << "Unique: " << "** missing **" <<
endl;
break;
}
return 0;
}
The getopt function (#include <unistd.h>) 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.
would you able get me the code for this
question
Make sure that your program works correctly (and efficiently)
even if it is run with large data sets. Since you do not
know how large the collection of words might become, you will need
to make your vector grow dynamically. A suitable
strategy is to allocate space for a small number of items initially
and then check at each insert whether or not there is
still enough space. When the space runs out, allocate a new block
that is twice as large, copy all of the old values into
the new space, and delete the old block.
You can test large text input by copying and pasting form a test
file or alternatively using file redirection if you are on a
Unix-based machine (Linux or macOS). The latter can be achieved by
running the program from the command line and
redirecting the contents of your test file as follows:
./words < test.txt
Total: 1234
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply