Design a program that prompts the user for a word and then prompts the user for
ID: 3767087 • Letter: D
Question
Design a program that prompts the user for a word and then prompts the user for a letter. Your program should count the number of times the letter entered appears in the word and then continue prompting for a new letter until an option to stop is entered. The program should list tthe letters found. HINT:Declare a Boolean array of size 26 to track whether a letter has been found.
You must use at least 2 functions and you must pass at least one array in each of the 2 functions (you may have more functions and not pass it or pass them if you like).
Explanation / Answer
#include<iostream.h>
#include<conio.h>
#include<string.h>
class aa
{
public:
char str[20];
char c;
void fill(char s[], char c1)
{
strcpy(str,s);
c=c1;
}
void search(char s[], char c1)
{
int i;
for(i=0;i<20;i++)
{
if(s[i]==c1)
cout<<"Character found at "<<i;
}
}
};
void main()
{
aa o;
char c[20],s,ans='y';
while(ans=='y')
{
cout<<"Enter String ";
cin>>c;
cout<<"Enter character to search";
cin>>s;
o.fill(c,s);
o.search(c,s);
cout<<"Continue[y/n]";
cin>>ans;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.