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

Your job is to write the fill function for a raster-based graphics program. The

ID: 3739149 • Letter: Y

Question

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: Select from the options: (L) oad art· F) ill. (S) ave art Choice? L File to read: art.txt ceaee ??????e@ee> Keu) Language: C++ Topic: Recursion

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();

}

}

}