computer c++ program with code

profilethetig
hw5_q__code__incomplete_output.docx

This is the question( I did “i” and “k”) I did not do “j” and I need help with it

Here is the code

#include<iostream>

#include<string>

#include<fstream>

#include<sstream>

#include<algorithm>

using namespace std;

void RemoveComment(string code)

{

while(code.find("/*")!=string::npos)

{

int startpos1=code.find("/*");

code.erase(startpos1,(code.find("*/",startpos1)-startpos1)+2);

}

while(code.find("//")!=string::npos)

{

int startpos2=code.find("//");

code.erase(startpos2,code.find("\n",startpos2)-startpos2);

}

cout<<code<<endl;

}

string RemoveSpace(const string & code)

{

istringstream iss(code);

string result;

string temp;

while (iss>>temp)

{

result+=temp;

result+=' ';

result.erase(result.end()-1);

return result;

}

}

int main()

{

string code;

ifstream file;string npos;

////////////////////////////////////////////////////////////////////////

file.open("file.txt");

if (file.is_open())

{

cout<<'\n' << endl;

cout<<"Before removing comment"<< endl;

cout<<'\n' << endl;

while ( getline (file,code))

{

cout<< code << endl;

}

}

else

{

cout<<"file can not be open"<<endl;

}

file.close();

//////////////////////////////////////////////////////////////////////////////////

file.open("file.txt");

if (file.is_open())

{

cout<<'\n' << endl;

cout<<"After removing comment"<< endl;

cout<<'\n' << endl;

while ( getline (file,code))

{

RemoveComment(code);

}

}

else

{

cout <<"Unable to open file";

}

file.close();

/////////////////////////////////////////////////////////////////////////////////

system("paise");

return 0;

}

Here is my output ( the incomplete output)