Write a C++ Program that uses: 1.Strings 2.Passing Strings to functions 3.Files
ID: 3690212 • Letter: W
Question
Write a C++ Program that uses: 1.Strings 2.Passing Strings to functions 3.Files Input and output. Preparatory Reading: Chapter 8 in Problems Solving with C++ Project Requirements: 1.Write a function called removeRepeats that, given a string, removes any repeated letters and returns a new string. 2.Write a main method that reads words (strings) from a file and writes the new strings (with no repeated letters, regardless of case,) to another file. 3.Several options are left for the programmer to determine:Use of either c-string(char arrays) or thestring class. Use of a container (array or vector) to store the strings. You can either store the strings in an array or vector - or just read and write without storage. 4.As you can see, many of the implementation details are left up to the programmer. At this point in the course you should be able to make design decisions based on good programming practices.
Explanation / Answer
Please follow the code to get the desired outputs and can find the description in comments:
// Removing Duplicate Characters.
#include <iostream.h>
#include <conio.h>
#include <string.h>
void removeRepeat(char*);
int main()
{
const int n=50;
char input[n];
cout<< "Enter Your Characters(Max=50):";
cin.get(input,n);
dup_delete(input);
return 0;
}
void removeRepeat(char *input)
{
int i,j,k=0,count=0,z=0;
char output[50];
char dup[50];
for(i=0;i<50;i++){
for(j=i+1;j<50;j++)
if(input[i]==input[j]) count++;
if(count>1)
dup[k]=input[i];
k++;
count=0;
}
for(i=0;i<50;i++){
for(j=0;j<50;j++)
if(input[i]==dup[j]) break;
if(j==50) output[z]=input[i];
z++;
}
cout<< "The Non-Duplicate Characters Is:" << output;
ofstream myfile; // opening a file to write the data
myfile.open ("example.txt"); // name your file as desired
myfile << "Writing this to a file. " << output;
myfile.close(); // closing the file
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.