Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1,Write a short C++ code fragment that reads a line of text and echo the line wi

ID: 3919845 • Letter: 1

Question

1,Write a short C++ code fragment that reads a line of text and echo the line with all uppercase letters replaced by asterisks.

2,Write a C ++program that prompts for an input file name and output file name, receives them in a C-string. The program should check for errors opening a file. Then write the contents of the input file in output file.

3,The dot operator is used between an object and a data member or between a calling object and a call to a member function from the class of the object.

4,A structure variable can be defined directly in the same statement that defines a structure definition.

Explanation / Answer

1) ,Write a short C++ code fragment that reads a line of text and echo the line with all uppercase letters replaced by asterisks.

Answer : -

//Including all the necessary Libraries

#include<algorithm>

#include<string>

#include<iostream>

using namespace std;

int main()

{

string text;

int i;

//Get the text in a string

cout<<"Enter the text"<<endl;

getline(cin,text)

//Iterate over each letter in the text

for(i=0;i<text.length();i++)
{

//check if it is uppercase
if(isupper(text[i]))
{

// if it is uppercase replace it with "*"
replace(text.begin(), text.end(),text[i], '*');
}
}

//Display the text
cout << text << endl;

return 0;

}