Question

Write a functionthat calculates the first character in a string that exists more than twice in...

Write a functionthat calculates the first character in a string that exists more than twice in the stringand returns the index of that character or -1 if none exists.The program should prompt the user to enter an entire line including any whitespace as a string. The program then prints out the index and character that exists at least three times or a message “Not found” if all characters of the string have none or single duplicates.

In C++ please

For example:“Cheesy Feet”àe at index 2

“How are you? àNot found!

“It’sa great day.” àa at index 5

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include<string>
using namespace std;
void find(string c){
int flag=1;
for(int i=0;i<c.length();i++){
int count=0;
for(int j=0;j<c.length();j++){
if(c[i]==c[j])
count++;
}
if(count>=3){
cout<<c[i]<<" at index "<<i<<endl;
flag=0;
break;
}
  
}
if(flag)
cout<<"Not found\n";
}
int main()
{
char ch='y';
string arr;
while(ch=='y'||ch=='Y'){
cout<<"Enter name";
getline (cin, arr);
find(arr);
cout<<"do you want to continue press 'y'";
cin>>ch;
getline (cin, arr);
}
return 0;
}

Add a comment
Know the answer?
Add Answer to:
Write a functionthat calculates the first character in a string that exists more than twice in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a Java program which takes a string as a user input. Create 2 functions. The...

    Write a Java program which takes a string as a user input. Create 2 functions. The first function expects a string as argument and returns void. It converts all upper case characters to lower case and converts all lower case characters to upper case. It then prints out the converted string to a console. The second function also expects a string as argument and returns void. It will find first charactor that is repeated exactly 2 times in the string....

  • In the first task, you will write a Java program that accepts a string of the...

    In the first task, you will write a Java program that accepts a string of the format specified next and calculate the answer based on the user input. The input string should be of the format dddxxdddxx*, where d represents a digit and x represents any character and asterisk at the end represents that the string can have any number of characters at the end. 1. Prompt the user to enter a string with the specific format (dddxxdddxx*) 2. Read...

  • Python 3: Write a function CharCount, to take a string S and a single character C,...

    Python 3: Write a function CharCount, to take a string S and a single character C, and returns the count of C (one letter) in the string S. If the letter of C is not found in S, the function returns -1. You must write your own function to do this and can not use any built-in counting functions. Use the function in main to get two inputs from the user, a sentence and a character, then show the count...

  • Write a C++ program for the instructions below. Please read the instructions carefully and make sure...

    Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   please put comment with code! and please do not just copy other solutions. 1. write the code using function 2. Please try to implement a function after the main function and provide prototype before main function. Total Characters in String Array 10 points Problem 2 Declare a string array of size 5. Prompt the user enter five strings that are...

  • C++ (1) Prompt the user to enter a string of their choosing (Hint: you will need...

    C++ (1) Prompt the user to enter a string of their choosing (Hint: you will need to call the getline() function to read a string consisting of white spaces.) Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Nothing ends here; our hopes and our journeys continue!...

  • C++ please! (1) Prompt the user to enter the name of the input file. The file...

    C++ please! (1) Prompt the user to enter the name of the input file. The file will contain a text on a single line. Store the text in a string. Output the string. Ex: Enter file name: input1.txt File content: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Nothing ends here; our hopes and our journeys continue! (2) Implement a PrintMenu() function,...

  • (c programming): write a program that contains a function named getName, that does not get any...

    (c programming): write a program that contains a function named getName, that does not get any parameter and returns a character array of a random name from a constant list of 30 names, in a global array. the function returns that random name. each name in the list is a character string that consists of not more than 20 characters(not including finishing 0). the name consists of only characters from the american alphabet (a-zA-Z) and does not contain any "white"...

  • Please write code using Python. Rubric Assignment Solution Total: 100 pts Program successfully retrieves and validates...

    Please write code using Python. Rubric Assignment Solution Total: 100 pts Program successfully retrieves and validates user input 15 pts Morse Code Function Created 10 pts Function Uses Parameters to get input message 15 pts Function successfully converts passed message to Morse Code and returns the Morse Code equivalent of message 45 pts Program calls Morse Code function and outputs the result of the function (i.e. the actual Morse Code) 15 pts Main Function Requirement Part 2 MUST have a...

  • (1) Prompt the user to enter a string of their choosing. Store the text in a...

    (1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Nothing ends here; our hopes and our journeys continue! You entered: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT