C++ :: How To Change Hierarchy Without Passing Root Element
Aug 6, 2013
I got a mesh which has an edge with a specific transformation (translation + orientation). When this configuration / transformation is changed, its neighbours are to be updated. This structure is kept inside a tree so that when a root "frame" is passed to a method like UpdateHierachy, the mesh will recursively update itself.
If, I don't pass this method the root element, which is in my case, how do I change the rest of the structure? The reason to do this is because I want to say move the door, the windows and furniture will move along with it.
View 8 Replies
ADVERTISEMENT
Mar 12, 2013
I have an application which is used for calibration for electrical components. Here I want to set a rootpath for this application. I did some research and I found out that I can get the rootpath of the application (that is where the exe is stored) But what I am really looking for is once I start the application the root path should be what I assign. For instance currently the root path is "C:UsersPublicDocumentsABC.ToolsProjects" but I would like the root path to be "E:New ABC" Is this possible? I wrote some code where I call the exe of the application and it opens the file in a folder that I specify :
private void NewJournal_Click(object sender, EventArgs e)
{
string filePath = @"E:New ABCabc.vnalog"
if (!File.Exists(filePath))
{
return;
}
string SelectedFile = @"/select, " + filePath;
System.Diagnostics.Process.Start(@"E:New ABCabc.vnalog", SelectedFile);
}
Now this code open the .vnalog file in the application. And this works great..!!! How can I now change the path within the application?
View 1 Replies
View Related
Apr 12, 2014
Code:
#include <stdio.h>
void define (int integer, int IntArr[0], int *IntP);
int main(void)
{int integer = 0, IntArr[1] = {0}, IntP = 0;
define(integer, IntArr, &IntP);
[Code]...
Why does the integer with array change after passing trough the function and the normal integer doesn't? (I know why the normal one doesn't, but I dont get the array one)
View 1 Replies
View Related
Apr 25, 2014
How do we design a container of objects all of which belong to some subclass which directly/indirectly inherits from a given parent class? Moreover, I would like to have functions that enable me to pick only objects of a certain class type from the container.
For example if the parent class is A and I have a hierarchy of classes that derive from it, we must have a container that can contain any class that exists in this hierarchy. Also, get_B() must be able to let me examine only those objects in this container that inherit (directly/indirectly) from class B (class B exists in the hierarchy rooted at A).
Preferably, we would like to avoid downcasting. Or even explicit typechecking of any sort.
View 8 Replies
View Related
Apr 27, 2014
I have been given a HW to write code for a payroll system. The base class would be Employee. There are four types of employees.
1 - Salaried (fixed salary, no matter the hours)
2 - Hourly (overtime [>40 hours] pays time and half)
3 - Commissioned (paid percentage of sales)
4 - Base-plus-commissioned (base salary + percentage of sales)
Also add a private data member birthDate (a Date object) and departmentCode, an int to class Employee.
1 - Is the following hierarchy that I'm visualizing right? Or is a change needed?
Here is the link: [URL] ....
2 - In hourly, what does in round brackets mean? What is meant by "pays time and half"?
3 - In base-plus-commissioned, is it required to take "base salary" from user or I just get salary from the salaried employee?
View 5 Replies
View Related
May 29, 2013
code:
class BM_FONT_CALL BMfont {
public:
BMfont();
~BMfont();
bool Load(const std::string& fontName);
void Print(float x, float y);
class BM_FONT_CALL BMstring : public std::string
[code]....
How can I do `BMstring` have an access to `BMfont`'s members, as if `BMstring` will not inherit `BMfont`'s members? For example, if I do this:
BMfont::BMstring text;
text.scale //I don't want this
What I want to do here is, I want the `BMstring::Compile()` to have an access to `BMfont` with no any instance of `BMfont` inside `BMstring`.
Or what if I do this:
class BM_FONT_CALL BMstring : public std::string {
std::function<void (void)> func;
public:
BMstring() { func = BMfont::Compile(); }
}
By making the `Compile()` member of `BMfont`.But this won't compile. How can I achieve this?
View 2 Replies
View Related
Jun 6, 2012
I have a hierarchy of Actions (NonMovingActions and MovinActions each with sub-hierarchies). Actions class has an abstract function.
Code:
class Action {
public:
Action(Agent& agent, ...):agent(agent),..{}
virtual ~Action(void);
virtual bool run()=0;
[Code]...
It appears that C++ does not allow this (in Java it was possible). Compiler objects that Action class is abstract (and cannot be instantiated?!)
Code: error C2259: 'Action' : cannot instantiate abstract class
1- May I know what do I not understand here? We cannot refer to sub-class instances with a reference of parent class type?
2- Should I use vector of pointers instead or what?
View 6 Replies
View Related
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
Mar 10, 2014
So I have linked list and function which deletes element if next element is bigger, so my code is working but its not working with first element, in the comment I have wrote code which I would code for checking that first element, but when ever I check it is blowing up all program.
#include <iostream>
using namespace std;
struct llist {
int x;
llist *next;
[Code] .....
View 1 Replies
View Related
Jun 11, 2014
I have to create a 2D link list with 2 level hierarchy
some thing like that
Code:
head nodes level 1: 0 1 2
/| / /|
Sub node level 2: 0 1 2 0 1 0 1 2
Real Data under |
each sub node: |
int **join=Null;
int unique = 0;
int col;
int ptr;
int *tmp_perm=Null;
int col_elem;
I know how to deal with 1 level link list structure. But i don't know how to access, delete, nodes and sub nodes from this 2 level hierarchy. C
View 4 Replies
View Related
Feb 23, 2013
I have a global list that contains smaller lists of char arrays. I have an issue where when I'm reading back the inner lists the last element of one list seems to point to first element of the next.
So my data looks like the below (values separated by commas with the pairs separated by tabs. The last pair in a line is the same as the first). When I read the first list back instead of seeing "456.678,678.98" as the last element in the list. I see "435.67,234.98" twice: at the end of the first list and start of the other. I have debugged when the list is populated and can see the correct values going in so I can't figure what's happening.
456.678,678.98 123.45,345.56 256.67,789.98 456.678,678.98
435.67,234.98 123.65,342.56 987.78,678.34 435.67,234.98
Code to fill the list:
obstacle_list = op_prg_list_create();
while (fgets(line, sizeof(line), obstaclePositions_traj_file) ) {
token = strtok(line, "
"); //Pull the string apart into tokens using the
input = op_prg_list_create();
[Code] ....
View 3 Replies
View Related
Aug 23, 2012
I have an std list of type double.. and the list is always guaranteed to have just 2 elements. I need to get the value of element 2 minus element 1. What is the least amount of code to accomplish that?
I tried this:
Code:
list<double> dList;
dList.push_back(1.0);
dList.push_back(2.0);
list<double>::iterator iter = dList.begin();
list<double>::iterator iter2 = dList.end();
double result = *iter2 - *iter;
But this code does not work. Why not?
View 6 Replies
View Related
Feb 20, 2013
My coin/money change code works when there can be an exact change each time, i.e. when the 1 cent option is available. However, when the change options are only $10, $5, $1, 25 cents and 10 cents, it does not give me what I want for instance, I wanted to get change for $237.80, I was expecting to get:
23 10's, one 5, two 1's and 8 dimes. However, the code below is giving me 23 10's, one 5, two 1's and 3 quarters (there is no option left for the 5 remaining cents).how to fix it?
Code:
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
void change(double cents, int a[]);
int main() {
double Dollars;
double cents;
[code]...
View 14 Replies
View Related
Dec 9, 2013
i have written a function that gives me the square root of a number. Yes i know there is already a function in <cmath> that gives square roots but i thought it would be pretty challenging (and therefore fun) to try writing one on my own. I wrote my code while i was in school, listening to my Irish teacher ramble on and on about useless shit, so it's probably not the best possible way of finding the square root of a number.
double msqrt(double x) {
double adder=1;
double y = x;
for(int a=0; ; a++) {
if(y*y > x) y = y/2;
if(y*y <= x) break;
[code]....
View 6 Replies
View Related
Dec 13, 2014
I am having some difficulties splaying this element to the root.. Considering i have this splay tree .
0
1
2
3
4
What are the steps to get it 4 to the root?
View 1 Replies
View Related
Apr 30, 2014
Any way to travel from a leaf to the root. For example I search the tree to find the leaf i want and then trace/record the path back to the root.
View 2 Replies
View Related
Mar 18, 2014
Lets say for example I have a BST that is sorted by char names, using strcmp. IF greater than 0 go right else go left.
I.E (this is just an example, they are not inserted correctly)
cat
/
dog buffalo
/ /
fish mouse zebra snake
I wanted to make a copy of this BST IF the length of the nodes are greater than the root, how would I approach this? I kinda started on this but I'm not sure if I'm making this more difficult than it should be.
void BST::copygreater(node * root, node *& dest, int & holder) {
if(!root) {
dest = NULL;
return;
}
holder = strlen(root->name) + 1; //Don't know about this? If we do a recursive call then the value would change every call?
[Code] ......
View 2 Replies
View Related
May 19, 2013
I got problem in binary tree code. below is my code. When i select pre, post or inorder, the .exe is not responding.. Since in my binary tree theres no roots yet.. who do i solve it? It need condition or what?
View 1 Replies
View Related
Dec 27, 2013
I'm trying to parse the root directory of FAT32 in order to get a dir list in the root folder.
So I need to go over all the directory entries in the root directory and parse them.
My problem is that I don't know when to stop the iteration - How to get the size of the root directory?
I noticed that there is a byte in the boot sector - the number of the entries in the root - but in FAT32 the value is always 0, So how can i get the size of the directory?
View 1 Replies
View Related
Jun 19, 2013
I wrote the following recursion for finding the distance between a root and a leaf, but am not quite sure how to make it work.
Code:
int calc_depth(Node* tree, Node* zero) {
if (!tree)
return 0;
if (zero->right || zero->left == tree)
return 1;
return (zero->right ? calc_depth(tree, zero->right) : calc_depth(tree, zero->left));
}
View 14 Replies
View Related
Dec 5, 2013
I am writing a program to find the square root of a number. I am using the Newton-Raphson method..Just to clarify a bit of the code.. fabs(1/(x+1)) < 0.001 is to check for relative error..
EXAMPLE: for user entry of 100 if the iteration process ends in 10.055 the answer will return as 10 which is correct. But it isn't doing that.
It compiles I then proceed to run it..prompts me "Enter a number to find the square root of: I type 100 then hit enter...
"The square root of 100 is -1077834936"
My first time writing a program from complete scratch.
And I know there is a sqrt() function...just wanted to write my own.
Code:
#include <stdio.h>
#include <math.h>
double mysqrt(double a);
int main()
{
double a, result;
printf("Enter a number to find the square root of: ");
[Code]...
View 1 Replies
View Related
Mar 30, 2013
I am trying to computed the time it takes for a projectile to hit the ground. The problem is that i need to square the input of velocity before i do the calculation. the question I have is that if it's possible to have multiple arguments inside the brackets after main.
#include <stdio.h>
#include <math.h>
double distance (double a, double v, double g);
int square(int y);
double height(double v, double a, double g);
double time (double v, double a, double g);
double sqrt(double num);
[Code] ....
View 2 Replies
View Related
Feb 8, 2014
I want to find the root of an equation f(x) by using the secant method [URL] .....
#include <math.h>
#include <iostream>
using namespace std;
//Define function f(x)
double f(double x, double a, double b) {
return sin((a*x)/(1+x*x))*atan(b*x)+atan(x);
[Code] ....
1) Do I have to keep the function f and RootFinderSMNew in different cpp files?
2) When compiling I get the following errors:
1>------ Build started: Project: Assignment2.1, Configuration: Debug Win32 ------
1> Find Roots Secant method.cpp
[Code] .....
What am I doing wrong ?
View 1 Replies
View Related
Jul 13, 2014
How to write a function macro in C for finding the sqrt of a number?
View 2 Replies
View Related
Mar 1, 2013
I have been trying to write a Newton's Method program for the square root of a number and have been failing miserably...
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double x1;
double y;
double x0;
[Code] .....
View 6 Replies
View Related
Apr 1, 2014
I having trouble with the rational class
here is my assignment:
Add a square root function to the rational class. Have your program print the square root of any rational number. I want to find the square root for numerator and denominator separatetly. divide the answer to get decimals and convert the decimal to fractions. i got till geting the decimal but i want to convert it back to a simplified fraction
// finding greatest common factor
int gcd(int a, int b)
{
if (b == 0)
return a;
else
return gcd(b, a % b);
}
[Code]...
View 2 Replies
View Related