C++ :: Program That Will Represent Axis-aligned Right Triangle In X-y Plane As A Class

Apr 10, 2013

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.

View 19 Replies


ADVERTISEMENT

C++ :: Design Class That Can Be Used That Can Represent A Parabola

Apr 24, 2013

The program is supposed to design a class that can be used that can represent a parabola.

Code:

#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>
#include <cstdlib>
#include <cstring>

using namespace std;
class Parabola {
public:
Parabola( double, double, double );

[Code] .....

View 3 Replies View Related

C++ :: Program To Read Image (Later Represent By Array 3D)

May 1, 2013

I will make a program to read the image in C++. And later, the image will represent by array 3D, which (x,y) represent the spatial coordinate of (height*weight) image (pixel) and z represent the intesity of those image (0-255).

In matlab, the code for do that is --> imread('image.jpg')

How can I do that in C++?

View 2 Replies View Related

C++ :: Stack Function Is Supposed To Represent Scope Of Program

Dec 5, 2014

I am trying to make an interpreter. This stack function is supposed to represent the scope of the program, meaning scope of the variables. The START represents a new scope, and FINISH represents the current scope closing. I am trying to do a recursive function in which the stack is updated with each recursive call, which represent a new scope for each call.After i enter a new scope and the scope ends, my program prematurely terminates.

void stack(ifstream& file,Hash& Table) {
string line;
getline(file,line);
int i=0;

[code].....

View 2 Replies View Related

C++ :: Void Triangle - Print Class Function

Sep 1, 2013

//Point.cpp
#include "Point.h"
#include <iostream>
#include <cmath>
using namespace std;

Point::Point() { //Initialise the point to the origin.

[Code] ....

void Triangle::print() { //print out the Triangle with the format "( (x1, y1), (x2, y2), (x3, y3) )"

How do I accomplish this? When i test with cout << _point1.print(), there's an error:

[Error] no match for 'operator<<' in 'std::cout << ((Triangle*)this)->Triangle::_point1.Point::print()'

View 4 Replies View Related

Visual C++ :: Triangle Class With Member Variables

Apr 8, 2015

C++
Create a Triangle class that has the following member variables:
side1 - a double
side2 - a double
side 3 - a double perimeter area

The class should have the following member functions:

- default constructor that sets the value of all 3 sides of a triangle to 0.0

- a constructor with arguments that accepts values for the three sides of a triangle (member variables) as arguments

- setDimensions - a function that allows the value of the three sides to be entered by the user through the keyboard

- testSides - a function that determines if the 3 values entered can actually be the sides of a triangle. If they do not create a triangle, print the values entered and an appropriate message
--The sum of any two side lengths of a triangle must always be greater than the length of the third side: so side 1 + side 2 > side 3 and side 1 + side 3 > side 2 and side 2 + side 3 > side 1 ( all three must be true for the 3 values to make a triangle)

- getSide1 - a function that returns the value of side 1, getSide2 - a function that returns the value of side 2, getSide3 - a function that returns the value of side 3

- getArea - a function that returns the area of a triangle: The formula for the area of a triangle (when the height is not known) is: A = sqrt (p(p-side1)(p-side2)(p-side3)) where p = (side1+side2+side3)/2

- getPerimeter - a function that returns the perimeter of a triangle: Perimeter = side1 + side2+ Side 3

- A displayTriangleInfo function that displays side1, side2, side3, area, and perimeter for a triangle object.

After testing your code for a single object, create an array of 5 triangles. Use a for loop and the setDimensions function to allow the user to set the values for the 3 sides of a triangle, test the vales entered to determine if the 3 create a triangle. If they do create a triangle than use the getArea and getPerimeter functions to calculate the Area and Perimeter for the triangle and use the displayTriangleInfo function to display all of the data for that triangle. If the three values do not create a triangle then print the 3 numbers entered and an appropriate message. In either case the loop should then move on and get the data for the next triangle from the user.

View 7 Replies View Related

C/C++ :: Structure Representing Point In XY-plane

Mar 18, 2015

We are supposed to create a point structure that can be used to represent a point in the xy-plane. Then, write a menu-driven C++ program that uses variables of type point to perform a variety of tasks involving points in the xy plane, including slope, distance, midpoint, equation of a line passing through points, and colinearity. One of the functions we are to create is simply for reading in the user-input in the following form "(x,y)" with the user entering the parentheses and comma. We are to create two functions that translate back and forth between this format and what the assignment calls "one point variable."

I'm confused how I'm supposed to take the user entering, say "(1,4)" and reading that into an x and y, and then comparing it against another set of points. I'm guessing I read them in as a, b, c, d, but I'm not sure what this has to do with a structure.

View 1 Replies View Related

C++ :: Finding Intersection Point Between A Plane And A Line

Mar 25, 2013

I'm following this example on finding the intersection point between a plane and a line. (it's about three quarters down) [URL] .....

However this seems to only show how to solve u.

1. I don't understand what u is.
2. How do I find out the intersection point, in terms of (x, y, z)?

View 4 Replies View Related

C++ :: Right Triangle Program Using X And Y

Jan 12, 2015

I originally had the user input three different lengths and then used this to determine whether or not it was a right triangle.

if(c==sqrt(a*a+b*b)||a==sqrt(b*b+c*c)||b=sqrt(a*a+b*b))

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.

View 1 Replies View Related

C++ :: Program That Prints A Triangle Of Symbols

Jan 1, 2015

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?

View 4 Replies View Related

C++ :: Program That Prints Out Pascal Triangle?

Jan 20, 2015

I have a program that prints out pascal's triangle. One problem: it isn't a triangle. The output doesn't work. This is what it should print:

Code: How many rows: 4
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1 and this is what it does print: Code: Enter a number of rows: 4
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1

[Code]....

View 3 Replies View Related

C++ :: Program To Calculates Hypotenuse Of A Right Triangle

May 12, 2014

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;

[Code] ....

View 4 Replies View Related

C++ :: Program To Find Area Of Triangle?

May 26, 2013

i have written a program to find area of triangle, but i meet some errors,

//******area of triangle******//
#include<iostream>
using namespace std;

[Code].....

View 1 Replies View Related

C++ :: Program That Prints A Triangle Of Symbols In A Certain Direction

Jan 12, 2015

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 ( ) {

[Code] .....

View 6 Replies View Related

C :: Program That Returns Pascal Triangle Of N Rows

Nov 25, 2013

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));

[Code] ....

View 7 Replies View Related

C/C++ :: Right Triangle Program - Computing Lengths Of Sides

May 5, 2014

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.

#include <stdio.h>
#include <math.h>
main() {
float angle;
float hypotenuse;
float adjacent;
float opposite;

[Code] ....

View 2 Replies View Related

C++ :: Working On 2 Axis The Same Way

Aug 13, 2013

I have been coding this 2D physic engine for quite some time, I work on the many part of these 2 axis ( x and y ) in the same manner is just that one is an x and one is y

So there is a lot of duplicate code

If there is a bug in one part I have to fix the other axis too which becomes a hazzle because I have to fix the duplicates too. The sample code from my program

for( auto it =bodies.begin(); it != bodies.end(); ++ it ){
sf::Vector2f velocity = it->getVelocity();
if( velocity.x != 0 ){
// do some friction force calculation

[Code] ...

It is even more of a hazzle when I work with 4 quadrant, I have 4 duplicate code each ... How do I write a function for both axis ?

View 9 Replies View Related

C# :: XNA Quanternion Multiple Axis

Nov 28, 2011

I made a working version using absolute vextors being rotated by matrices and keeping relative vecotrs for translations. What I didnt like is that I HAVE TO use the standard XYZ axis for rotation.What I decided to do was use quanternions to store current rotation,cthen buffer rotations each time some were done and add it up.The way I see it, it should look somewhat like this:

(in the UpdateRotation part, plz dont mind any typos i make, this isnt the actual current code. Also on a small note I use dictionaries, so dont be surprised xD) Code: RelativeVectors["Up"] = Vector3.Transform(AbsoluteVectors["Up"], (Quanterion)CurrentRotation);
//repeat for Look and Right relative vectors
Quanternion Yaw = Quanternion.CreateFromAxisAngle(RelativeVectors["Up"], RotationBuffer["Yaw"]);
//repeat for roll and pitch
CurrentRotation = Quanternion.Contancate(CurrentRotation,(Yaw*Pitch*Roll));
//

clear the rotation buffer Whats happening right now tho, is that doing this exactly doesnt actually do anything, so I have to use standard axis anyway.

View 1 Replies View Related

C :: Mirroring Image Over Y Axis

Nov 30, 2014

how to do the mirror function? I have my other two working 100% but for some reason i cannot figure out how to do the mirror part. I want it to be like my flip function(lower code) where I can print the image through the for statement

Code:

int main (int argc, char *argv[]) {
// declarations here
// open input file
FILE *input;

[Code].....

View 1 Replies View Related

C :: Create A Program That Asks User To Input Integer Lengths Of Three Sides Of A Triangle

Sep 6, 2013

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;
}

[code]....

View 14 Replies View Related

C :: Scaling Y Axis - Vertical Histogram

Mar 6, 2015

Scaling the yaxis on my histogram for one of my class projects. I've gotten mostly everything but stuck on scaling. I'm pretty sure it's something simple to do, but I'm having trouble, and I've tried everything to my knowledge to get it scaled from 0.1 - 1, like this:

Here is my code:

#include<stdio.h> //include all preprocessor directives
#include<Windows.h>
int main(void) {
int MAX = 0; //initialize and declare variables
int allcounts [10] = {0}; //store an array of integers for
int yaxis, xaxis = 0;

[Code] ....

I'm close, but every time I try and change my y axis in the for loop from 1 going down to 0.1, it doesn't give me a right output.

View 2 Replies View Related

C/C++ :: Plotting Points On A Circle With One Fixed Axis

Oct 31, 2014

I am working on a computer program where I need to generate points on a circle. I am familiar with this kind of algorithm:

for(d=0; d<=2*pi; d+=0.01)
{
x = cos(d)*radius;
y = sin(d)*radius;
}

However, due to the specifics of the program I am writing, I need to iterate through a fixed number of points one at a time, like so:

for ( int x = 0; x < blockSize; x++ )
{
y = ???
}

This essentially "fixes" one axis of the circle, since I can't do: x=rx+sin(d)*r.

I have tried simply: "y = sin(d)*radius;" and I get a curved shape, but it's not a circle.

My question then is, how do I get the value of y in this situation, where the x axis is incrementing by 1 through a range of values? Is it mathematically possible?

View 6 Replies View Related

C++ :: Linear Interpolation Code For X And Y Axis - Compile Errors

Oct 15, 2012

When trying to compile, I am receiving errors which I am assuming are pretty generic and common:

lin_interp.c:21: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
lin_interp.c:100: error: expected '{' at end of input

I am just trying to get the code to work for now. I have created a program similar to this which worked in C++, but the code isn't jiving in C.

Code:
// Lin_Interp.c : Defines the entry point for the console application.
//
#include "PACRXPlc.h" /* Include file applicable for all targets */
#include "ctkInitCBlock.h"
#include "string.h"
#include "math.h"
#include "stdlib.h"
#include <time.h>
#include <ctype.h>
#include <stdio.h>
/* Constants / #defines */
// Print-Out on console "XY LIMIT ARRAY" XYlim

[Code] .....

View 8 Replies View Related

C/C++ :: Object Represent A Value And Add / Remove Cart?

Sep 25, 2013

im working on Book Ordering system and i having trouble how to make the system recognize different price values when i add different books into it, also how to make the system to be able to add/remove cart?

View 12 Replies View Related

C++ :: Two Player Tic Tac Toe Game - Use Enums When Possible To Represent Values

Apr 19, 2013

Here is the code I have written so far. My problem is that when the second user enters its position the last user's position is wiped of the board. I want to know how I can hold that position and keep doing so until the game is finished. I thought that calling the previous function would do that (and you can see where I have put that into a comment) but it doesn't.

Code:
#include <iostream> //includes header file
using namespace std;
//function prototypes
void printLeftUpper(int i, int j);
void printMiddleUpper(int i, int j);

[Code] ....

View 1 Replies View Related

C++ :: Obtaining Pointers To Represent Each Branch In Hierarchy?

Aug 24, 2014

My program has a large version of this, where every leaf class is singleton, and pointers of the base class to represent each possible path are stored in a map during compile time. I have it working as follows:

#include <iostream>
#include <string>
#include <map>

[Code].....

But System::initializePrototypes() is constructing the map manually, and I want to use recursion somehow, because my hierarchy is much bigger than this. It's also easy to miss a path doing it the above way, and when new classes are added to the hierarchy, it will be a nightmare to update the map. So the ideal solution is recursion constructing the map perfectly--and when new classes are introduced, nothing needs to be added to System::initializePrototypes().

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved