Pasta is an Italian word meaning "dough", so it's the main ingredient of both "cake" and all sorts of macaroni. Why is it so weird that we choose to use the word "pasta" for cake? ;p There is even the word "pastry" in English.
Anyway, what's the difference between pasta and macaroni?
In English, pasta refers to various kinds of things made from dough (flour, water, sometimes egg). Many of them are called noodles.
Macaroni are a particular kind of pasta: they are long and straight and have a hole along their length: a bit like a straw.
There are also "elbow macaroni" which are a lot shorter and are curved (shaped like a parenthesis, more or less), and also have a hole along their length. These are the kind usually used in the dish "macaroni and cheese".
Spaghetti are similar but are thinner and have no hole in the middle.
Then there are also farfalle (butterfly-shaped pasta), spirelli (corkscrew-shaped pasta), and others. I wouldn't call spaghetti or any of those other kinds "macaroni".
So, all macaroni are pasta but not all pasta are macaroni.