Practice #1

Download code here

Create a struct to represent 2D points

		struct Point
		{
			float x, y;
		};
		

Write a function named ReadPoint that takes a point and reads its x and y coordinates
Note: The point is passed by reference

		void ReadPoint (Point& pnt)
		{
			cout<<"Enter x coordinate of the point: ";
			cin>>pnt.x;
			cout<<"Enter y coordinate of the point: ";
			cin>>pnt.y;
		}
		

Write a function named DisplayPoint that takes a point and prints its x and y coordinates
Note: The point is passed by const reference

		void DisplayPoint (const Point& pnt)
		{
			cout<<"("<< pnt.x<<", "<< pnt.y<< ")"<< endl;
		}
		

Write a simple main function to test your code

		void main ()
		{
			Point p1, p2;
			ReadPoint (p1);
			DisplayPoint (p1);
			p2 = p1;		// assignment statment is the only aggregate operation
							// that defined on structa
			DisplayPoint (p2);

			//const int NumPoints = 3;
			//Point arrPoints[NumPoints];
			//ReadArrayPoints (arrPoints, NumPoints);
			//DisplayArrayPoints (arrPoints, NumPoints);
		}
		

In your main function, declare an array of points

		const int NumPoints = 3;
		Point arrPoints[NumPoints];
		

Write a function named ReadArrayPoints that takes an array points and its size and reads x and y coordinates of array points

		void ReadArrayPoints (Point arr[], const int size)
		{
			for (int i = 0; i < size; ++i)
				ReadPoint (arr[i]);
		}
		

Write a function named DisplayArrayPoints that takes an array points and its size and prints x and y coordinates of array points

		void DisplayArrayPoints (const Point arr[], const int size)
		{
			for (int i = 0; i < size; ++i) {
				cout<<"Point "<< i<< " : ";
				DisplayPoint (arr[i]);
				cout<< endl;
			}
		}
		

Create a struct to represent lines. A line is comprised of two points

		struct Line
		{
			Point pnt1, pnt2;
		};
		

Write a function named ReadLine that takes a line and reads x and y coordinates of its two points

		void ReadLine (Line& line)
		{
			cout<<"Enter Point 1 coordinates\n";
			ReadPoint (line.pnt1);
			cout<<"Enter Point 2 coordinates\n";
			ReadPoint (line.pnt2);
		}
		

Write a function named DisplayLine that takes a line and prints x and y coordinates of its two points

		void DisplayLine (const Line& line)
		{
			cout<<"Point 1 coordinates";
			DisplayPoint (line.pnt1);
			cout<<"Point 2 coordinates";
			DisplayPoint (line.pnt2);
		}