Dense subset of $C[0,1]$ which preserves rationals I am trying to prove the following:

In $C[0,1]$ the functions that preserve the rationals (i.e. $f(\mathbb{Q})\subseteq \mathbb{Q}$) are dense.

So far, I have not made much progress- I am aware that $A$ is dense in $B$ iff $A$ has non-empty intersection with each open set $U$ in $B$ but am not sure how to apply this definition. I have also thought about showing that the closure of $X$ (where $X$ is the set of functions that preserve the rationals) is equal to $C[0,1]$ by a double-inclusion proof but I have also made no progress with this approach. Am I on the right track or should I change my approach?
 A: By the Weierstrass approximation theorem we get that polynomials with real coefficients are dense in $C[0,1]$.
On the other hand polynomials with rational coefficients are dense in polynomials with real coefficients (simply by per-coefficient approximation).
Finally a polynomial with rational coefficients maps rationals to rationals. And so we get even stronger result:

Polynomials with rational coefficients are dense in $C[0,1]$.

A: Without the Weierstrass Theorem: Given $f\in C[0,1]$ and $r>0$ we can find $g\in C[0,1]$ with $g[\Bbb Q\cap [0,1]]\subset \Bbb Q$ and $\sup \{|g(x)-f(x)|: x\in [0,1]\}\le r$ as follows:
$f$ is uniformly continuous.
Let $s>0.$ Take $n\in \Bbb N$ such that $|f(x)-f(y)|<s$ whenever $|x-y|\le 1/n.$
For  integer $j$ with $0\le j\le n,$ take $g(j/n)\in \Bbb Q$ with $|g(j/n)-f(j/n)|<s.$ For integer $j$ with $0\le j\le n-1,$ let $g$ be linear on the interval $[j/n,(j+1)/n].$
For any $x\in [0,1]$ take integer $j\le n-1$ such that $x\in [j/n, (j+1)/n].$ We have $$|g(x)-g(j/n)|\le |g((j+1)/n))-g(j/n)|<3s$$ because $|g((j+1)/n)-f((j+1)/n)|<s$ and $|g(j/n)-f(j/n)|<s$ and $|f((j+1)/n)-f(j/n)|<s.$  We have $$|g(j/n)-f(x)|< 2s$$ because $|g(j/n)-f(j/n)|<s$ and $|f(j/n)-f(x)|<s.$ Therefore $$|g(x)-f(x)|<5s. $$ Now if $s=r/5$ we have $$|g(x)-f(x)|<r$$ for all $x\in [0,1].$
A: Just to take up a problem suggested by the OP in a comment: Let $D$ be the set of continuous functions that are not polynomials with rational coefficients, but sill send rationals to rationals. Then $D$ is dense in $C[0,1].$ Proof: Let $f\in C[0,1]$ and $p$ a polynomial with rational coefficients. Let $n$ be the degree of $p.$ Then for $m=1,2,\dots,$ the functions
$$q_m(x) = \frac{p(x)}{(1+x/m)^{n+1}}$$
are not polynomials, but do take rationals to rationals. You can verify that $q_m\to p$ uniformly on $[0,1]$ as $m\to \infty.$ Since $|p-f|$ can be as small as we want (Weierstrass), the result follows.
