By była odpowiedz, usmieszek
#include <iostream>
#include <string>
#include <vector>
struct coord
{
float percentX;
float percentY;
};
int
main ()
{
int x = 20, y = 10;
// table for draw
std::string col (x, '.');
std::vector < std::string > rows (y, col);
const coord eyeleft = { 0.3, 0.3 };
const coord eyeright = { 0.6, 0.3 };
std::vector < coord > nose = {{0.4, 0.4},{0.5, 0.4}};
for (coord & c:nose)
rows.at (y * c.percentY).at (x * c.percentX) = 'I';
std::vector < coord > noseholes ={{0.4, 0.5},{0.5, 0.5}};
for (coord & c:noseholes)
rows.at (y * c.percentY).at (x * c.percentX) = '0';
std::vector < coord > mouth =
{{0.2, 0.6},{0.3, 0.7},{0.4, 0.8},{0.5, 0.8},{0.6, 0.7},{0.7, 0.6}};
rows.at (y * eyeleft.percentY).at (x * eyeleft.percentX) = 'O';
rows.at (y * eyeright.percentY).at (x * eyeright.percentX) = 'O';
for (coord & c:mouth)
rows.at (y * c.percentY).at (x * c.percentX) = 'x';
for (const auto & z:rows)
std::cout << z << std::endl;
return 0;
}
edit:: taki komentarz przy ewentualnym bad_alloc error
size_t x = 20, y = 10;
.................
for (coord & c:nose)
if(y * c.percentY<y && x * c.percentX<x )
rows.at (y * c.percentY).at (x * c.percentX) = 'I';
else std::cerr<<'' poleciało za tablicę, badalloc error"<<std::endl;
//////////////////////////////////////////////////////////////////////
int x = 20, y = 10;
.................
for (coord & c:nose)
if(c.percentY>=0 && c.percentY<1 && c.percentX<1 && c.percentX>=0)
rows.at (y * c.percentY).at (x * c.percentX) = 'I';
else std::cerr<<'' poleciało za tablicę, badalloc error"<<std::endl;