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

(C++) For this assignment, make sure that you comment your source code adequatel

ID: 3738016 • Letter: #

Question

(C++)

For this assignment, make sure that you comment your source code adequately.

Your job is to write the fill function for a raster-based graphics program. The graphic is stored in a 2D array of symbols. The input to the function is the row and column cell of the pixel (symbol) to be changed and what symbol to change it to. The goal is to fill the enclosed shape (of one symbol) with the new symbol. This should be done recursively.

The program should dynamically read in an ascii art file, then prompt the user for the cell to fill and what symbol to fill it with. Then allow the user to save the new art.
Example run:

'<@@@@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@@@@>' '<@@@@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@@@@>' '<@@@@< .oooo. .$$@@@@>' '<@@@@oo$$$$$$$o.. ..o$$@@@@>' '<@@@@$$$$$$$$$$$$$oooooooo$$$$$@@@@>' '<@@@@'$$$$$$$$$$$$$$$$$$$$$@@@@>'
'<@@@@< ~"SSSSSS"~ >@@@@>'

)$$$$$$$$$$

>@@@@>'

>@@@@>'

.<@@@@@< .$$$$$'~+++++++'~'$$$$$$$ /$$$$$$>@@@@@>. .<@@@@@<' o$$$$$$++++++++++++++++`'$$$$$$$$$$$$++'>@@@@@>. .<@@@@@<' o$$$$$$oo.++++++++++++++++++)$$$$$$$$$$+++++'>@@@@@>. '<@@@@@< o$$$$$$$$$$$.+++++++++++++++++++++++++++++++++>@@@@@>' '<@@@@< o$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$oooooo...++++>@@@@>' '@@@@< $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$)>@@@@>' '<@@@@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@@@@>' '<@@@@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@@@@>'
'<@@@@< .oooo. .$$@@@@>' '<@@@@oo$$$$$$$o.. ..o$$@@@@>' '<@@@@$$$$$$$$$$$$$oooooooo$$$$$@@@@>' '<@@@@'$$$$$$$$$$$$$$$$$$$$$@@@@>'
'<@@@@< ~"SSSSSS"~ >@@@@>'

Select from the options oad art, Fill, ase art syrebek The rgv ? ?? the fsrctwis tir nva and cabs", cell ar tie pise! 'svrioll tó he ch.rge

Explanation / Answer

ANS:-

void fill(){

while(true){

cin>>symbol;

if(symbol=='E'){

cout<<"type s to save"<<endl;

save();

}

else{

cout<<"type E to exit and F to continue fill"<<endl;

cout<<"Load text:";

cin>>filename;

std::ifstream infile(filename,std::ofstream::binary);

std::ofstream outfile ("temp.txt",std::ofstream::binary);

outfile.open ("test.txt");

cout<<"Enter x co-ordinate:";

cin>>x;

cout<<"Enter y co-ordinate:";

cin>>y;

cout<<"Enter symbol:";

cin>>symbol;

string line;

while (std::getline(infile, line)){

if(x==0)

break;

outfile.write(line,line.length());

x--;

}

if(x==0 and line.length()>0){

line[y-1]=symbol;

outfile.write(line,line.length());

while (std::getline(infile, line)){

outfile.write(line,line.length());

}

}

else{

while(x>0){

outfile.write(" ",1);

}

line='';

for(int i=0;i<y;i++){

line+=' ';

}

line[y-1]=symbol;

outfile.write(line+" ",line.length());

}

outfile.close();

infile.close();

std::ofstream file;

file.open(filename,ios::out);

std::ifstream infile("new.txt",std::ofstream::binary);

while (std::getline(infile, line)){

file.write(line,line.length());

}

file.close();

infile.close();

}

}

}