[Solved] Change Position with C++

Change Position: The room that Patrick and Johnny were staying was very big. They felt lazy to walk inside the room from the bed’s location to another location. So they wanted to change the position of the bed. The shape of the room is a Square. They decided to place the bed at the centre of the room so that their walking distance would be minimised. Can you please help them in placing the bed at the centre?

                         [Solved] Change Position with C++                                                              [Solved] Change Position with C++

Given the coordinates of the left bottom vertex of the square room and the length of the side, you need to write a program to determine the coordinates of the centre of the room.

[Assumption — Length of the side is always even]
 

Input Format:

Input consists of 3 integers. The first integer corresponds to the x-coordinate of the left bottom vertex. The second integer corresponds to the y-coordinate of the left bottom vertex. The third integer corresponds to the length of the square.

Output Format:

Refer Sample Input and Output for exact formatting specifications.
 

Sample Input and Output:

[All text in bold corresponds to input and the rest corresponds to output]

Enter the x-coordinate of the left bottom vertex

10

Enter the y-coordinate of the left bottom vertex

30

Enter the length of a side

16

The centre of the room is at (18,38)

Solution

#include <iostream>
using namespace std;

int main()
{
    int x, y, l;
    cout << "Enter the x-coordinate of the left bottom vertex" << endl;
    cin >> x;
    cout << "Enter the y-coordinate of the left bottom vertex" << endl;
    cin >> y;
    cout << "Enter the length of a side" << endl;
    cin >> l;
    cout << "The centre of the room is at (" << x + l / 2 << "," << y + l / 2 << ")" << endl;
    return 0;
}

Happy Learning – If you require any further information, feel free to contact me.

Share your love
Saurav Hathi

Saurav Hathi

I'm currently studying Bachelor of Computer Science at Lovely Professional University in Punjab.

📌 Nodejs and Android 😎
📌 Java

Articles: 444

Leave a Reply

Your email address will not be published. Required fields are marked *