Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// Starter file for Question 1 or HW7, due Wed 2/26 before class // [---------] // TODO: Include your hypothesis and analysis here //vector 1:

image text in transcribed

// Starter file for Question 1 or HW7, due Wed 2/26 before class // [---------] // TODO: Include your hypothesis and analysis here //vector 1: put non duplicates in vector sort it then output into file //vector 2: //vector 3: #include #include #include #include #include #include #include using namespace std; using namespace std::chrono; // for timing experiments

const int EXPERIMENT = 1; // change this as you test your algorithms (1-3) const string INFILE = "quickbrownfox.txt"; //"don_quixote.txt"; // test with DQ const string OUTFILE = "output.txt"; // don't change this!

void timedExperiment(string filename, int exp); void readWithVector1(string filename); void readWithVector2(string filename); void readWithSet(string filname);

// starts a timed experiment based on default values or command line arguments int main(int argc, char** argv) { if (argc

// runs specified experiment on the specified filename and reports the time void timedExperiment(string filename, int exp) { auto start = high_resolution_clock::now(); switch (exp) { case 1: readWithVector1(filename); break; case 2: readWithVector2(filename); break; case 3: readWithSet(filename); break; default: cout (stop - start); cout

// TODO: implement these experiments!

void readWithVector1(string filename) { vector v1; vector::iterator it; string temp; ifstream in_one; in_one.open(filename); if (in_one.fail()) { cout >temp) { for (it = v1.begin(); it != v1.end(); it++) { v1.push_back(temp); } } in_one.close();

ofstream out_one; out_one.open(OUTFILE); for (auto e : v1) { out_one

void readWithSet(string filename) { } ___________________________________________________________________________________________________________________________________

This is what I currently have. I need some help understanding how to read files into vectors. erase the duplicates and sort it. The file can be any arbitrary txt file.

vector one is more than enough with a good commentary description of what is going on in the code.

Overview. This week's task is to write two programs using the vector, set, and map classes in the C++ Standard Template Library. The first program will compare the use of vector vs set in processing a large text file. For the second program, you will read the contents of a data file into a map that you will use to design a console-based UI to allow a user to query a password-protected database. Submission instructions. Upload your completed implementations of the two starter files-hw7qi.cpp and hw7q2.cpp - keeping the original filenames as usual. You should not have to add any include directives to the starter files, since Q1 should only use vectors and sets and Q2 should only use a map. Question 1 specifics. Design and analyze three algorithms for the same task: read the words in a file into a data structure, and output the alphabetized words line-by-line to a separate file without any duplicates. Implement the three algorithms described below in the stub functions provided for you in the starter code, and give your analysis in the header comment section of your program. Analyze (5 points): Scan the algorithm descriptions below, and before you start your implementa- tion, hypothesize which algorithmic approach will be fastest to run and fastest to code. Test for correctness on the small test file "quickbrownfox.txt" (you can compare against the pro- vided "output.txt" file), and then record the results of your timed experiments on the large "don quixote.txt" novel. How did the development process and empirical results compare with your expectations? Include a discussion in comments at the top of your Q1 file about runtime and ease-of-development considerations. Algorithm 1 (10 points): Implement readWithvectorl to populate a vector word-by-word as you read the text file. Before you insert a word into the vector, check to make sure that it is not already in the vector. Then sort the vector using the sort function we used in class, and finally iterate through the contents of the vector, outputting them to the output file line-by-line. Algorithm 2 (10 points): Implement readWithVector2 to populate a vector word-by-word as you read the text file. Put each word (even duplicates) into the vector as you read it. Then sort the vector using the sort function we used in class, and finally iterate through the contents of the vector, outputting them to the output file line-by-line. Now since the vector contains duplicates, you will have to ensure that you only output one copy of each word in the vector. Algorithm 3 (10 points): Implement readWithSet to populate a set word-by-word as you read the text file. Then iterate through the contents of the set, outputting them to the file line-by-line. Overview. This week's task is to write two programs using the vector, set, and map classes in the C++ Standard Template Library. The first program will compare the use of vector vs set in processing a large text file. For the second program, you will read the contents of a data file into a map that you will use to design a console-based UI to allow a user to query a password-protected database. Submission instructions. Upload your completed implementations of the two starter files-hw7qi.cpp and hw7q2.cpp - keeping the original filenames as usual. You should not have to add any include directives to the starter files, since Q1 should only use vectors and sets and Q2 should only use a map. Question 1 specifics. Design and analyze three algorithms for the same task: read the words in a file into a data structure, and output the alphabetized words line-by-line to a separate file without any duplicates. Implement the three algorithms described below in the stub functions provided for you in the starter code, and give your analysis in the header comment section of your program. Analyze (5 points): Scan the algorithm descriptions below, and before you start your implementa- tion, hypothesize which algorithmic approach will be fastest to run and fastest to code. Test for correctness on the small test file "quickbrownfox.txt" (you can compare against the pro- vided "output.txt" file), and then record the results of your timed experiments on the large "don quixote.txt" novel. How did the development process and empirical results compare with your expectations? Include a discussion in comments at the top of your Q1 file about runtime and ease-of-development considerations. Algorithm 1 (10 points): Implement readWithvectorl to populate a vector word-by-word as you read the text file. Before you insert a word into the vector, check to make sure that it is not already in the vector. Then sort the vector using the sort function we used in class, and finally iterate through the contents of the vector, outputting them to the output file line-by-line. Algorithm 2 (10 points): Implement readWithVector2 to populate a vector word-by-word as you read the text file. Put each word (even duplicates) into the vector as you read it. Then sort the vector using the sort function we used in class, and finally iterate through the contents of the vector, outputting them to the output file line-by-line. Now since the vector contains duplicates, you will have to ensure that you only output one copy of each word in the vector. Algorithm 3 (10 points): Implement readWithSet to populate a set word-by-word as you read the text file. Then iterate through the contents of the set, outputting them to the file line-by-line

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Database Programming With Visual C# .NET

Authors: Ying Bai

1st Edition

0470467274, 978-0470467275

Students also viewed these Databases questions