Question

C++ only. Must use loops. Please do not use sequence of if statements. Given as input...

C++ only.

Must use loops. Please do not use sequence of if statements.

Given as input string and an int N, set result a string made of N repetitions of the last N characters of the string. You may assume that N is between 0 and the length of the string, inclusive.  

• for input of "Hello", 3 → "llollollo"

• for input of "Hello", 2 → "lolo"

• for input of "Hello", 1 → "o"

Homework Answers

Answer #1
#include<iostream>
using namespace std;
int main() 
{
    string s;
    int n;
    
    cout<<"Enter a string: ";
    cin>>s;
    
    cout<<"Enter number: ";
    cin>>n;
    
    for(int j = 0;j<n;j++){
       for(int i = s.length()-n;i<s.length();i++){
          cout<<s[i];
      }
   }
    return 0;
}

Know the answer?
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
Similar Questions
Must use loops. Please do not use sequence of if statements. I need it in C++....
Must use loops. Please do not use sequence of if statements. I need it in C++. Given 2 strings, a and b, set result to the number of the positions where they contain the same length 2 substring. So "xxcaazz" and "xxbaaz" yields 3, since the "xx", "aa", and "az" substrings appear in the same place in both strings. for input of "xxcaazz", "xxbaaz" → 3 for input of "abc", "abc" → 2 for input of "abc", "axc" → 0
C++ Write a recursive function that reverses the given input string. No loops allowed, only use...
C++ Write a recursive function that reverses the given input string. No loops allowed, only use recursive functions. Do not add more or change the parameters to the original function. Do not change the main program. I had asked this before but the solution I was given did not work. #include #include using namespace std; void reverse(string &str) { /*Code needed*/ } int main() {    string name = "sammy";    reverse(name);    cout << name << endl; //should display...
6.31 LAB: Count characters - methods ----- javascript please Write a program whose input is a...
6.31 LAB: Count characters - methods ----- javascript please Write a program whose input is a character and a string, and whose output indicates the number of times the character appears in the string. Ex: If the input is: n Monday the output is: 1 Ex: If the input is: z Today is Monday the output is: 0 Ex: If the input is: n It's a sunny day the output is: 2 Case matters. n is different than N. Ex:...
ANSWER IN C++ ONLY A string of characters including only alphabets (lowercase letters) is provided as...
ANSWER IN C++ ONLY A string of characters including only alphabets (lowercase letters) is provided as an input. The first task is to compute the frequency of each character appearing in the string. In the output, the characters have to be arranged in the same order as they appear in the input string. Then characters have to be rearranged, such that all the characters having a specific frequency, say xx, come together. Let the frequency of a character, lying in...
Note: Do not use classes or any variables of type string to complete this assignment Write...
Note: Do not use classes or any variables of type string to complete this assignment Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along...
use c language only to solve this porblem -------------------------- Have the function StringChallenge(str) take the str...
use c language only to solve this porblem -------------------------- Have the function StringChallenge(str) take the str string parameter being passed and return the number of words the string contains (e.g. "Never eat shredded wheat or cake" would return 6). Words will be separated by single spaces. Examples Input: "Hello World" Output: 2 Input: "one 22 three" Output: 3 you have the following code what edits can you do #include <stdio.h> #include <string.h> void StringChallenge(char str[]) {      // code goes...
*In Java Please RECURSION Objectives • Learn the basics of recursion – Part II (last week...
*In Java Please RECURSION Objectives • Learn the basics of recursion – Part II (last week was Part I) Submission Guidelines: You will turn in 2 program files (one for each lab problem) Tasks This lab has two parts: 1. Write a recursive method repeatNTimes(String s, int n) that accepts a String and an integer as two parameters and returns a string that is concatenated together n times. (For example, repeatNTimes ("hello", 3) returns "hellohellohello") Write a driver program that...
Let S denote the set of all possible finite binary strings, i.e. strings of finite length...
Let S denote the set of all possible finite binary strings, i.e. strings of finite length made up of only 0s and 1s, and no other characters. E.g., 010100100001 is a finite binary string but 100ff101 is not because it contains characters other than 0, 1. a. Give an informal proof arguing why this set should be countable. Even though the language of your proof can be informal, it must clearly explain the reasons why you think the set should...
C++ only: Please implement a function that accepts a string parameter as well as two character...
C++ only: Please implement a function that accepts a string parameter as well as two character arguments and a boolean parameter. Your function should return the number of times it finds the character arguments inside the string parameter. When both of the passed character arguments are found in the string parameter, set the boolean argument to true. Otherwise, set that boolean argument to false. Return -1 if the string argument is the empty string. The declaration for this function will...
MIPS ASSEMBLY Have the user input a string and then be able to make changes to...
MIPS ASSEMBLY Have the user input a string and then be able to make changes to the characters that are in the string until they are ready to stop. We will need to read in several pieces of data from the user, including a string and multiple characters. You can set a maximum size for the user string, however, the specific size of the string can change and you can’t ask them how long the string is (see the sample...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT