Now it has to be modified in order to accept the input 2,2 4,4 and 6,8(only an example) and be able to find out if it is a right triangle. I was told that arrays were not necessarily the only way to go about it.
I'm making a program that prints a triangle of @ signs given rows (but not columns).
For example, the output with rows = 4 would be: @@@@ @@@ @@ @
and rows = 3 would be: @@@ @@ @
However, trying to make this has given me a program that does something similar (but not the same):
for example, with my current program rows = 4 outputs: @@@@ @@@ @@ @
and rows = 3 gives @@@ @@ @
It seems that it's just missing a space (and therefore a setw and setfill), but I found 2 problems:
1. The space needs to not apply to the first line. 2. I can't get it to make a space before each row without making a space between each column.
My current code is:
#include <iostream> #include <iomanip> using namespace std; int main ( ) { int rows;
[Code] ....
I have tried putting in << setws and << setfills of various values but it seems to always apply to between each column as well as at the start of each row- what do I do?
How to do the function part here is the question. "Write a program that calculates the hypotenuse of a right triangle. the program should ask the users to enter the length of the two legs of the right triangle and the program should call a function hypotenuse() that will calculate and display the length of of the hypotenuse. NOTE: The program should include a prototype for the function hypotenuse()" i have this so far
#include <iostream> 4 #include <cmath> // Needed to use the sqrt function 5 using namespace std; 6 7 int main() 8 { 9 double a, b, c;
So I need to make a program that prints a triangle of symbols in a certain direction.
For example: Code: How many rows? 3
@ @@@ @@@@@
How to do that. It's rare that I post without figuring anything out, but I'm just simply not sure. I have a program that prints a triangle in a similar direction, so maybe if I could get some hints as to what to do with that (HINTS, not direct source code) .
Code: #include <iostream> #include <iomanip> using namespace std; int main ( ) {
I need to make a program that returns pascal's triangle of N rows. I actually need to make a function of format "int **func(int n)". I don't know how to go about that, so I am trying this method first, but I seem to be getting an endless loop.
Code: #include <stdlib.h>#include <stdio.h> int *rowN(int rowNum, int* prevRow) { int *rowN; rowN=realloc(rowN,(rowNum+1)*sizeof(int));
I made a simple program to compute the lengths of a triangles sides, but when I enter 30 for angle and 10 for hypotenuse I get the opposite side is -9.880316 and the adjacent is 1.542514.
I am having trouble of exactly how "class" works. I dont know what the difference between set and get is. I have this code:
#include <iostream> #include <cmath> using namespace std; class Point { private: double px; double py;
[Code] .....
How to get void Triangle::setBottomLeftX(const double x) to work.
Implement the get and set member functions for the class Triangle. Use the appropriate class attributes of the class Triangle.
a. The location of the bottom left vertex is stored in the member attribute blPoint. b. The top left vertex can be computed from blPoint and the height. c. The bottom right vertex can be computed from blPoint and the length.
C programming: I want to creat a program that asks the user to input the integer lengths of three sides of a triangle, and if so whether the triangle is a right-angled, acute or obtuse one. i am having some doubts about the if, else if statements. I never seem to know how and in what order to use them.
Code:
#include <stdio.h> #include <stdlib.h> #include <math.h> int main(int argc, char *argv[]){ int SideA; int SideB; int SideC; }
What the heck is wrong with my logic? I just print a rectangle!!! I have played with thing for ever it seems. I thought the rotating part would be hard but now I find myself stuck.
I need to find out neighbors of a triangle and loop it over entire unstructured grid. How to do it?. Cell numbers are random so I am unable to loop over all cells.
I intended to compute perimeter of a triangle. The problem is the initial value for the triangle.
#include <iostream> #include <cmath> using namespace std;
struct Point{ double x; double y;
[Code] ......
I expect to get 0 for triangle1, but I get some strange value...
Here is the result
Type x for point1 : 1 Type y for point1 : 1 Type x for point2 : 3 Type y for point2 : 1 Type x for point3 : 1 Type y for point3 : 3 The perimeter of the triangle1 is : 2.82843 The perimeter of the triangle2 is : 6.82843
Similar to Pascal’s triangle, the difference triangle has some interesting properties that find applications in various fields of the natural and applied sciences. In simple terms, a difference triangle is a set of integers arranged in an inverted triangle where each inverted triangle triad has its lower element equal to the difference (absolute value) of the two elements in the upper row. A difference triangle can be created from a sequence of integers forming the uppermost row by iteratively taking differences between consecutive terms to form the next row until a single-element row is created.
Example Consider the sequence 5, 8, 13, 21, 34, 55 from the Fibonacci series as the uppermost row of the difference triangle. The difference between successive elements form a new set: 3 (= 8 – 5), 5 (= 13 – 8), 8 (= 21 – 13), 13 (= 34 – 21), and 21 (= 55 – 34). The process can then be repeated until there is only one element left giving the following difference triangle:
5 8 13 21 34 55 3 5 8 13 21 2 3 5 8 1 2 3 1 1 0
Problem Write a program that forms a difference triangle using a given series of numbers as topmost row.
Write a class called MyTriangle, which models a triangle with 3 vertices, is designed as follows. It contains:
1. The MyTriangle class uses three MyPoint instances as the three vertices.
2. Three private instance variables v1, v2, v3 (instances of MyPoint), for the three vertices.
3. A constructor that constructs a MyTriangle with three points v1=(x1, y1), v2=(x2, y2), v3=(x3, y3).
4. An overloaded constructor that constructs MyTriangle given three instances of MyPoint.
5. A toString() function that returns a string description of the instance in the format "Triangle @ (x1, y1), (x2, y2), (x3, y3)".
6. A getPerimeter() function that returns the length of the perimeter in double. You should use the distance() method of MyPoint to compute the perimeter.
7. Also write a test program (called main.cpp) to test all the functions defined in the class (example of a triangle: (-2, 1), (1, 3) and (3, -3)).
class MyTriangle { MyPoint v1; MyPoint v2; MyPoint v3;
I wrote a function to calculate the hypotenuse of a triangle. My code looks fine but when i enter the two sides it does not give out the right answer. I really don't know what to do.
So, I have created a class called "point" and i have 4 "point" objects. They only have 2 variables, x and y (their position). The first 3 points form a triangle and now I need to tell if the forth one is inside or outside. I have found some solutions but they involve heavy math (they are based on the sum of the angles or something like that). I want to know if there is any way to solve this only by using the distance between points. I have created a function which takes 2 "point" objects and returns a float value which is their distance.
Here is some code:
#include <iostream> #include <cstdlib> #include <math.h> using namespace std;
I am currently learning "if statements" while doing a program that calculates the area of a triangle. My problem is that the result is always "0". I am pretty sure the problem lies within my math, but how I have set it up wrong.
I am using Heron's Formula. Here it is for reference:
area=sqrt(s(s-a)(s-b)(s-c)) where s=(a+b+c)/2
Code: #include <stdio.h> #include <math.h> int main () {
When i set any 3 inputs length, the space should be move in right position. I try to fix the space move forward into 1 space, but don't know why it doesn't work. Specially, when the number is 4 or 5. The space didn't move 1 space.
using System; class length{ static void Main(){ int i,j,k; string star = "*"; string s1 =""; string s2; int[] nums = new int[] {3,4,5};