Need it done in C++ and no pointers!!! please can somebody do this this the Data
ID: 644717 • Letter: N
Question
Need it done in C++ and no pointers!!!
please can somebody do this
this the Data File:
magic
spell
owl
destine
fatal
pure
dragon
phoenix
special
school
uncle
friendship
teacher
master
question
eagle
guess
human
develope
clue
blog
difficult
simulate
tiger
ratio
performance
width
care
game
dictionary
picture
choose
look
soft
assumption
eat
apple
problem
shaby
spider
map
english
romantic
music
moon
watermelon
definition
remote
freedom
similar
writer
search
inside
poodle
constraint
state
quality
slave
action
condition
google
description
cooking
handbook
research
cousin
sister
example
block
blossom
cheer
dog
cat
friend
candy
church
perfect
genre
movie
surf
club
golf
swim
country
book
best
student
teacher
computer
calculate
algorithm
photo
facebook
foundation
money
building
stone
story
store
support
grief
captain
After your program reads in the list of words, it randomly picks one word to play the game. This word is
referred to as the
Explanation / Answer
#include
#include
#include
#include
#include
#include
using namespace std;
string rand_select_elems(string a[], int len)
{
srand((unsigned)time(NULL));
static int l = 0;
int n = rand() % (len - l);
int m = l + n;
string t = a[l];
a[l] = a[m];
a[m] = t;
t = a[l];
l ++;
l %= len;
return a[n];
}
void display(const char *c,int len)
{
for ( int i(0); i != len; ++i )
{
if(i==0 || i==len-1)
cout< else
cout<<"_" ;
}
}
int compare(const char *c,char a,int len)
{
int pos;
for(int i=0;i!=len;++i)
{
if(c[i]==a)
pos=i;
}
return pos;
}
int main ()
{
char *cpFileName = "Data.txt";
string saFileText [105];
// Append the text " DONE" to the file.
ofstream oFile (cpFileName, ios_base::app);
oFile << " DONE";
oFile.close ();
// Get input
ifstream iFile (cpFileName);
for (int i = 0;; ++i)
{
getline (iFile, saFileText [i]);
if (saFileText [i] == "DONE") break;
}
iFile.close ();
// Print the results
for (int i = 0; saFileText [i] != "DONE"; ++i)
{
cout << "Line #" << i << " : " << saFileText [i] << endl;
}
string s=rand_select_elems(saFileText,103);
const char* c=s.c_str();
display(c,s.length());
char a;
cout<<"Enter the letter"< cin>>a;
int p;
p=compare(c,a,s.length());
cout<
cin.get();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.