Visual C++ :: Recursion Involving Tree With Many Branches And All Branches Need To Be Stored?
Dec 22, 2014
I want to store all the result which are basically 8 points generated after every time function GenTestPoint is called.
how to store all the points generated i.e 4096+512+64+8 points. However, I mainly need the 4096 points which are generated at the end. I am new to programming, not much familiar with pointer and all stuff.
Its start from level 1.
Level 1 = 8 Points;
Level 2 = 64 points;
Level 3 = 512 Points;
Level 4 = 4096 points;
8 points will be calculated only when if statement is true. But it's fine in the worst case all the statements are true and at the end we will get 4096 points. Just consider that all the if statements are true and I am getting 4096 points at the end which I need to store in some GLOBAL Variable.
I need this 4096 points at the end.
void GenTestPoint(Vec3f test, float level) {
float new_denominator = pow(2.0f,level);
Vec3f result1, result2, result3, result4, result5, result6, result7, result8;
Vec3f result11, result12, result13, result14, result15, result16, result17, result18;
result1 = (test.x - 1/new_denominator, test.y - 1/new_denominator, test.z - 1/new_denominator);
[code].....
View 2 Replies
ADVERTISEMENT
Nov 8, 2013
I need creating a unique form of binary tree. I will eventually drop 256 balls into this to see the distribution, but its creating a pascals triangle recursively.
To create it I need to use two classes, a tree and a node class, and friend them create it recursively.
View 2 Replies
View Related
Jul 21, 2013
The code below is suppose to create directories and upload files, but it is not working. What can I do to make the code work?
Code:
void CRECURSIONDlg::Recursion(CString sPath) {
hInternet = InternetOpen(TEXT("BEAR FTP"),
INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
// Make sure there are no errors
hIConnect = InternetConnect(hInternet,"192.168.1.4", 211,
"******", "*****", INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
[Code] ....
View 6 Replies
View Related
Dec 9, 2014
Write following functions
makingArray: this function will return a double pointer which points to a double array and take one parameter- an integer variable which has a default argument of 5. The argument is the size of the integer array. when the function is called, the users input or default argument will be used for the size of the array. The function will initialize all elements of the array with the 'cin' object.
getTotal: this function will return a double and take two parameters- a double array, which can NOT be modified by this function, and an integer variable for a size of the array. This function will calculate the total of all elements then return a double number which is the total.
main: demonstrate functions( makingArray and getTotal) by calling them in a program
View 1 Replies
View Related
Sep 26, 2014
what I'm trying to do is create 3 child processes stemming from one parent process. I have figured that out but the problem is my program exits when it get to the third child leaving it orphaned(I think).
This is my code for the first generation of processes:
int i = 0;
pid_t child;
about("Dad");
printf("Now .. Forking !!
[Code] .....
I have created a menu GUI that I feel messes with the loop commands, i.e. "Continue". The menu pops up repeatedly after each child process is created. I commented out the block of code for menu which fixed it. I was wondering if there is a way so that I can have the menu not messing with the processing?
View 1 Replies
View Related
Jan 30, 2014
I am currently trying to write a test program involving constructors. I know what I am about to ask is pretty basic stuff but Visual Studio is not recognizing when I declare strings for some reason. My code isn't completed yet but as I am typing string in to declare the variable in the class Visual Studio is not recognizing string as a usable value.
Code below:
#include <cassert>
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
class college {
[Code] .....
Like I said... this is completely unfinished I just need to understand why my strings aren't being recognized.
View 2 Replies
View Related
May 12, 2013
I've written a c++ program that contains the following classes: class Shape, Circle, Ellipse, Rectangle, Triangle. All the classes are a subclass of class Shape. They syntax of their definition is fine, I see no visible errors. This is the code:
#include "graphics.h"
//#include <iostream>
using namespace std;
const float Pi = 3.141;
float distance (int x1, int y1, int x2, int y2) {
[Code] ....
Now when I declare a variable of each subclass in the main, I get an error on two of the classes.
int main () {
Circle a;
Rectangle b;
Ellipse d;
Triangle c;
int x1, y1;
float length;
[Code] .....
...And there's a bunch of similar if conditions. My compiler gives an error under b and d, i.e. the Rectangle object and the Ellipse object. The error is, "Expected a ';'" . I have quadruple checked every inch of my code and as far as I can tell, there are no missing semicolons. Where this ";" belongs ....
View 2 Replies
View Related
May 16, 2014
So basically it consists of implementing a single turn for the game called 'pig' and printing out scores and probabilities of those scores. So this is what I have thus far :
int randomNum (int min, int max) {
return min + rand () % (max - min + 1);
} int singleTurn (int holdValue) {
int totalRoll = 0;
int score = 0;
do {
score = randomNum(1,6);
[code]....
View 13 Replies
View Related
Nov 18, 2013
I am unable to implement the insert function properly,every time i run the program i just get the first value and name,i am not getting other Id's and name.
Code:
"(Header File)"
#include <iostream>
#include <string>
using namespace std;
class node {
public:
int ID;
node (string StudentName, int IDNumber) {
[Code] ....
View 4 Replies
View Related
Oct 31, 2014
I want to find maximum element from a tree (not a binary tree ) ???? ...using c language...
View 1 Replies
View Related
Feb 10, 2013
For my data-structures class, I am attempting to create a binary search tree template to be used to create an AVL tree. I've written a Generic_Tree template for the BST to inherit from, and before I jump into implementing the AVL tree I'm testing the BST member functions. Everything was compiling fine until I added the BST insert() function. Now, I'm getting the following error message from my linker:
undefined reference to 'BST<void>::insert(int, void*)'
Stemming from the call in main line 16.
my makefile compiles with:
g++ -Wall -g Generic_Tree.cpp BST.cpp barfing.cpp main.cpp
Generic_Tree:
template < typename NODE_DATA, unsigned MAX_KIDS >
class Tree {
protected:
struct NODE {
NODE_DATA* contents;
Tree* child[MAX_KIDS];
Tree* parent;
[Code] ....
I'm use to c and havn't used classes or templates before (except for declaring instances of them). The whole syntax is mystifying to me,.
View 4 Replies
View Related
May 12, 2014
To construct and write down algorithm of determination of the sum of squares of consecutive integers with recursion use. I tried to do something:
public static int RecSumSquare(int x, int n)
{
if (n < 0) throw new ArgumentException("n should be greater than zero");
if (n == 0) return 0;
else return x*x+RecSumSquare(x, n - 1);
}
But I don't know as the beginning and the end of this algorithm will look.
View 2 Replies
View Related
May 4, 2014
Suppose I'm given the following code:
int mystery(int n){
int something;
if(n > 0)
View 1 Replies
View Related
Mar 27, 2013
So the task is to find the node with minimum value of a binary tree (not binary search tree). the input is the pointer to the root of the tree. and i cannot make recursion work when i do if conditions. here is what i have Code: /*function 3-takses as input the pointer to the root of the tree and returns a pointer to the node with the minimum value*/
CPPtr minimumvalue(CPPtr SP){
CPPtr min = NULL; //node of minimum value
if(SP== NULL){ // if there is a node, begin comparing
return NULL;
}
else{
if(SP->data<SP->left->data){ //if the node has smaller value than its left child
min = SP; //update node of minimum value
[code].....
no matter where i call my function i get errors like unhandled exception at some memory. how to use recursion in this?
View 6 Replies
View Related
Feb 8, 2013
I have this problem set that has to use recursion to permutate scores. I have read in all the numbers and have tested that it works . l have also attached what I have so far. Here is what I think I need to do:I have to pass the structs into this permutation algorithm that is here:
Code:
#include <stdio.h>
void ListPermutations(char str[]);
void RecursivePermute(char str[], int k);
void ExchangeCharacters(char str[], int i, int j);
[Code]....
View 1 Replies
View Related
Apr 28, 2013
It seems that boost's file recursion requires that the file using the recursion must be in the include path. This makes using file recursion in a library header a problem as libraries may be located in a subdirectory of an include path (which is minor since the programmer can state the subdirectory in the recursive file call as long as it is not relative to the calling file). I also found it a problem when the main compile directory isn't in the compile path.
View 9 Replies
View Related
Mar 28, 2013
So the task is to find the node with minimum value of a binary tree (not binary search tree). the input is the pointer to the root of the tree. and i cannot make recursion work when i do if conditions. here is what i have
CPPtr minimumvalue(CPPtr SP){
CPPtr min = NULL;//node of minimum value
if(SP== NULL){// if there is a node, begin comparing
return NULL;
[Code] ....
No matter where i call my function i get errors like unhandled exception at some memory. How to use recursion in this?
View 1 Replies
View Related
Oct 15, 2014
I want to convert the following program into a non-recursive code using a stack and a loop:
void write(int n) {
if (n>0) {
write(n-1);
cout << n << " ";
write(n-1);
}
}
And here is the code I am using but that currently does not work, and I do not know why:
stack<int> S;
S.push(n);
while (not S.empty()) {
int k = S.top();
[Code] .....
How to simulate that recursion. I thought it was enough to push into the stack the equivalent recursive call.
View 2 Replies
View Related
May 8, 2014
So i have a program it works which takes in a word reverses it prints it out. BUT! the problem is that the program is without recursion. convert the function into recursion.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
[Code].....
View 2 Replies
View Related
Oct 20, 2014
I am trying to print an outline. My code works up to a depth of 3. (The depth is the number of subsections - so 3 would be section 1, section 1.A, and section 1.A.1). It also works for a width (number of sections and each type of subsection) of 26, where it is capped. However, to get a larger depth, it would involve many more loops. Not only is that terrible code, it also freezes up the terminal I'm working on. I believe recursion would make it much nicer, but I'm struggling to grasp the idea when using a string (I understand when it is a number).
#include <stdio.h>
int sec(int width, int snum) {
char section[100];
sprintf(section, "Section ");
[Code].....
View 1 Replies
View Related
Nov 9, 2014
I put some checks in factorial program, I am confused how 27, 40 50 is coming in output and ans is 10.
#include<stdio.h>
int fact(int n) {
if(n==1) {
printf("hello1 %d
",n);
return 1;
[code].....
View 2 Replies
View Related
Aug 28, 2013
I have a linked list I made and am practicing a simple recursion function sum() which returns the sum of all numbers in each node of the list. Here is my sum() function:
int sum(ListNode *ptr){
if (ptr->next)
return (ptr->num + sum(ptr->next));
else
return(0);
}
where the initial arg passed through the ListNode * parameter is my head node (with null value). The output is fine until that point, then the program locks up and I get the "...has stopped working" error.
View 1 Replies
View Related
Apr 28, 2014
I have been asked to write three functions for a Liked List that can add remove and reverse the elements of the Linked List. Now, I have done the add function and It is displaying the elements properly using recursion function. But My removal function is not working and I tried all the possible logic I can think of, I dont know, where did I make mistakes.
This is My class for the Linked List
#ifndef __Linked_Lists_Recursive_function_Implementation___NumberList__
#define __Linked_Lists_Recursive_function_Implementation___NumberList__
#include <iostream>
using namespace std;
[Code]....
View 4 Replies
View Related
Feb 7, 2015
I am trying to input a recursion method. The code compiles, however, it is only giving me a value of 1. I am wanting the value of 5 when it is compiled. Why is this?
#include <iostream>
using namespace std;
int number(int x) {
if (x == 1)
[Code] ....
View 9 Replies
View Related
Mar 20, 2013
How to print to the screen the value of n after it has been multiplied.
For example: if I use cout << "n: " << n << " power: " << power << "
"; I
can see the variable "power" decrementing by 1, but I don't see the variable "n" incrementing with its new value after it has been multiplied by n * n.
#include <iostream>
using namespace std;
typedef unsigned short int USHORT;
typedef unsigned long int ULONG;
ULONG Getpower(USHORT n, USHORT power);
[Code] .....
View 2 Replies
View Related
Feb 25, 2013
I'm trying to write a program that converts a decimal number to a binary one. I have most of the program written, but I am having a little bit of trouble. Whenever I enter a decimal number, the program will convert it correctly to binary, however, the last number is not included in the conversion. EX: Converting 37 into binary (0100101) yields 010010 when entered into the program. BTW the program must utilize recursion to achieve this goal.
#include <iostream>
using namespace std;
void decToBinary(int num1);
int main() {
int num1;
[code]....
View 4 Replies
View Related