Write a C++ program that reads in input until the EOF.
The program should output the input exactly...with the following changes:
Anytime the substring "New York University", "American", or "Lady gaga" appears in the text, it should be replaced with 5 asterisks "*****".
Example:
Input:
New York University safmsa qwqoca
safffja qwrq ssss 23333
af21jspof American shfafh121 Lady gaga spdj1-
(Note that this is a paragraph with ONE line in the middle)
Output:
***** safmsa qwqoca
safffja qwrq ssss 23333
af21jspof ***** shfafh121 ***** spdj1-
below is the detailed explanation I hope you will understand it properly
I am reading data from the data file
#include<bits/stdc++.h>
using namespace std;
int main(){
ifstream file; //input stream
file.open("data");//opening a file
string s;
string str = "";
while(file>>s){ //reading data and writing it to s
str+=s+" "; //storing s to str
}
//it's our actual string
cout<<"print the actual string\n";
cout<<str<<"\n\n";
//Lets first check for New York University
//and its count is 19
string str1 = "New York University";// first substring
size_t index = str.find(str1); //finding the first index of
str1(New York University)
while(index != string::npos){ // if index is not equal to the end
of the str then we have found the substring
string temp = str.substr(0,index); //storing values from 0 to the
first index
string x = "*****"; //adding 5 starts to the x
temp+=x; //adding it to the temp which is a temporary
variable
int start = index+str1.size(); // now we need to skip str1 or(New
York University) from our actual string becuase we have replaced it
with 5 starts
// New York University starting index
int end = str.size()-start; //New York University
ending index so we skiped this string from start to end
temp+=str.substr(start,end); //now adding rest of the string to
temp which we need
str = "";
str = temp; // now assigning temp to str
index = str.find(str1); // finding the index again if any
exist
}
// printing our string without str1
cout<<"after removing New York University \n";
cout<<str<<"\n\n";
//same is the case for ther substring so i am not writing comments
for them i hope you understands
//
.......................////////////////////////////////////////////////..................
//now check for "American"
str1 = "American";
index = str.find(str1);
while(index != string::npos){
//string ::npos it return the maximum possible value that can be
stored in size_t if the substring is not find it is beeter way to
check
string temp = str.substr(0,index);
string x = "*****";
temp+=x;
int start = index+str1.size();
int end = str.size()-start;
temp+=str.substr(start,end);
str = "";
str = temp;
index = str.find(str1);
}
cout<<"after removing American"<<endl;
cout<<str<<"\n\n";
//
.....................................///////////////////////////////////////////////.....................
//now check for Lady gaga
str1 = "Lady gaga";
index = str.find(str1);
while(index != string::npos){
string temp = str.substr(0,index);
string x = "*****";
temp+=x;
int start = index+str1.size();
int end = str.size()-start;
temp+=str.substr(start,end);
str = "";
str = temp;
index = str.find(str1);
}
cout<<"after removing Lady gaga"<<endl;
cout<<str<<endl;
}
output file
Write a C++ program that reads in input until the EOF. The program should output the...
c program that counts the number of characters, words and lines from standard input until EOF. attached is what i Have so far but its not working ?. about shell redirection Requirements 1. Write a C program that counts the number of characters, words and lines read from standard Input until EOF Is reached. 2. Assume the Input is ASCII text of any length. 3. Every byte read from stdin counts as a character except EOF 4. Words are defined...
Write a C++ program that repeatedly reads lines until an EOF is encountered. As each line is read, the program strips out all characters that are not upper or lower case letters or spaces, and then outputs the line. Thus, the program acts as a filter and issues no prompt. There are many ways this program could be written, but to receive full credit, you must observe the following: Place your code in a file called filterChars.cpp. The program should...
Please do it with C++. Thanks:) Write a program that reads a string and a character from the keyboard. The program should output how many times the character appears in the string. Make the program run in a loop until the string finish is input. Sample run: Input a string: alicia Input a letter: a The letter appears 2 times Input a string: felix Input a letter: x The letter appears 1 time Input a string: finish Good Bye.
I/O program for C Write a program in direct1.c which reads from standard input a line and then outputs that line immediately to standard output. it should read the first line only ! Then, write another program called direct2.c which reads from standard input every line until end of input and outputs them to standard output. Everything that goes in should come out exactly as it was. Compile both programs and run them on the input files given below The...
write a short c++ program that reads integers from a file named zzin1.dat (5,7,21,2,-9,10,3,1,11) until the eof condition is reached add 1 to each value and save it to an output file named acdc1.dat
C++ (1) Write a program to prompt the user for an input and output file name. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs. For example, (user input shown in caps in first line, and in second case, trying to write to a folder which you may not have write authority in) Enter input filename: DOESNOTEXIST.T Error opening input file: DOESNOTEXIST.T...
Write a C program named space_to_line.c that features a while loop that continuously reads input from the user one character at a time and then prints that character out. The exception is that if the user inputs a space character (‘ ‘), then a newline character (‘\n’) should be printed instead. This will format the output such that every word the user inputs is on its own line. Other than changing the spaces to newlines, the output should exactly match...
Write a C++ program that reads in a text file andwrites the histogram of character counts sorted inalphabetical order to an output file. Eg, if theinput file is “to be or not to be”, then the outputshould be:b **2e **2n *1o ****4r *1t ***3
Write a C program that counts the number of each digit entered by the user (Input process should be ended using EOF character). You should use switch to compute the number of each digits. For each digit your program should print a line containing that number of adjacent asterisks. Sample Input1: 18218342850056D855599 Sample Outputi: 0** 3° 5*** 6° 7 g*** Sample Input: 77777445521056 Sample Output2: 0* 1 2° 3 45 S. 6° 8 9 Sample Output 3: Sample Input3: 782222231567799988001332092555...
Write a program that first reads in the name of an input file and then reads the file using the csv.reader() method. The file contains a list of words separated by commas. Your program should output the words and their frequencies (the number of times each word appears in the file) without any duplicates. Ex: If the input is: inputl.csv and the contents of input1.csv are: hello, cat, man, hey, dog, boy, Hello, man, cat, woman, dog, Cat, hey, boy the output is: hello 1 cat 2 man...