Language: C++

#ifndef ___Class_Point
#define ___Class_Point

#include <cmath>

class Point
{
private:

	double x_;
	double y_;

public:

	Point() : x_(0), y_(0) { }

	Point(double x, double y) : x_(x), y_(y) { }

	Point(double x1, double y1, double x2, double y2) : x_(x2 - x1), y_(y2 - y1) { }

	double x() { return x_; }
	double y() { return y_; }

	void operator= (Point& p) { x_ = p.x_; y_ = p.y_; }
	
	Point& operator+ (Point& p) { return Point(x_ + p.x_, y_ + p.y_); }
	Point& operator- (Point& p) { return Point(x_ - p.x_, y_ + p.y_); }
	Point& operator* (double s) { return Point(x_ * s, y_ * s); }
	Point& operator/ (double s) { return Point(x_ / s, y_ / s); }
};

double norm(Point& p1)
{
	return p1.x() * p1.x() + p1.y() * p1.y();
}

double abs(Point& p1)
{
	return sqrt(norm(p1));
}

double cross(Point& p1, Point& p2)
{
	return p1.x() * p2.y() - p1.y() * p2.x();
}

double dot(Point& p1, Point& p2)
{
	return p1.x() * p2.x() + p1.y() * p2.y();
}

#endif

#ifndef ___Computational_Geometry
#define ___Computational_Geometry

bool palarell(Point& p1, Point& p2)
{
	return cross(p1, p2) == 0;
}

bool palarell(Point& p1_s, Point& p1_e, Point& p2_s, Point& p2_e)
{
	return palarell(p1_e - p1_s, p2_e - p2_s);
}

bool orthogonal(Point& p1, Point& p2)
{
	return dot(p1, p2) == 0;
}

bool orthogonal(Point& p1_s, Point& p1_e, Point& p2_s, Point& p2_e)
{
	return orthogonal(p1_e - p1_s, p2_e - p2_s);
}

Point projection(Point& hypo, Point& base)
{
	return base * (dot(hypo, base) / norm(base));
}

Point reflection(Point& hypo, Point& base)
{
	return base + (projection(hypo, base) - hypo) * 2.0;
}

#endif

#include <cstdio>

#pragma warning(disable: 4996)

int main()
{
	int x1, y1, x2, y2, x3, y3, q;

	scanf("%d", &x1);
	scanf("%d", &y1);
	scanf("%d", &x2);
	scanf("%d", &y2);

	Point p(x1, y1, x2, y2);

	scanf("%d", &q);

	for (int i = 0; i < q; i++)
	{
		scanf("%d", &x3);
		scanf("%d", &y3);

		Point a(x1, y1, x3, y3);

		Point c = projection(a, p);

		printf("%.15f %.15f\n", x1 + c.x(), y1 + c.y());
	}

	return 0;
}

Compiler output:
a.cc: In member function 'Point& Point::operator+(Point&)':
a.cc:26:46: error: cannot bind non-const lvalue reference of type 'Point&' to an rvalue of type 'Point'
   26 |         Point& operator+ (Point& p) { return Point(x_ + p.x_, y_ + p.y_); }
      |                                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc: In member function 'Point& Point::operator-(Point&)':
a.cc:27:46: error: cannot bind non-const lvalue reference of type 'Point&' to an rvalue of type 'Point'
   27 |         Point& operator- (Point& p) { return Point(x_ - p.x_, y_ + p.y_); }
      |                                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc: In member function 'Point& Point::operator*(double)':
a.cc:28:46: error: cannot bind non-const lvalue reference of type 'Point&' to an rvalue of type 'Point'
   28 |         Point& operator* (double s) { return Point(x_ * s, y_ * s); }
      |                                              ^~~~~~~~~~~~~~~~~~~~~
a.cc: In member function 'Point& Point::operator/(double)':
a.cc:29:46: error: cannot bind non-const lvalue reference of type 'Point&' to an rvalue of type 'Point'
   29 |         Point& operator/ (double s) { return Point(x_ / s, y_ / s); }
      |                                              ^~~~~~~~~~~~~~~~~~~~~