473,462 Members | 1,243 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

standard input in c++ to read 2D coordinates

Hi,

I am new to c++ programming.Could anyone tell me how I can use
standard input in c++ to read 2D coordinates? e.g., read n elements
which have x-coordinates and y-coordinates.

Could anyone show me a simple example? Thanks very much.

---Tonny
Nov 11 '07 #1
3 3005
Ganon11
3,652 Expert 2GB
It depends on how you want this done.

Do you want 2 int variables (xCoordinate, yCoordinate) to hold the values?

Do you want a 2D array with size N X 2 (where N is how many points you need), where the array[i][0] value is your X coordinate and the array[i][1] value is your Y coordinate?

Do you want to define a struct to hold two ints and manipulate these?

Do you want to define a class that will again hold two ints, but also provide some other functionalities?
Nov 11 '07 #2
Hi, thanks for reply.

I want to define a structure to hold n points in a graph, e.g. compute the distance between any two points in a graph.

Any help will be greatly appreciated.
Nov 11 '07 #3
Ganon11
3,652 Expert 2GB
OK, I would start by creating a Point class. The Point class has two int variables for its X and Y coordinates. It should have a constructor that allows it to accept initial values, or provide default values, for the coordinates. It could have a computeDistance(Point& other) function to compute the distance (using the Pythagorean Theorem), as well as an overloaded == operator, maybe even overload the << operator so you can easily and nicely output your points.
Nov 11 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Hobart Runa Sze | last post by:
Hello, I read that passing data via POST means PHP running as CGI needs to read from standard input buffer instead of global vars. I tried reading from $_POST but can't find my data there. I...
3
by: Bill Cohagan | last post by:
I'm writing a console app (in C#) and I want to be able to redirect the standard input/output streams when it's run at a command prompt. IOW I want to support the "<" and ">" redirection syntax....
9
by: kernelxu | last post by:
hi,everybody. I calling function setbuf() to change the characteristic of standsrd input buffer. some fragment of the progrem is: (DEV-C++2.9.9.2) #include <stdio.h> #include <stdlib.h> int...
5
by: Christophe HELFER | last post by:
Hi, I would like to do this in VB Languague. I have an executable file in DOS mode. This executable returns informations and display them to the DOS window. Unfortunately, I have to process...
0
by: Miha | last post by:
I wrote a simple Windows Application based application in C# called the CallWebServiceGui. This application is started from a different application called WsGuiStarter. The WsGuiStarter redirects...
0
by: lini | last post by:
Hello, I am writing some code in the scenario which can be described as follow: + program A which writes to standard output (e.g. cout >> whatever). + program B which has GUI and also listens to...
1
by: terminatorul | last post by:
Hello Sorry if asking a known question. I have a program that reads lines of text from standard input and writes the non-empty ones back to standard output. In most cases it will be used with...
27
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= | last post by:
I have a fully-portable C program (or at least I think I do). It works fine on Windows, but malfunctions on Linux. I suspect that there's something I don't know about the standard input stream...
0
by: AliAmjad | last post by:
Hello All, How can I read from standard input and write to standard output. System.Diagnostics.Process.StandardInput's MSDN reference didn't help as it separately starts the process and then...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.