contestada

Given a string, an integer position, and a character, all on separate lines, find the character of the string in that position and replace it with the character read. Then, output the result.

Respuesta :

Following are the C++ program to replace a character value from the input string:

Program Explanation:

  • Defining header file.
  • Defining the main method.
  • Defining three different types of variables "str, P, and Ch" that are "string, integer, and character".
  • After input value into the above variable, a character at method is declared that takes position index value and replaced by character.
  • At the last using print method that prints replaced string value.

Program:

#include <iostream>//header file

#include <string>//header file

using namespace std;

int main() //main method

{

   //defining variables

 string str;//string

 int P;//integer

 char Ch;//character

 cin>>str;//input string value

 cin >>P;//input integer value

 cin >> Ch;//input character value

 str.at(P)  = Ch; //uing char-at method that takes position index value and replaced by character

 cout << str << endl;//print replaced string value

 return 0;

}

Output:

Please find the attached file.

Learn more:

brainly.com/question/24497583

Ver imagen codiepienagoya
ACCESS MORE