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 written to outFileName."
int countChar (ifstream &inStream): returns number of character in input file.
int countWord(ifstream &inStream): returns number of words in input file.
int countLines(ifstream &inStream): returns number of lines in input file.
After calling each function, you have to reset the state flags and move the stream pointer to beginning of file. You can do that by closing and re-opening the file, or by calling member functions:
inStream.clear(); inStream.seekg(0);
Example:
Input: input.txt output.txt
Output:
Text with no white space is successfully written to output.txt.
Number of characters is: 154
Number of words is: 36
Number of lines is: 10
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void removeSpace(ifstream &inStream, ofstream
&outStream);
int countChar (ifstream &inStream);
int countWords(ifstream &inStream);
int countLines (ifstream &inStream);
int main()
{
string input, output;
cin >> input >> output;
ifstream inStream(input);
ofstream outStream(output);
if(inStream.fail())
cout << "Input file does not exist.\n" ;
else
{
removeSpace(inStream, outStream);
cout << "Text with no white space is successfully written to
outFileName.\n";
inStream.clear();
inStream.seekg(0, inStream.beg);
cout << "Number of characters is: " <<
countChar(inStream) << endl;
inStream.clear();
inStream.seekg(0, inStream.beg);
cout << "Number of words is: " <<
countWords(inStream) << endl;
inStream.clear();
inStream.seekg(0, inStream.beg);
cout << "Number of lines is: " <<
countLines(inStream) << endl;
inStream.close();
}
outStream.close();
return 0;
}
//define your functions here
/*
Author: ANUNAGA
Date: 19-Sep-2019
*/
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void removeSpace(ifstream &inStream, ofstream &outStream);
int countChar(ifstream &inStream);
int countWords(ifstream &inStream);
int countLines(ifstream &inStream);
int main()
{
string input, output;
cin >> input >> output;
ifstream inStream(input);
ofstream outStream(output);
if (inStream.fail())
cout << "Input file does not exist.\n";
else
{
removeSpace(inStream, outStream);
cout << "Text with no white space is successfully written to "<<output<<".\n";
inStream.clear();
inStream.seekg(0, inStream.beg);
cout << "Number of characters is: " << countChar(inStream) << endl;
inStream.clear();
inStream.seekg(0, inStream.beg);
cout << "Number of words is: " << countWords(inStream) << endl;
inStream.clear();
inStream.seekg(0, inStream.beg);
cout << "Number of lines is: " << countLines(inStream) << endl;
inStream.close();
}
outStream.close();
return 0;
}
//define your functions here
void removeSpace(ifstream &inStream, ofstream &outStream){
char ch;
while(inStream>>ch){
outStream<<ch;
}
}
int countChar(ifstream &inStream){
int count = 0;
string line;
while(!inStream.eof()){
getline(inStream, line);
count += line.size();
}
return count;
}
int countWords(ifstream &inStream){
int count = 0;
string word;
while(!inStream.eof()){
inStream>>word;
count++;
}
return count;
}
int countLines(ifstream &inStream){
int count = 0;
string line;
while(!inStream.eof()){
getline(inStream, line);
count++;
}
return count;
}
Let me know if you have any clarifications. Thank you...
C++ Programming question For this exercise, you will receive two string inputs, which are the names...
C++ problem. hi heys, i am trying to remove beginning and the end whitespace in one file, and output the result to another file. But i am confused about how to remove whitespace. i need to make a function to do it. It should use string, anyone can help me ? here is my code. #include <iostream> #include <iomanip> #include <cstdlib> #include <fstream> using namespace std; void IsFileName(string filename); int main(int argc, char const *argv[]) { string inputfileName = argv[1];...
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;...
In c++ please How do I get my printVector function to actually print the vector out? I was able to fill the vector with the text file of names, but I can't get it to print it out. Please help #include <iostream> #include <string> #include <fstream> #include <algorithm> #include <vector> using namespace std; void openifile(string filename, ifstream &ifile){ ifile.open(filename.c_str(), ios::in); if (!ifile){ cerr<<"Error opening input file " << filename << "... Exiting Program."<<endl; exit(1); } } void...
In
c++ programming, can you please edit this program to meet these
requirements:
The program that needs editing:
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int cal_avg(char* filenumbers, int n){
int a = 0;
int number[100];
ifstream filein(filenumbers);
if (!filein) {
cout << "Please enter a a correct file to read in the
numbers from";
}
while (!filein.eof()) {
filein >> number[a];
a++;
}
int total = number[0];
for (a = 0; a < n; a++) {...
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...
Hi! 1. I need some help with sorting string in a text file. My goal is to 1 shift left strings for string.length time. I was able to do that successfully. However, I am also trying to sort, using insertion sort , the resulting shifts. I store all shifts in a vector (or is it better to use an array?!) , and try to sort them that way, but my output is just the shifted strings but not sorted. Can...
//I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which manipulates text from an input file using the string library. Your program will accept command line arguments for the input and output file names as well as a list of blacklisted words. There are two major features in this programming: 1. Given an input file with text and a list of words, find and replace every use of these blacklisted words with the string...
C++ Can someone please help me with this problem- commenting each line of code so I can understand how to solve this problem using the C++ programming language? I really need help understanding how to create a file for the program to read. Do I create the file in Visual basic or create a text file? I have the code, just need to know how to create the file for it to read. #include<fstream> #include<iostream> using namespace std; int main()...
Please add a detailed comment for this program. #include<iostream> #include<string> #include<fstream> #include<sstream> #include<cctype> using namespace std; int is_palindrome(string word){ int len = word.size(); for(int i=0; i<len/2; i++){ if(toupper(word[i])!=toupper(word[len-i-1])) return 0; } return 1; } int have_vowels3(string word){ int cnt = 0; for(int i=0; i<word.size(); i++){ if(tolower(word[i])=='a' || tolower(word[i])=='e' || tolower(word[i])=='i' || tolower(word[i]) =='o' || tolower(word[i]) == 'u') cnt++; } if(cnt>=3) return 1; else return 0; } int have_consecutives(string word){ for(int i=0; i<word.size()-1; i++){ if(tolower(word[i])=='o' && tolower(word[i+1]=='o')) return 1; } return...
The following is a sample inventory in C++, i want to ask the user to input a item number for removing from inventory. //CPP #include <iostream> #include <fstream> #include <cstdlib> #include <iomanip> #define MAX 1000 using namespace std; //Function to Add a new inventory item to the data into the array in memory void addItem(string desc[],string idNum[], float prices[], int qty[],int &num) { cout<<"Enter the names:"; cin>>desc[num]; cout<<"Enter the item number:"; cin>>idNum[num]; cout<<"Enter the price of item:"; cin>>prices[num]; cout<<"Enter the...