473,657 Members | 2,763 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

object is getting scrambled, but why? plz help!

Ok iam despered, in Main of this code the object 'two' is looking as
should be when i print it, but the exact same code in procedure
"duTest" makes the object
filled up with additional strange values. I played with this code for
hours but i cant find the problem. Plz help me
#include "genetic.h"
#include "neuron.h"
#include "network.h"
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

void duTest()
{
DNA one(0);
UniversalNeuron two;

one.addAllel(4) ;
one.addAllel(4) ;
one.addAllel(1) ;
one.addAllel(3) ;
one.addAllel(3) ; //filling up one.

two.insertDNA(o ne);
two.show(); // Why dont it work??
}

int main()
{
int dummie;
DNA one(0);
UniversalNeuron two;

one.addAllel(4) ; // filling up one.
one.addAllel(4) ;
one.addAllel(1) ;
one.addAllel(3) ;
one.addAllel(3) ;

cout << "\nHere duTest routine\n";
duTest(); // doesnt work <-- inside here two gets filled
//with the right values, but also with some strange values

two.insertDNA(o ne); // works
two.show(); // ^^ <--this works fine,two is not
//filled with strange values

scanf("%d",&dum mie); // press key..
return(1);
}
////// paste from other file VV
class UniversalNeuron
{
public: //
UniversalNeuron ();
UniversalNeuron (int nS ,int gS, int dS, int daS);//
~UniversalNeuro n();
UniversalNeuron (UniversalNeuro n const &other);
void operator=(Unive rsalNeuron const &other);
void insertDNA(DNA &d); // <-- maybe interesting for
// solving problem ???
void show();

etc etc

Jul 23 '05 #1
5 1256
br*******@hotma il.com wrote:
| Ok iam despered, in Main of this code the object 'two' is looking as
| should be when i print it, but the exact same code in procedure
| "duTest" makes the object
| filled up with additional strange values. I played with this code for
| hours but i cant find the problem. Plz help me
|
|
| #include "genetic.h"
| #include "neuron.h"
| #include "network.h"

Neither of these are standard headers, and you haven't posted them.

| #include <iostream>
| #include <algorithm>
| #include <string>
|
| using namespace std;

Please don't do that.

| void duTest()
| {
| DNA one(0);

Unknown identifier DNA.

| UniversalNeuron two;

I'll assume UniversalNeuron is a class because you said so further down.

| one.addAllel(4) ;
| one.addAllel(4) ;
| one.addAllel(1) ;
| one.addAllel(3) ;
| one.addAllel(3) ; //filling up one.

What does addAllel do?

| two.insertDNA(o ne);

What does insertDNA do?

| two.show(); // Why dont it work??

How should I know why it doesn't work, when you haven't posted any
relevant code.

| }
|
| int main()
| {
| int dummie;
| DNA one(0);
| UniversalNeuron two;
|
| one.addAllel(4) ; // filling up one.
| one.addAllel(4) ;
| one.addAllel(1) ;
| one.addAllel(3) ;
| one.addAllel(3) ;
|
| cout << "\nHere duTest routine\n";
| duTest(); // doesnt work <-- inside here two gets filled
| //with the right values, but also with some strange values
|
| two.insertDNA(o ne); // works
| two.show(); // ^^ <--this works fine,two is not
| //filled with strange values
|
| scanf("%d",&dum mie); // press key..

You haven't #included any header for scanf.

| return(1);

Consider returning EXIT_SUCCESS or 0.

| }
|
|
| ////// paste from other file VV
| class UniversalNeuron
| {
| public: //
| UniversalNeuron ();
| UniversalNeuron (int nS ,int gS, int dS, int daS);//
| ~UniversalNeuro n();
| UniversalNeuron (UniversalNeuro n const &other);
| void operator=(Unive rsalNeuron const &other);
| void insertDNA(DNA &d); // <-- maybe interesting for
| // solving problem ???

Maybe.

| void show();
|
| etc etc

Please post a minimal example that reproduces the error, and we might be
able to help you.
--
Robert Bauck Hamar
Jul 23 '05 #2
On 2005-05-29, br*******@hotma il.com <br*******@hotm ail.com> wrote:
Ok iam despered, in Main of this code the object 'two' is looking as
should be when i print it, but the exact same code in procedure
"duTest" makes the object


two is neither declared nor defined in that code. Neither have you posted
any of the class methods that are possible causes of this problem. If
you're not using pointers anywhere, I'm guessing that one of your variables
isn't initialized properly.

Cheers,
--
Donovan Rebbechi
http://pegasus.rutgers.edu/~elflord/
Jul 23 '05 #3
I guess this is the most relevant code, its quite big sorry for that .
And really tnx for your effort ^^
void DNA::addAllel(i nt a)
{
int *tempDNA;
int tempDNASize = size;
tempDNA = new int[tempDNASize];
for (int i = 0; i < tempDNASize; i++) // fout in deze for lus.
tempDNA[i] = dnaString[i];
delete [] dnaString;
dnaString = new int[++size];
for (int i = 0; i < tempDNASize; i++)
dnaString[i] = tempDNA[i];
dnaString[tempDNASize] = a;
delete [] tempDNA;
}

class DNA
{
public:
DNA();
DNA(int sz);
DNA(DNA const &other);
~DNA();
int getAllel(int p);
int getSize();
void operator=(DNA const &other);
void showDNA();
void mutate(float allelFlipProb, float lengthChangePro b);
void mutateTwee(floa t allelFlipProb, float lengthChangePro b);
void crossover(float crossoverProb, const DNA &other);
void addAllel(int a); // ads allel on end.
int getKarma();
void putKarma(int k);
private:
void copy(DNA const &other);
void destroy(void);

int karma; // opzoeken.
int size;
int *dnaString;
};

class UniversalNeuron
{
public: // sommige procedures moeten nu private worden.
UniversalNeuron ();
UniversalNeuron (int nS ,int gS, int dS, int daS);// neighbourhood,
grid, detEm, detEmAll.
~UniversalNeuro n();
UniversalNeuron (UniversalNeuro n const &other);
void operator=(Unive rsalNeuron const &other);
void insertDNA(DNA &d); // werkt zo?
void show();
void getOut();
void putIn();
void process();
void putSubneuron(in t t, int s);
void getEmiterAcces( int s, Emitter *neighbour);// zoiets..

int getDetEm(); // moeten nog VV
void putDetected(int s, float sz ,int sub); // (spec , size ,
subneuron)
void putSpike (float sp, int sub); // (spike, subneuron)
private:
void copy(UniversalN euron const &other);
void destroy(void);

float nFunc(float a, float b, float x);
void nfaAdjust(float a);
void nfbAdjust(float a);
void copyAdjust(floa t a);
void destructAdjust( float a);
void staticOne();
void staticTwo();
void dynamicOne();
void dynamicTwo(int i);
void dynamicThree(in t i, int j , float in);
void dynamicThreeLoc al(int i, int j, float in , int sN);
void dynamicFour(int i);
void dynamicFive();

Manifestation *blueDetectors;
Manifestation *blueEmitters;

SubNeuron *subParts; // bij een 3d grid heeft een neuron 6 , 18 of
26(!) buren.
int neighbourhood; // soort neighbourhood
float nFuncA;// parameters van Neuron functie.
float nFuncB;
float inbox;
float outbox;
float copyTrigger; // bepaald of copieren
float destructTrigger ; // bepaald of destructen

int detEmAll; // alle soorten emmiters of detectors
int detEm; // detectors or emitters on each subneuron
int gridSize; // size of grids.
ConditionCatego ry **ifCondition;
float **thenCondition ;

int alive;
};

void UniversalNeuron ::insertDNA(DNA &d )
{
int effectiveSize;
effectiveSize = d.getSize() - (d.getSize()%5) ; // meervoud van 5.

cout << "\ninsertDN A ffsize : " << effectiveSize << "\n"; // debug
for (int j = 0; j < effectiveSize; j++) //
cout << d.getAllel(j) <<"-"; //
cout <<"\n"; //

for (int i = 0; i < effectiveSize; i+=5) // 5 na lus toegevoegd?
{
cout <<d.getAllel(i) <<" "<<d.getAllel(i +1) <<" "<<d.getAllel(i +3)
<<" "<<d.getAllel(i +4) <<" "<<d.getAllel(i +2)<< " ; ";

ifCondition[d.getAllel(i)][d.getAllel(i+1)].addCondition(d .getAllel(i+3), d.getAllel(i+4) ,d.getAllel(i+2 ));
}
cout << "\n";
}

Jul 23 '05 #4
I will try to make an minimal example that does the same and post that
one,
All Tnxs for your effort and advice ^^

Jul 23 '05 #5
br*******@hotma il.com wrote:

I guess this is the most relevant code, its quite big sorry for that .
And really tnx for your effort ^^

void DNA::addAllel(i nt a)
{
int *tempDNA;
int tempDNASize = size;
tempDNA = new int[tempDNASize];
for (int i = 0; i < tempDNASize; i++) // fout in deze for lus.
tempDNA[i] = dnaString[i];
delete [] dnaString;
dnaString = new int[++size];
for (int i = 0; i < tempDNASize; i++)
dnaString[i] = tempDNA[i];
dnaString[tempDNASize] = a;
delete [] tempDNA;
}


Why all that complicated memory management?
You already have a dynamic growing array at your finger
tips, just use it!

class DNA
{
public:

...

int karma; // opzoeken.
// no longer needed int size;
std::vector< int > dnaString;
};

and your addAllel() function shrinks down to:

void DNA::addAllel(i nt a)
{
dnaString.push_ back( a );
}

and that's the benefit:
* it works out of the box
* you don't need a custom copy constructor any
longer (same for: destructor, assignment operator)
* it will be at or very near the same speed then your home-
made dynamic array. But most likely it will be faster then
your home made array
* lots of complicated and error prone code vanishes into thin air.
* Did I already mention, that std::vector works out of the box?
--
Karl Heinz Buchegger
kb******@gascad .at
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6906
by: Eyal | last post by:
Hey, I would appriciate if anyone can help on this one: I have a java object/inteface having a method with a boolean parameter. As I'm trying to call this method from a javascript it fails on a type mismatch. It is positively because of the boolean(java primitive)parameter. It goes fine if I change this parameter to int or String. This inteface has a lot more methods which works fine, it is just the
6
2234
by: Pierre-Benoit | last post by:
Hi there, I've a strange problem with ado.net and an Access db. I need to create a little C# app that take the content of "ole object" field and then save it into a file. The problem is that when I do the following Byte byteBLOBData = new Byte; byteBLOBData = (Byte)(ds.Tables.Rows);
11
9242
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in C++. I find my self sometimes, trying Object app = Object(); Object *app = Object(); Object app = new Object();
11
1383
by: huzz | last post by:
I am trying to assign a value from DataItem to a variable but keeping getting " Object reference not set to an instance of an object" error message. what i am missing? public void create_ddl(object s, RepeaterItemEventArgs e) { string categoryName = ((DataRowView)e.Item.DataItem).Row.ToString();
4
5256
by: OpticTygre | last post by:
I need to write a loop that prints all the combination possibilities of a character array. Basically, taking a scrambled word, or a regular word, and printing out all the combinations. The letters in the word will only be used once. It sounds easy, but for some reason, I can't get the logic straight in my head. The formula is as follows: If n = the number or letters in the word, the C = the number of combinations, so: C = (n)(n -...
5
2513
by: Michael Moreno | last post by:
Hello, In a class I have this code: public object Obj; If Obj is a COM object I would like to call in the Dispose() method the following code: System.Runtime.InteropServices.Marshal.ReleaseComObject(Obj);
1
2092
by: sohara28 | last post by:
We have recently discovered that several sending systems (all using the same subroutine) have been scrambling some of the data sent to an MS SQL database. I'm trying to figure out how to identify the scrambled records. We know that records with zero in the 4th, 6th and 7th positions of their SSNs, had the SSN rearranged. Instead of the SSN in order (123456789) it is now (467512389). The SSN is used as a subsidiary ID field in the...
5
1295
by: sck10 | last post by:
Hello, Occasionally, my web.config file will get scrambled and I have no idea why. Has anyone else experienced this problem? Thanks, sck10... It goes from this: <add name="ConnOracleIPS2" connectionString="DATA SOURCE=kms_snap.ih.lucent.com;
5
1981
by: Ben | last post by:
Hi, I am looking to incorporate the scrambled text functionality (a graphic etc with scrambled text appears and the user is required to type in what he sees to prevent anonymous hits/spamming etc. - security feature available in most credit card /banking websites). Any pointers to where I can start? Thanks, Ben
0
8394
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6164
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4152
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.