This is what I sent and recieved from an expert to day. I have attached a screenshot because there is an error on 64 under the word sort(a red squiggly line). If possible can the error be fixed please. I am using Visual Studio 2019, C++ console for Windows 10 and I am unable to run the program. Below is all correspondence from earlier. I had to delete the cod

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

This is what I sent and recieved from an expert to day. I have attached a screenshot because there is an error on 64 under the word sort(a red squiggly line). If possible can the error be fixed please. I am using Visual Studio 2019, C++ console for Windows 10 and I am unable to run the program. Below is all correspondence from earlier.  

I had to delete the code I sent and a copy of the 1st code sent by expert due to upload word count

 

Please rewrite this program without the unnecessary vector.

1) The program below declares the following vectors,

vector<string> all_words;
vector<int> all_word_counts;
vector<vector<int>> all_line_numbers;

One of the vectors is unnecessary.

2) Sort the 2 or 3 parallel vectors in ascending order of all_words vector.

check_circle

Expert Answer

thumb_up
 
thumb_down
Given Information

Need to remove unnecessary vector from the code which is not used.

And also need to sort the 2 03 3 parallel vectors which has been used in the code. 

Using Sort on 2nd Vector

As 3rd vector is removed 2nd vector is left to be sorted, so revised code along with sorted values of all_words_counts.

#include <cassert>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

const string empty_string = "";
vector<string> getWords(const string& text);
int findWord(const vector<string>& words, const string& word);
int main()
{
    vector<string> all_words;
    vector<int> all_word_counts;
    //vector<vector<int>> all_line_numbers;
    string input_file_name;
    cout << "Source file name? ";
    getline(cin, input_file_name);
    ifstream finp;
    finp.open(input_file_name);
    assert(finp.good());
    string line;
    int word_counter = 0;
    int max_word_length = 0;
    int max_word_count = 0;
    int line_number = 0;
    getline(finp, line);
    while (!finp.eof())
    {
        line_number++;
        vector<string> words = getWords(line);
        word_counter += words.size();
        for (int idx = 0; idx < words.size(); ++idx)
        {
            int widx = findWord(all_words, words[idx]);
            if (widx == -1)
            {
                cout << words[idx] << endl;
                all_words.push_back(words[idx]);
                all_word_counts.push_back(1);
                vector<int> word_line_numbers;
                word_line_numbers.push_back(line_number);
              // all_line_numbers.push_back(word_line_numbers);
                if (words[idx].length() > max_word_length)
                   max_word_length = words[idx].length();

            }
            else
            {
                all_word_counts[widx]++;
              // all_line_numbers[widx].push_back(line_number);
                if (all_word_counts[widx] > max_word_count)
                    max_word_count = all_word_counts[widx];
            }
        }
        getline(finp, line);
    }
 sort(all_word_counts.begin(),all_word_counts.end());
    finp.close();
    string output_file_name = input_file_name;
    string time_as_string = to_string(static_cast<int>(time(nullptr)));
    int period_pos = input_file_name.find_last_of('.');
    if (period_pos == -1)
        output_file_name = output_file_name + time_as_string + ".txt";
    else
        output_file_name = output_file_name.replace(period_pos, output_file_name.length() - period_pos + 1, time_as_string + ".txt");
    ofstream fout;
    fout.open(output_file_name);
    assert(fout.good());
   
    cout << word_counter << endl;
    const int word_counts_fwidth = static_cast<int>(log10(max_word_count)) + 1;
    const int line_number_fwidth = static_cast<int>(log10(line_number)) + 1;
    const int words_per_line = 36;
    //using new variable for reference
 int newindex = 0;
    for (int idx = 0; idx < all_words.size(); ++idx)
    {
        fout << setw(max_word_length) << left << all_words[idx] << ' ' << right << setw(word_counts_fwidth) << right << all_word_counts[idx] << endl;
        //for (int idx2 = 0; idx2 < all_line_numbers[idx].size(); ++idx2)

  for (int idx2 = 0; idx2 < all_word_counts[idx]; ++idx2)
        {
            if (idx2 != 0 && idx2 % words_per_line == 0)
                fout << endl;
            fout << setw(line_number_fwidth) << right << ++newindex << ' ';
        }
        fout << endl;
        fout << endl;
    }
    fout.close();
    system("pause");
    return 0;
}
int findWord(const vector<string>& words, const string& word)
{
    for (int idx = 0; idx < words.size(); ++idx)
        if (words[idx] == word)
            return idx;
    return -1;
}
vector<string> getWords(const string& text)
{
    vector<string> words;
    int start_pos = 0;
    while (start_pos < text.length())
    {
        while (start_pos < text.length() && !isalnum(text[start_pos]))
            start_pos++;
        string word = empty_string;
        while (start_pos < text.length() && (isalnum(text[start_pos])))
        {
            word += static_cast<char>(toupper(text[start_pos]));
            start_pos++;
        }
        if (word.length() > 0)
            words.push_back(word);
    }
    return words;

}

Homework12Problem
(Global Scepe)
46
all_word_counts.push_back(1);
vectorcint> word_line_numbers;
word_line_numbers.push_back(line_number);
// all_line_numbers.push_back(word_line_numbers);
if (words[idx].length() > nax_word_length)
nax_word_length - words(idx].length();
47
48
49
50
51
52
53
54
else
55
all_word_counts[widx]++;
I/ all_line_numbers[widx].push_back(line_number);
if (all_word_counts[widx] > nax_word_count)
max_word_count - all_word_counts[widx];
56
57
58
59
60
61
62
getline(fing, line);
63
soct (all_word_counts.begin(), all_word_counts.end());
finp.close();
string output_file_name - input_file_name;
string time_as_string - to_string(static_castcint>(tine(nullptr)));
int period_pos - input_file_name.find_last_of(".');
if (period pos -1)
output_file_name - output_file_nane + tine as string + ".txt";
else
64
65
66
67
68
69
70
71
output_file_name - cutput_file_nane.replace(period_pos, output_file_name.length() - period_pos + 1, time_as_string + ".txt");
72
ofstrean fout;
fout.open(output_file_nane);
assert(fout.good());
73
74
75
76
77
cout « word_counter « endl;
const int word counts_fuidth - static_castcint>(log18(max_word_count)) + 1;
const int line_number_fuidth - static_castcint>(log1e(line_number)) + 1;
const int words per_line - 36;
78
79
80
100%
11
Ln: 3 Ch 1 SPC CRLF
am Explorer
olbox
Transcribed Image Text:Homework12Problem (Global Scepe) 46 all_word_counts.push_back(1); vectorcint> word_line_numbers; word_line_numbers.push_back(line_number); // all_line_numbers.push_back(word_line_numbers); if (words[idx].length() > nax_word_length) nax_word_length - words(idx].length(); 47 48 49 50 51 52 53 54 else 55 all_word_counts[widx]++; I/ all_line_numbers[widx].push_back(line_number); if (all_word_counts[widx] > nax_word_count) max_word_count - all_word_counts[widx]; 56 57 58 59 60 61 62 getline(fing, line); 63 soct (all_word_counts.begin(), all_word_counts.end()); finp.close(); string output_file_name - input_file_name; string time_as_string - to_string(static_castcint>(tine(nullptr))); int period_pos - input_file_name.find_last_of(".'); if (period pos -1) output_file_name - output_file_nane + tine as string + ".txt"; else 64 65 66 67 68 69 70 71 output_file_name - cutput_file_nane.replace(period_pos, output_file_name.length() - period_pos + 1, time_as_string + ".txt"); 72 ofstrean fout; fout.open(output_file_nane); assert(fout.good()); 73 74 75 76 77 cout « word_counter « endl; const int word counts_fuidth - static_castcint>(log18(max_word_count)) + 1; const int line_number_fuidth - static_castcint>(log1e(line_number)) + 1; const int words per_line - 36; 78 79 80 100% 11 Ln: 3 Ch 1 SPC CRLF am Explorer olbox
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Graphical User Interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education