473,883 Members | 1,709 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating pythagorean triples from input.

A pythagorean triple is a triple <a,b,c> whose components are positive
integers satisfying a*a + b*b = c*c. An example is <3,4,5> since 3*3 + 4*4 =
9 + 16 = 25 = 5*5.

I want to write a function to extract pythagorean triples from an input
stream. The input is formatted so that only the first two components <a,b>
of a pythagorean triple are specified. The function signature will be:

std::istream &operator>>(std ::istream &is, PythagoreanTrip le &triple);

Can anyone write me some good working code that implements this
functionality? This is not for a school project in case you're wondering.
Thanks.
Jul 22 '05 #1
37 3428
"Jason Heyes" <ja********@opt usnet.com.au> wrote in message
news:41******** *************** @news.optusnet. com.au...
A pythagorean triple is a triple <a,b,c> whose components are positive
integers satisfying a*a + b*b = c*c. An example is <3,4,5> since 3*3 + 4*4
= 9 + 16 = 25 = 5*5.

I want to write a function to extract pythagorean triples from an input
stream. The input is formatted so that only the first two components <a,b>
of a pythagorean triple are specified. The function signature will be:

std::istream &operator>>(std ::istream &is, PythagoreanTrip le &triple);

Can anyone write me some good working code that implements this
functionality? This is not for a school project in case you're wondering.
Thanks.


No? Well it sure sounds like it.

Not that it matters. Requests for coding from requirements are off topic for
this newsgroup. Take a crack at writing your function and if it doesn't work
post what you have.

--
Cy
http://home.rochester.rr.com/cyhome/
Jul 22 '05 #2
"Cy Edmunds" <ce******@spaml ess.rochester.r r.com> wrote in message
news:vo******** *********@twist er.nyroc.rr.com ...
"Jason Heyes" <ja********@opt usnet.com.au> wrote in message
news:41******** *************** @news.optusnet. com.au...
A pythagorean triple is a triple <a,b,c> whose components are positive
integers satisfying a*a + b*b = c*c. An example is <3,4,5> since 3*3 + 4*4
= 9 + 16 = 25 = 5*5.

I want to write a function to extract pythagorean triples from an input
stream. The input is formatted so that only the first two components
<a,b> of a pythagorean triple are specified. The function signature will
be:

std::istream &operator>>(std ::istream &is, PythagoreanTrip le &triple);

Can anyone write me some good working code that implements this
functionality? This is not for a school project in case you're wondering.
Thanks.


No? Well it sure sounds like it.

Not that it matters. Requests for coding from requirements are off topic
for this newsgroup. Take a crack at writing your function and if it
doesn't work post what you have.

--
Cy
http://home.rochester.rr.com/cyhome/


I wrote the requirements myself I'll have you know.
Jul 22 '05 #3

"Jason Heyes" <ja********@opt usnet.com.au> wrote in message
news:41******** *************** @news.optusnet. com.au...
A pythagorean triple is a triple <a,b,c> whose components are positive
integers satisfying a*a + b*b = c*c. An example is <3,4,5> since 3*3 + 4*4
= 9 + 16 = 25 = 5*5.

I want to write a function to extract pythagorean triples from an input
stream. The input is formatted so that only the first two components <a,b>
of a pythagorean triple are specified. The function signature will be:

std::istream &operator>>(std ::istream &is, PythagoreanTrip le &triple);

Can anyone write me some good working code that implements this
functionality? This is not for a school project in case you're wondering.
Thanks.


Is all that < , > part of your input? If not it sounds very easy, just read
two integers and calculate the third.

john
Jul 22 '05 #4
Jason Heyes wrote:

A pythagorean triple is a triple <a,b,c> whose components are positive
integers satisfying a*a + b*b = c*c. An example is <3,4,5> since 3*3 + 4*4 =
9 + 16 = 25 = 5*5.

I want to write a function to extract pythagorean triples from an input
stream. The input is formatted so that only the first two components <a,b>
of a pythagorean triple are specified. The function signature will be:

std::istream &operator>>(std ::istream &is, PythagoreanTrip le &triple);

Can anyone write me some good working code that implements this
functionality? This is not for a school project in case you're wondering.
Thanks.


What I am wondering is: What is your *exact* problem?
The task sounds easy enough. Or not so easy, depending on what you
are willing to invest in syntax parsing.

Post your attempt at it, and tell us where your problem is, which
part of it you can't do or have no idea on how to do it.

--
Karl Heinz Buchegger
kb******@gascad .at
Jul 22 '05 #5
"Jason Heyes" <ja********@opt usnet.com.au> wrote in message news:<41******* *************** @news.optusnet. com.au>...
"Cy Edmunds" <ce******@spaml ess.rochester.r r.com> wrote in message
news:vo******** *********@twist er.nyroc.rr.com ...
"Jason Heyes" <ja********@opt usnet.com.au> wrote in message
news:41******** *************** @news.optusnet. com.au...
I want to write a function to extract pythagorean triples from an input
stream.
Can anyone write me some good working code that implements this
functionality? This is not for a school project in case you're wondering.
Thanks.


Requests for coding from requirements are off topic for this newsgroup.


I wrote the requirements myself I'll have you know.


So? RTFF. Requests for coding from requirements are off topic, and
there's no exception in there for the case where you wrote them.

Besides, it's not like we believe you. You can't write the requirements
in that detail if you can't even try to come up with a first attempt
at implementing them.

Regards,
Michiel Salters.
Jul 22 '05 #6

"Jason Heyes" <ja********@opt usnet.com.au> wrote in message
news:41******** *************** @news.optusnet. com.au...
A pythagorean triple is a triple <a,b,c> whose components are positive
integers satisfying a*a + b*b = c*c. An example is <3,4,5> since 3*3 + 4*4
= 9 + 16 = 25 = 5*5.

I want to write a function to extract pythagorean triples from an input
stream. The input is formatted so that only the first two components <a,b>
of a pythagorean triple are specified. The function signature will be:

std::istream &operator>>(std ::istream &is, PythagoreanTrip le &triple);

Can anyone write me some good working code that implements this
functionality? This is not for a school project in case you're wondering.
Thanks.


You should be able to write it yourself. Are you asking for an algorithm?
Well, since a*a+b*b=c*c, try computing the square root of a*a+b*b. If the
result of that is the same as the floor() of that result, then you've got a
valid integer result, and a result that satisfies the requirements.
Otherwise you don't.

sqrt(3*3+4*4) = 5.0000... == 5.0 --> 5 satisfies
sqrt(3*3+5*5) = 5.8309... != 5.0 --> nothing satisifies

-Howard

Jul 22 '05 #7
"Jason Heyes" <ja********@opt usnet.com.au> wrote in message news:41******** *************** @news.optusnet. com.au...
A pythagorean triple is a triple <a,b,c> whose components are positive integers satisfying a*a + b*b = c*c. An example is <3,4,5>
since 3*3 + 4*4 = 9 + 16 = 25 = 5*5.

I want to write a function to extract pythagorean triples from an input stream. The input is formatted so that only the first two
components <a,b> of a pythagorean triple are specified. The function signature will be:

std::istream &operator>>(std ::istream &is, PythagoreanTrip le &triple);

Can anyone write me some good working code that implements this functionality?
Your request shows up here often enough to have become a FAQ.
See http://www.parashift.com/c++-faq-lit...t.html#faq-5.2
This is not for a school project in case you're wondering.
I would help if you could cogently explain why anybody not a student
would need to solve this trivial problem yet require help to do so.
Thanks.

--
--Larry Brasfield
email: do************* **********@hotm ail.com
Above views may belong only to me.
Jul 22 '05 #8
"Michiel Salters" <Mi************ *@logicacmg.com > wrote in message
news:fc******** *************** ***@posting.goo gle.com...
"Jason Heyes" <ja********@opt usnet.com.au> wrote in message
news:<41******* *************** @news.optusnet. com.au>...
I wrote the requirements myself I'll have you know.


So? RTFF. Requests for coding from requirements are off topic, and
there's no exception in there for the case where you wrote them.

Besides, it's not like we believe you. You can't write the requirements
in that detail if you can't even try to come up with a first attempt
at implementing them.

Regards,
Michiel Salters.


Don't talk about what I can or can't do. Its insulting.
Jul 22 '05 #9
"John Harrison" <jo************ *@hotmail.com> wrote in message
news:2v******** *****@uni-berlin.de...

"Jason Heyes" <ja********@opt usnet.com.au> wrote in message
news:41******** *************** @news.optusnet. com.au...
A pythagorean triple is a triple <a,b,c> whose components are positive
integers satisfying a*a + b*b = c*c. An example is <3,4,5> since 3*3 + 4*4
= 9 + 16 = 25 = 5*5.

I want to write a function to extract pythagorean triples from an input
stream. The input is formatted so that only the first two components
<a,b> of a pythagorean triple are specified. The function signature will
be:

std::istream &operator>>(std ::istream &is, PythagoreanTrip le &triple);

Can anyone write me some good working code that implements this
functionality? This is not for a school project in case you're wondering.
Thanks.


Is all that < , > part of your input? If not it sounds very easy, just
read two integers and calculate the third.

john


No the < , > symbols are not part of the input. Here is some code that reads
two integers and calculates the third:

int a, b;
if (!(is >> a && is >> b))
return is;
int c = (int)sqrt(a*a + b*b);

This is wrong code for the stated requirements.
Jul 22 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2040
by: 3than7 | last post by:
I am writing an application to solve Pythagorean Theorum Problems. This is on my own time, i am using a book to learn c++, and after doing a fahrenheit to celsuis program from that book, i wanted to try to make something all be meself. I have it working great to find the hypotenuse, but am having some dufficulty making it produce a missing leg. As you know, a^2 + b^2 = c^2 I have a variable that does the input for the one of the legs...
3
1679
by: Leeh | last post by:
I'm new to the world of RDF and RDF/XML so pardon my naive question: I understand that the "real" RDF model is the conceptual network of nodes (Subjects and Objects) connected by predicate arcs; and that the official way to serialize the graph is to use the RDF/XML specification. So far so good; but N3 and/or N-Triple notations are also used, and it sure seems to me that N3 is "iso-morphic" to the graph; i.e. The triples (properly...
11
4314
by: corwood | last post by:
I am in a VB .NET class, and one of the assignments is to use loops to generate a list of all the pythagorean triples where legA and legB <100 and hypotenuse < 200, and then put this list into a listbox. I have done this so far: 'Allocate some local variables Dim LegA As Integer Dim LegB As Integer Dim Hyp As Integer Dim Triple As String Dim Found As Integer
5
4725
by: stephanieanne2 | last post by:
The Problem: A right triangle can have sides that are all integers. The set of three integer values for the sides of a right triangle is called a Pythagorean triple. These three sides must satisfy the relationship that the sum of the squares of two of the sides is equal to the square of the hypotenuse. Find all Pythagorean triples for side1, side2, and the hypotenuse that fall within a user-specified range. Limit the upper-bound to 500. Use a...
11
15072
by: inferi9 | last post by:
hi everyone I am new here and I have this C++ program that I have to write but it keep given me nothing useful. here is the question: A right triangle can have sides that are all integers. A set of three integer values for the sides of a right triangle is called a Pythagorean triple. These three sides must satisfy the following relationship: (side1)^2 + (side2)^2 = (hypotenuse)^2 Output all Pythagorean...
12
7432
by: abkierstein | last post by:
This is my 1st program and I need some help. I've almost got this one finished but I don't know where to go from here. There is something wrong with the sides I've assigned. Any tips? // Program: Pythagorean Theorem // Written by: Hellbreaker // // #include <iostream> #include <cmath> using namespace std;
0
9792
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11141
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10415
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7971
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5797
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5991
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4220
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3232
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.