C++ :: Implementation Of Function In BST To Return Parent With Biggest Son / Sons

May 30, 2013

I got a code of a BST and i need to create a function that will return the value of the parent that it's son/sons sum to the biggest sum - BST and not AVL.

I assume that the shortest code will be recursive but i didn't manage to get it right - i'll send the code without my function because it's wrong - l

#include <vector>
#include <iostream>
using namespace std;
//-----------------------------------------------------------------
// class Node
// a single Node from a binary tree
//-----------------------------------------------------------------
template <class T> class Node

[Code] ....

View 1 Replies


ADVERTISEMENT

C++ :: Composition - Can't Use Set Function Of Parent Class

Apr 5, 2013

From parent class, I mean the class whose obj has been made in the class after that.

#include <iostream>
using namespace std;
class a{
int x,y;
public:
a(int u = 0, int v = 0);
void setXY(int,int);

[code].....

View 1 Replies View Related

C :: Will Return Root Statement At End Ever Return Value Other Than Value Passed To Function?

Mar 29, 2013

I'm writing some functions pertaining to binary trees. I've used recursion once before while learning quicksort but am still quite new and unfamiliar with it. And this is my first time touching a binary tree. So my question: In my addnode function, will the return root statement at the end ever return a value other than the value passed to the function?

Code:

#include <stdlib.h>
struct tnode
{
int data;
struct tnode * left;
struct tnode * right;
}

[code]....

View 4 Replies View Related

C++ :: Hash Function Implementation

Aug 26, 2013

I was trying to implement a hash function in c++. This is just for learning purposes and not for a class project or assignment question. I had some questions before I started programming it:

1) Is it meaningful to have a hash function which maps string to string, string to int, int to int, float to int?
2) Can we have a template implementation which does element to element hashing?

I looked at several sources for a clear understanding of concepts and implementation technique but could not find a good source for reading about hashing.

View 3 Replies View Related

C++ :: String Function In Implementation Section

Jul 20, 2013

I am having trouble with the implementation section of my code. The trouble I am having is with the """"string Name::RevereUsingString()""" function/method. I keep getting an error saying that """"control reaches end of non-void function"""". The two void function below the ""string Name::RevereUsingString()"" fuction/method are ok and ready to be worked on.

How to implement the ""string Name::RevereUsingString()"" correctly in the implementation section?

#include <iostream>
#include <string>
using namespace std;
//-------------Class Section------------------------------------
class Name {

[Code] .....

View 2 Replies View Related

C++ :: Sum Of The Biggest Numbers In A Triangle

Jan 3, 2014

After trying to understand the problem i finally gave up. The problem requires me to calculate the sum of the biggest numbers in a triangle.

For example: 5
4 0
3 8 2
2 7 9 6

Here is the solved problem from the book(It uses recursion, but i do not get it at all)

#include <iostream>
#include <fstream>
using namespace std;
int triunghi[50][50], n, sum=0;
int suma_max(int i, int j);

[Code] .....

I doesn't give me the same result(26) if a change the order of the numbers in the triangle.

View 3 Replies View Related

C/C++ :: Find Biggest Number In A Row

Apr 11, 2015

I'm having this issue where my else if statements are not working. My program only works correctly when I go into my if statement and change the first part of my array to the specific row I am trying to find ex [0][i] to [1][i].

int getMonthMax(int scores[][COLS],int month){
int highestN=0,i, j;
for (i=0;i<ROWS-1;i++){
if(scores[0][i]>highestN){
highestN=scores[0][i];

[Code] .....

View 4 Replies View Related

C :: Finding The Biggest Number In Array?

Feb 2, 2014

I'm supposed to find the biggest number (largest value), in any given array A with n numbers. (no floats)

My thoughts here are, check if A[0] > A[1]. if yes, check if A[0] > A[2]. If no, check if A[1] > A[2] etc.

I'm not sure how I can do this in code. I'm thinking if A[0] > A[1] is true, then set A[0] = A[k]. Kind of set it aside, and use that for the next if test. But I'm not sure how to do it.

This is my code so far.

Code:
int main(){
int A[7] = {12, 6, 9, 33, 2, 25, 53};
int i, k;
k = 0;

[Code]....

I'm aware of the flaws here, but this is the best I can do so far. How can I get the if test to use A[k] next, as A[k] will always be the biggest value?

View 11 Replies View Related

C :: How To Find Biggest Column Of Matrix

Jan 23, 2013

Here is the draft of code that i designed. My task is here to create the matrix, allocate the dynamic memory for it, and to find the biggest sum of the column elements that is located over main diagonal. So main points is correct memory allocation, and the sorting to the biggest sum of column higher than diagonal.

View 14 Replies View Related

C++ :: Fixed Point Implementation - Calling A Static Member Function

Apr 25, 2013

I am doing fixed point implementation in c++ which is done by the following code

#ifndef __fixed_point_header_h__
#define __fixed_point_header_h__
#include <boost/assert.hpp>
#include <boost/static_assert.hpp>
#include <boost/operators.hpp>
#include <limits>

[Code] ....

I am getting the error ambiguous overload for âoperator<â in âbeta < ((-5.0e-1) * pi)â

I know the problem the static member function cannot access the members and objects of structs. am i right?

and how to solve this problem, do i need to implement the cossin_cordic function as a non member function.

View 14 Replies View Related

C++ :: Using Child Class As Parameter Of A Function In Its Parent Class

Aug 27, 2014

I am currently having an issue with a piece of code that I am writing in which I need to use a vector of a child class as a parameter in a function in the parent class. Below is an example of my code:

#include "child.h"
#include <vector>
class parent {
parent();
function(std::vector<child> children);
// rest of class here
}

When I do this my program doesn't compile. However if I try to forward declare, as shown in the following example, it once again refuses to compile:

#include <vector>
class child;
class parent{
parent();
function(std::vector<child> children);
// rest of class here
}

This time, it refuses to compile because it needs to know the full size of the class child in order to create the vector. How to being able to access the child is essential for my program, so what should I do?

View 3 Replies View Related

C :: How To Find Biggest Prime Factor Of A Number

Feb 10, 2015

i want to write a program which find the biggest prime factor of a number for example the biggest prime factor of six is three or the biggest prime factor of fifteen is five. What is my program bug

Code:

#include <stdio.h> // main functions
#include <math.h> // for sqrt function
int main()
{
int i, j, k, f; // F = Flag;
printf("Enter K

[Code]...

View 9 Replies View Related

C++ :: Find Biggest Part Of Column Over Diagonal Of Matrix

Jan 23, 2013

How to find the biggest column of the matrix (higher of main diagonal) Here is the draft of code that i desighned/ Of cause it has a several mistake. My task is here to create the matrix, allocate the dynamic memory for it, and to find the biggest sum of the column elements that is located over main diagonal. So main points is correct memory allocation, and the sorting to the biggest sum of column higher than diagonal.

#include<iostream>
#include<conio.h>
#include<time.h>
using namespace std;

[Code]....

View 5 Replies View Related

C++ :: Pass 2 Arrays Into Void Function And Return Values To One Function?

Feb 12, 2014

I'm trying to pass 2 arrays into a void funtion, and return values to one function.

this is the the program I'm working with, after I'm done I have to split it into 3 files, a header, a main, and a separate cpp file for the functions to live in.

#include <iostream>
using namespace std;
void processArrary(int numberCount[], int Numbers[], int intnumberSize, int numberCountSize);
int main() {
int Scores[26] = {76, 89, 150, 135, 200, 76, 12, 100, 150, 28, 178, 189, 167, 200, 175, 150, 87, 99, 129, 149, 176, 200, 87, 35, 157, 189};
int numberCount[8] = { 0 };

[code]...

The goal of this program is to separate and count the groups of numbers then output the amount of numbers in each group. Near as I can tell, everthing should work, but I'm getting all zeros to be displayed in each group.

View 6 Replies View Related

C :: Main Function Does Not Return Any Values When Calling Other Function?

Jun 9, 2013

The function is supposed to return value from the file in my main, but I am getting empty value. I am trying to get better with pointer. Right now just teaching myself.

right now the only way for this code to show value is when in put the putchar(*ps) inside my readfile function. I would like to readfile to return value and print in the main function.

Code:

#include <stdio.h>
char *readfile(char filename[]);
int main(int argc, char *argv[] ) {

[Code].....

View 4 Replies View Related

C++ :: Function Will Not Return Value

Jan 14, 2015

Why my function will not return this int. It does make it into the if(... prints "test 32" but will not return the given value(123456789).

#include <iostream>
using namespace std;
int lastZero(int x[]);
int main(){
int myArray[] = {1,1,1};
lastZero(myArray);

[Code] ...

View 4 Replies View Related

C++ :: Best Way To Return Values From A Function?

Jan 24, 2014

I wanted to return a string I can do

Code:

string parseFilename(string fileName){
return fileName.subtr(/*blah*/);
}

Can I also use pointers/references here though? When would you use a pointer and when just a return statement?

View 2 Replies View Related

C :: Function Return Code / Value?

Sep 27, 2014

I have a function that needs to return a "uint8_t" value. However before doing the processing I need to perform a test on the argument to check if it's between expected boundaries. Although this function works it gives (a logical) warning that not always a value is returned although expected. What is the normal way for functions like these where I normally should return e.g. -1 in case the test doesn't succeed and otherwise the uint8_t (t) value?

Code:
uint8_t myFunc(int a) {
if (a >= 0 && a <= 100) {
// Perform actions
uint8_t = ...
return t;
}
}

View 9 Replies View Related

C++ :: How To Return A Pointer From Function

May 1, 2013

I am trying to return a pointer from a method. Below is a sample of my code.

CSubnode * CTest::GetSubNode() {
return m_psubnode;//this is declared in CTest as CSunbnode * m_psubnode
}
//in another class
m_subnode = m_ptest->GetSubNode(); //m_subnode is declared as a pointer

Is this the correct why to return a pointer?

View 2 Replies View Related

C++ :: Return Matrix In Function

Jul 4, 2013

How we can return a 3x3 matrix in c++ function.

My code is:

double *computeA() {
double *A = new double[2][2];
// some operations on A and then return
return A;
}

The error that I have in this case is:

error C2440: 'initializing' : cannot convert from 'double (*)[2]' to 'double *'

View 7 Replies View Related

C++ :: Need A Function To Return A String

Aug 13, 2014

I need a function to return a string..i need to pass input as "a,b,c,a,c,d,e" function should return out put as "a,b,c,d,e".

View 3 Replies View Related

C/C++ :: Function To Return Either Value Or Address Of That Value?

Feb 1, 2015

I'd like a function to return either a value or the address of that value by the users input. So he can call the function like:

function("adress") - gets an adress, or function("value") - gets the value

I've tried both function overloading and templates, but none of them worked. He might input a character for the address and an int for the value... but...

Another strange thing that i observed is that the value returned by the function below is 0, so the output is address 0.

class testing
{
public:
static int x;

[Code].....

View 2 Replies View Related

C++ :: Function Return Is Always True?

Oct 2, 2013

This program that I've made works fine to find midpoint, but not distance. The distancefunction always returns a 1 (true). To try to see that it wasn't the math, I added cout.setf(cout.boolalpha) to see and got a result of "true".

//This program is a start to solve basic coordinatre plane distances and midpoints
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

[Code].....

View 3 Replies View Related

C++ :: Get Return Type Of Function

Nov 21, 2012

Say I have overloaded functions with different arguments AND return types. Each set of argument has only one corresponding return type.

Code:
Vector grad(Scalar)
Tensor grad(Vector)

Later I have:

Code:
template <class T>
void test(T x) {
... Y = grad(x)
}

Then how do I automatically declare the type of Y. Do I need to make the grad function a template and specialize each of them ?

View 4 Replies View Related

C++ :: Rename Function Return -1

Jul 6, 2013

I used rename function to rename a file.

The file names are in std::string type variable.

The function usage is like this

int result = rename (old_file_name.c_str(),new_file_name.c_str());

I expected result = 0 but i get result = -1.

Does this return code is due to any file pointer holding to this file?

View 7 Replies View Related

C/C++ :: Is It Necessary Function Main Should Return Int?

Jan 24, 2013

If so what is the reason, and the returning int value indicates wat?

View 4 Replies View Related







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