You will need to take the cat to a vet in order to determine if it has an infection.
As to cleaning the carpets, the best thing to initially put down is vinegar. This will combat the urine smell. Of course, the cat may just decide to pee in a different area of your home.
If the cat is not sick, it may just be staking out its territory. I have been having a similar problem with my two cats. One is extremely jealous and has been peeing outside of the litter box to "protest" the other cat. I have three litter boxes for the two cats. The vet has put the cat on a small dose of "cat valiums". I have put dog training pads on the floor around the areas where she pees. There is only so much you can do. Cats are very independent animals. They cannot be scolded like dogs. Yelling at them only increases their anxieties worsening the problem.
Good luck and hope the cat is not sick.