home study engineering computer science questions and an
home / study / engineering / computer science / questions and answers / write a program to take an input file of normal ...
Question: Write a program to take an input file of normal en...
Bookmark
I need this in C++ Programming. Thanks!!!
Solution
Here is the code for you:
#include <iostream>
#include <cstdlib>
#include <fstream>
using namespace std;
string jumbleWord(string word)
{
int count = rand() % 5 ;
if(word.length() > 3)
for(int i = 0; i < count; i++)
{
int one = (rand() % (word.length()-1)) + 1;
int two = (rand() % (word.length()-1)) + 1;
char temp = word.at(one);
word.at(one) = word.at(two);
word.at(two) = temp;
}
return word;
}
int main()
{
ifstream fin;
ofstream fout;
string fileName, word;
cout<<\"Enter the name of the input file: \";
cin>>fileName;
fin.open(fileName);
cout<<\"Enter the name of the output file: \";
cin>>fileName;
fout.open(fileName);
while(!fin.eof())
{
fin>>word;
fout<<jumbleWord(word)<<\" \";
}
fin.close();
fout.close();
}
