| Author |
Topic |
|
tadin
Yak Posting Veteran
63 Posts |
Posted - 2007-04-06 : 20:26:00
|
| This a tough question for most of us like me. Specially, who has only 2 weeks of function knowledge but more most other guru of sql i think it is pie of cake.1.The triangle table has three columns, side_a, side_b and side_c. These represent the three sides of a triangle. Write a function or procedure in a package that will read all rows out of this table and output to a different table of your own creation whether the values contained form an equilateral triangle, an isosceles triangle or a scalene triangle, based on: An equilateral triangle is a triangle with all three sides of equal length. An isosceles triangle is a triangle with any two sides of equal length. A scalene triangle is a triangle with no two sides equal 2.create a function or procedure to adequately test your code by populating values to the triangle table, executing the code in step 1, reading the output from the output table and validating the output to the expected values. Your test code should essentially assert that three particular values result in some expected output. Your tests should not contain their own logic except to determine whether or not your assertion matches what your program outputs. Any help would be greatfull |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2007-04-06 : 21:41:44
|
| I think the point of homework is for you to learn something by doing the work yourself.CODO ERGO SUM |
 |
|
|
tadin
Yak Posting Veteran
63 Posts |
Posted - 2007-04-07 : 10:38:17
|
| This is not a homework, i found this question in google. So, i was working how i can solve the question. Any help would be thankfull.So, far i have only this information.Any help would be appreciated.create table dbo.TRIANGLE([id] int identity(1,1) not null primary key,side_a smallint not null,side_b smallint not null,side_c smallint not null) on [PRIMARY]; |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-04-07 : 11:20:25
|
| If you found it with Google, you most probably could find the answer with Google too.What have you come up with this far?If you need help with formulas, see http://hp41.claughan.com/images/00001/idydjnao.jpgPeter LarssonHelsingborg, Sweden |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-04-07 : 11:24:14
|
| Oh, my bad... I didn't realize how simple this is!Tadin, the problem statement has the answer! How do you check equality?Peter LarssonHelsingborg, Sweden |
 |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2007-04-07 : 17:42:46
|
remember that you can't make a triangle of 3 line segments of arbitrary length. The combined length of the two shortest segments must be greater than the longest segment.You might consider adding a constraint/trigger to keep non-sensible lengths from being entered into your table. www.elsasoft.org |
 |
|
|
tadin
Yak Posting Veteran
63 Posts |
Posted - 2007-04-07 : 18:55:36
|
| This is what i have in the table.1) create triangle table and triangle_new table. create table dbo.TRIANGLE(side_a decimal(5,2)not null,side_b decimal(5,2) not null,side_c decimal (5,2)not null) insert into triangle values (3, 4, 5);insert into triangle values (4,4, 5.66);insert into triangle values (2,2,2); |
 |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2007-04-07 : 19:04:46
|
here's what I was trying to say. this inserts into your table without errors:insert into triangle values (1,1,100)however you can't make a triangle with those three lengths. so you might want to add some code to prevent such nonsense from entering into your table. that's all i meant. or perhaps you don't care about this point. if not, that's fine.  www.elsasoft.org |
 |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2007-04-07 : 21:02:50
|
lengths of 1,1,100 do not make any sort of triangle. if you think they do, you need to go back and read your geometry book. www.elsasoft.org |
 |
|
|
tadin
Yak Posting Veteran
63 Posts |
Posted - 2007-04-07 : 21:07:18
|
| i didn't put 100 for one side.But you can have one side with 100 in length, still. |
 |
|
|
tadin
Yak Posting Veteran
63 Posts |
Posted - 2007-04-07 : 21:21:48
|
| i mean i didn't put the value above.I don't know what you're trying to do.I missed your previous message, you're right about the 1,1,100. |
 |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-04-08 : 03:45:54
|
| Jezemine, you have to be careful with that statement.{1, 1, 100} is not a triangle on the 2-dimensional plane, but on a 3-dimensional spherical object, it might be.Peter LarssonHelsingborg, Sweden |
 |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2007-04-08 : 09:39:56
|
hehe, good one. so we ought to ask OP what sort of spacetime curvature they are operating in...  www.elsasoft.org |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-04-08 : 09:59:38
|
Cheers! Peter LarssonHelsingborg, Sweden |
 |
|
|
tadin
Yak Posting Veteran
63 Posts |
Posted - 2007-04-09 : 15:28:54
|
| Continuing from the previous data. After the first table have been created, the question ask to create an another table, i plan to use a temperory table. So...I am continuing from here, i plan to copy the data...insert into temp Select * from dbo.triangle. Now. What i am planning, is the comparison for the three columns.Going back to the question.Test case and the data:http://en.wikipedia.org/wiki/TriangleAn equilateral triangle is a triangle with all three sides of equal length. An isosceles triangle is a triangle with any two sides of equal length. A scalene triangle is a triangle with no two sides equal side_a, side_b , side_c ;(3, 4, 5);(4,4, 5.66);(2,2,2); I would like to create a condition. Using if-else condtion or using caseexample, all the data in the three columns are equal than i would like to get an ouput equlaterial.So, on... |
 |
|
|
tadin
Yak Posting Veteran
63 Posts |
Posted - 2007-04-09 : 15:37:05
|
| Also, a good point that jezemine pointed out. In isosceles triangle, when the two sides are equal, their sum must be greater than the third side. So, i would also, like to create a condition using if-else or case or any other suggestions. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2007-04-09 : 16:17:26
|
quote: Originally posted by tadin Also, a good point that jezemine pointed out. In isosceles triangle, when the two sides are equal, their sum must be greater than the third side. So, i would also, like to create a condition using if-else or case or any other suggestions.
It has nothing to do with whether it's isosceles or not. in flat euclidean geometry, the sum of the two shorter sides of a triangle must be larger than the longest side. for instance, segments with lengths (1,2,100) also cannot make a triangle. www.elsasoft.org |
 |
|
|
tadin
Yak Posting Veteran
63 Posts |
Posted - 2007-04-09 : 16:48:59
|
| I have a solution in oracle. But i'm trying to do with the sql server,I don't want to do packages.What i'm focusing, here. I have three rows in one table, and copy that table to a new table which i would like to create a temp table and create a function that run through the first table copying the data from the first to a temp table and read the date from the temp table using the user defined function i would like to test the condition of the temp table and get the result read from the temp table to be output.example, the second table stating example, 3,3,3 is equilatrial.so forth. |
 |
|
|
tadin
Yak Posting Veteran
63 Posts |
Posted - 2007-04-09 : 16:55:28
|
| i'm testing the theory, and i don't mean it to be literal triangles. But your insights are great.By definition if three sides are not equal it's scalene. |
 |
|
|
Next Page
|