|
It doesn't seem to have pasted correctly down the bottom so I'm not sure exactly what's going on, some possibilities:
. you seem to be using investorsList after you've deleted it.
. investorsList=temp; //shouldn't this be done somewhere?
. numOfInvestors++ seems to be done twice
good luck
|
|
|
|
|
It's hard to read code that isn't formatted correctly also, so perhaps use the pre, tag. it preserves your orignal whitespace so tabs actually indent.
if(a==b)
AfxMessageBox("Example of pre tag");
is instead
if(a==b)
AfxMessageBox("Example of pre tag");
Remember to close your tags too!
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
void Investors:: addInvestor(Investor& in)
{
Investor* temp = new Investor[numOfInvestors+1];
if (investorsList == NULL)
{
investorsList = temp;
investorsList[0] = in;
}
else
{
for (int i = 0; i< numOfInvestors; i++)
{
temp[i] = investorsList[i];
cout <<investorslist[i]<<endl;
}
="" temp[numofinvestors]="in;" copy="" the="" new="" element="" in="" last="" position
="" numofinvestors++;="" increment="" numofinvestors
="" delete="" []="" investorslist;="" old="" list
="" for(="" i="0;" i<numofinvestors;="" i++)
="" {
="" investorslist[i]="temp[i];"
="" insertionsort(investorslist,="" numofinvestors);
="" investorslist[numofinvestors];="" numofinvestors++;
}=""
<\pre="">
|
|
|
|
|
Your missing a few brackets and your syntax is a little off.
void Investors::addInvestor(Investor& in)
{
Notice your new is created
Investor* temp = new Investor[numOfInvestors+1];
if (investorsList == NULL)
{
investorsList = temp;
investorsList[0] = in;
}
else
{
for (int i = 0; i< numOfInvestors; i++)
{
temp[i] = investorsList[i];
cout <<investorsList[i]<<endl;
}
temp[numOfInvestors] = in;
numOfInvestors++;
Notice your new is deleted, but what happens if else isn't executed
delete [] investorsList; //delete old list
//This isn't going to make sense to the compiler
for(i = 0; i
{
investorsList[i] = temp[i];
}
insertionSort(investorsList, numOfInvestors);
investorsList[numOfInvestors];
numOfInvestors++;
}
delete should go here unless your if constructs return early
}
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
for(i = 0; i //Your syntax here was off a little { investorsList[i] = temp[i]; }
I could not copy and paste the right code for some reason.
it kept truncating that part of the for statement that you are pointing it to reight above i will try to copy for the last time!
hope it works this time!
void Investors:: addInvestor(Investor& in)
{
Investor* temp = new Investor[numOfInvestors+1];
if (investorsList == NULL)
{
investorsList = temp;
investorsList[0] = in;
}
else
{
for (int i = 0; i< numOfInvestors; i++)
{
temp[i] = investorsList[i];
cout <<investorslist[i]<<endl;
}
="" temp[numofinvestors]="in;" copy="" the="" new="" element="" in="" last="" position
="" numofinvestors++;="" increment="" numofinvestors
="" delete="" []="" investorslist;="" old="" list
="" for(="" i="0;" i<numofinvestors;="" i++)
="" {
="" investorslist[i]="temp[i];"
="" insertionsort(investorslist,="" numofinvestors);
="" investorslist[numofinvestors];="" numofinvestors++;
}="" <\pre="">
|
|
|
|
|
void Investors:: addInvestor(Investor& in)
{
Investor* temp = new Investor[numOfInvestors+1];
if (investorsList == NULL)
{
investorsList = temp;
investorsList[0] = in;
}
else
{
for (int i = 0; i< numOfInvestors; i++)
{
temp[i] = investorsList[i];
cout <<investorslist[i]<<endl;
}
="" temp[numofinvestors]="in;" copy="" the="" new="" element="" in="" last="" position
="" numofinvestors++;="" increment="" numofinvestors
="" delete="" []="" investorslist;="" old="" list
="" for(="" i="0;" i<="" numofinvestors;="" i++)
="" {
="" investorslist[i]="temp[i];"
="" insertionsort(investorslist,="" numofinvestors);
="" investorslist[numofinvestors];="" numofinvestors++;
}="" <\pre="">
|
|
|
|
|
void Investors:: addInvestor(Investor& in)
{
Investor* temp = new Investor[numOfInvestors+1];
if (investorsList == NULL)
{
investorsList = temp;
investorsList[0] = in;
}
else
{
for (int i = 0; i< numOfInvestors; i++)
{
temp[i] = investorsList[i];
cout <<investorslist[i]<<endl;
}
="" temp[numofinvestors]="in;" copy="" the="" new="" element="" in="" last="" position
="" numofinvestors++;="" increment="" numofinvestors
="" delete="" []="" investorslist;="" old="" list
="" for(="" i="0;" i<="" numofinvestors;="" i++)
="" {
="" investorslist[i]="temp[i];"
="" insertionsort(investorslist,="" numofinvestors);
="" investorslist[numofinvestors];="" numofinvestors++;
}="" <\pre="">
|
|
|
|
|
Try this
Investors::Investors(UINT nSize)
{
investorsList = new Investor[nSize*sizeof(Investor)];
}
void Investors::addInvestor(Investor& in)
{
investorsList[numOfInvestors] = in;
insertionSort(investorsList, numOfInvestors);
numOfInvestors++;
}
Investors::~Investors()
{
delete [] investorsList;
}
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
hey HockeyDude;
first of all thank you for your explanations and efforts to solve my dilemma.
but may be i did not mention that I MUST start with an empty array and dynamically cnange its size as i'm adding elements to it!
|
|
|
|
|
Ah...well that adds another layer of difficulty.
Theres no way you can just declare a very large array at construction and fill it in as you go...?
Dynamic resizing isn't easy...I'm working on a class as we speak and i'm not sure i'd be able to fully explain.
First off i don't use new/delete, i use malloc/free.
you have to delete every new at the end of every code block otherwise you get memory leaks.
If you absolutely MUST dynamically resize your array I can only give you pointers...exact code I cannot.
basically use realloc/malloc/free
class CMyClass
{
public:
CMyClass() : m_nCount(0)
{ m_pBuff = malloc(sizeof(Investor)); }
~CMyClass(){ free(m_pBuff); }
void AddInvestor(Investor& newItem)
{
*(m_pBuff+m_nCount) = newItem;
m_nCount++;
m_pBuff = realloc(m_pBuff, sizeof(Investor)*(m_nCount+1)));
}
private:
UINT m_nCount;
Investor* m_pBuff;
};
Note: I don't know for 100% sure the above code is complete, I'm typping from the top of my head. I will however give a starting point.
The code only allocates to a larger size it does NOT shrink itself as required...It assumes there will be NO removal of items once in the array...Also it allocates memory one element at a time...this will fragment your memory. You'd have to allocate large chunks at construction fill them in, then have code in your AddInvestor() reallocate another large chunk and proceed as normal...
All in all this is quite alot of work.
Can I ask what this is for...? Have you considered perhaps using one of MFC's helper classes like CArray...??
It does the Sizing and allocation and stuff for you...
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Man you've been working hard on this stuff man, i don't know how to say thank you.
but the problem is that i must follow the instructor's specification!!!!!
if it depended on me i would have used a linked list but the thing is that i have to use exactly what he said if i don't want to get a zero in my project.
our instructor is so picky!
and as you say "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
i think this is what he wants make us go thru all mistakes??
well anyways here is my latest version of that stupid addInvestor(Investor in) method. see if you trace through it you probably won't find any problems
but the fact is that it adds the first element and crashes same as be4!!!
class Investors
{
// code........
int Investors::numOfInvestors = 0;
Investor* Investors:: investorsList = NULL;
// code........
void Investors:: addInvestor(Investor& in)
{
cout<< in<< endl;
cout<< "numOfInvestors at the beginning: "<< numOfInvestors<< endl;
numOfInvestors++;
Investor* temp = new Investor[numOfInvestors+1];
if (investorsList == NULL)
{
investorsList = temp;
investorsList[0] = in;
}
else
{
for (int i = 0; i < (numOfInvestors - 1); i++)
{
cout << "I am inside the first for loop and i = "<< i<< endl;
temp[i] = investorsList[i];
cout<< temp[i]<< endl;
}
delete [] investorsList;
investorsList = new Investor[numOfInvestors];
temp[numOfInvestors - 1] = in;
for( i = 0; i < numOfInvestors; i++)
{
investorsList[i] = temp[i];
}
insertionSort(investorsList, numOfInvestors);
}
delete [] temp;
cout<<"numOfInvestors at the end: "<< numOfInvestors<< endl;
}
<\pre>
AGAIN THANK YOU:rose: :rose: :rose: :rose: :rose: :rose:
|
|
|
|
|
Send me your cpp/h files unless theres more than one each in email.
It's hard for to lok at this code and guess whats really going on, unless I have the full thing.
Your code is really wide as well, so I keep having to scroll back and forth...It'll be much easier if I can code in my VC workspace.
So you MUST use new/delete for a dynamically growing array...you cannot use malloc and delete...?
That was the reason for the temp array creation...I see...
Yeah like i said..Actually....send me the entire project...that way theres no...missing links...
Cheers
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Zip it too! so I don't get 5-6 files...Just one
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
How can I safely add helpstrings to MFC ActiveX control's ODL file?
I am working on an old activex control and wish to add helpstrings.
After adding the helpstrings, it compiles without any problem and shows in VB class browser.
However, the ClassWizard crashes anytime I try to use it, any tip?
Best regards,
Paul.
Paul Selormey, Bsc (Elect Eng), MSc (Mobile Communication) is currently Windows open source developer in Japan.
|
|
|
|
|
A good whack might do it. (Delete the .clw file)
|
|
|
|
|
Hello -- i have a very wierd problem . i can't create a class starting with a capital C. when i:
Insert-->New Class
Enter the name that starts with a capital C -- the first C doesn't show up in the file name -- but lowercase 'c' works fine. This is as wierd as it gets . . . anybody got a clue on this one
also what is all this crap when i have the wizzards create a class:
#if !defined(AFX_USTOMER_H__E35819DB_8CEA_4883_A2DA_E78053B05B81__INCLUDED_)
#define AFX_USTOMER_H__E35819DB_8CEA_4883_A2DA_E78053B05B81__INCLUDED_
thanks,
tim
---------------------------------------
Tim Booher
|
|
|
|
|
It is not crap . They are called include file guard headers and they are used so that that particular file does not get included twice. The string AFX_USTOMER_H__E35819DB_8CEA_4883_A2DA_E78053B05B81__INCLUDED_ is generated randomly. For eg.
#ifndef _CUSTOMER_H_
#define _CUSTOMER_H_
.
.
.
.
#endif
Atul
Sonork 100.13714 netdiva
|
|
|
|
|
It it Hungarian notation to have all classes begin with a capital 'C'. VC interpret 'Custumer' as 'ustumer'. You could use 'CCustomer' or define your class whitout using the class-wizard.
/moliate
|
|
|
|
|
I don't know if it's Hungarian Notation, but i'm pretty sure that style was dropped with C++.
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Starting class names with C was dropped? Heh, not by a LONGSHOT. Sure, the standard doesn't use that convention, but MS and others having been using long before STL was a glimmer in people's eyes.
And yes, dropping the capitial C from the start of the file name is a ... feature. Annoying if that isn't want you want. However, when creating a new class, you can specify the file names.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
I never said starting classes with a C was dropped...read again!
I said It wasn't part of hungarian notation...
you know lpsz - long pointer to zero termintaed string
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Just TAB into the filename edit boxes and change the filenames there.
--Mike--
"There are only a limited number of jobs where they will ask to see the sausage. Most of them are in movies."
-- Christian Graus, 2/11/2002
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
Big fan of Alyson Hannigan.
|
|
|
|
|
What is the best way to convert
1. points to pixels?
2. cm to pixels?
|
|
|
|
|
explanation in MFC, and from memory. take with large pinch of salt
Given a CDC* pDC , an integer specifying points pt , and another integer specifying centimeters cm :- points to pixels
- cm to pixels (explained above already)
int px = cm*1000;
CSize size(px,px);
pDC->HIMETRICtoDP(&size);
*** note: see documentation for HIMETRICtoDP: in MM_TEXT mapping mode, the measurements gained from this only reflect physical measurements when the ratio of logical coordinates to physical coordinates is 1/1. Not sure when this would matter though.
farewell goodnight last one out turn out the lights Smashing Pumpkins, Tales of a Scorched Earth
|
|
|
|
|
Battleaxe Document Explorer was posted sometime ago, but my bookmark fails.
Best regards,
Paul.
Paul Selormey, Bsc (Elect Eng), MSc (Mobile Communication) is currently Windows open source developer in Japan.
|
|
|
|