c++
Assume the following functions have already been defined, write a main() to read the words of file "in.txt", the illegal words in "illegal.txt", and after removing the words that are illegal, output the remaining words to the file "clean.txt" vector<string> readFile(ifstream & inFile); // return words of file in vector vector<string> readIllegal(ifstream &illegalFile); // return vector of illegal words void writeCensored(ofstream & outFile, vector<string> words); // writes vector into file
#include <iostream>
#include <vector>
#include <fstream>
#include <string>
using namespace std;
vector<string> readFile(ifstream &inFile);
vector<string> readIllegal(ifstream &illegalFile);
void writeCensored(ofstream &outFile, vector<string> words);
// This main function is the answer
int main() {
ifstream in1("in.txt");
ifstream in2("illegal.txt");
ofstream out("clean.txt");
vector<string> words = readFile(in1);
vector<string> illegalWords = readIllegal(in2);
vector<string> result;
for (int i = 0; i < words.size(); i++) {
bool found = false;
for (int j = 0; j < illegalWords.size(); j++) {
if (words[i] == illegalWords[j]) {
found = true;
}
}
if (!found) {
result.push_back(words[i]);
}
}
writeCensored(out, result);
in1.close();
in2.close();
out.close();
return 0;
}
// I've written the function definitions as well if you are interested in what it looks like.
vector<string> readFile(ifstream &inFile) {
vector<string> s;
string word;
while (inFile >> word) {
s.push_back(word);
}
return s;
}
vector<string> readIllegal(ifstream &illegalFile) {
return readFile(illegalFile);
}
void writeCensored(ofstream &outFile, vector<string> words) {
for (int i = 0; i < words.size(); ++i) {
outFile << words[i] << endl;
}
}
c++ Assume the following functions have already been defined, write a main() to read the words...
I need to make a few changes to this C++ program,first of all it should read the file from the computer without asking the user for the name of it.The name of the file is MichaelJordan.dat, second of all it should print ,3 highest frequencies are: 3 words that occure the most.everything else is good. #include <iostream> #include <map> #include <string> #include <cctype> #include <fstream> #include <iomanip> using namespace std; void addWord(map<std::string,int> &words,string s); void readFile(string infile,map<std::string,int> &words); void display(map<std::string,int>...
I need help debugging this C++ prgram. What Am i doing wrong? //******************************************************** // This program reads two input files whose lines are //ordered by a key data field. This program should merge //these two files, writing an output file that contains //all lines from both files ordered by the same key field. // //********************************************************* #include <iostream> #include<string> #include<fstream> //prototype void mergeTwoFiles (ifstream&,ifstream&, ofstream&); using namespace std; int main() {string inFile1,inFile2,outFile; // input and output files ifstream in1; ifstream in2;...
I need to add something to this C++ program.Additionally I want it to remove 10 words from the printing list (Ancient,Europe,Asia,America,North,South,West ,East,Arctica,Greenland) #include <iostream> #include <map> #include <string> #include <cctype> #include <fstream> #include <iomanip> using namespace std; void addWord(map<std::string,int> &words,string s); void readFile(string infile,map<std::string,int> &words); void display(map<std::string,int> words); int main() { // Declaring variables std::map<std::string,int> words; //defines an input stream for the data file ifstream dataIn; string infile; cout<<"Please enter a File Name :"; cin>>infile; readFile(infile,words);...
For this assignment, you are to write a program that does the following: read temperatures from a file name data.txt into an array, and after reading all the temperatures, output the following to the monitor: the average temperature, the minimum temperature, and the total number of temperatures read. In addition, the program must use the following functions: //precondition: fileName is name of the file to open, inFile is the input file //postcondition: inFile is opened. If inFile cannot...
C++ Programming question For this exercise, you will receive two string inputs, which are the names of the text files. You need to check if the input file exists. If input file doesn't exist, print out "Input file does not exist." You are required to create 4 functions: void removeSpace (ifstream &inStream, ofstream &outStream): removes white space from a text file and write to a new file. If write is successful, print out "Text with no white space is successfully...
Python 3.6
Question 12 (2θ points) write a function named uniqueWords that counts how many different words there are in each line of an input file and writes that count to a corresponding line of an output file. The input file already exists when uniqueWords is called. uniquewords creates the output file. Input. The function uniquewords takes two parameters: ◆ inFile, a string that is the name of text file that is to be read. The file that inFile refers...
Write the functions needed to complete the following program as described in the comments. Use the input file course.txt and change the mark of student number 54812 to 80. /* File: course.cpp A student's mark in a certain course is stored as a structure (struct student as defined below) consisting of first and last name, student id and mark in the course. The functions read() and write() are defined for the structure student. Information about a course is stored as a...
For this assignment, you are to write a program that does the following: (C++) • read exam scores from a file name data.txt into an array, and • after reading all the scores, output the following to the monitor: the average score and the total number of scores. In addition, the program must use the following functions: //precondition: fileName is name of the file to open, inFile is the input file 2 of 2 //postcondition: inFile is opened. If inFile...
Can someone help me put the string removee the return to an outfile and fix?? prompt: CS 575 LabEx14: no e’s Let the user specify an input file and an output file (text files). Read the input file and write the output file; the output file should be the same as the input file, except that it has no e’s. For example, if the input file had the line. Streets meet in the deep. Then the output file would have...
Please help the out keeps printing twice
#include
#include
#include
#include
#include
using namespace std;
/**
* Function to calculate the future value and return the same
*/
double calculateFutureValue(double presentValue, double
interestRate, int months)
{
double futureValue = (double)presentValue * pow((1 +
interestRate), months);
return futureValue;
}
/**
* Function to read the input file and assign the value to the
variables
*/
unsigned int readfile(ifstream &inF, double &presentValue,
double &interestRate, int &months)
{
inF >>...