473,406 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

dynamic array problems

blackstormdragon
I have a feeling I'm doing this whole dynamic array thing wrong, or Im misunderstanding it.
Expand|Select|Wrap|Line Numbers
  1. private:
  2.     int degree;
  3.     int numCoef;
  4.     double *coef;
  5.  
  6. Polynomial::Polynomial( int hdegree)
  7. {
  8.     degree = hdegree;
  9.     numCoef = degree + 1;
  10.     coef = new double [numCoef];
  11.     FillCoef();
  12. }
These are just some snipits of code. When coef creates a new double, all I get is a one element array. No matter what is put in. I have a feeling I'm very confused, helps very appreciated.
Thanks
Oct 8 '07 #1
3 1370
rhitam30111985
112 100+
it is possible there is some error in the fillcoef() function.. which i guess inserts values in the the dynamic array .. could u post the relevant insertion fucntion so that u get better help?

regards
Rhitam
Oct 8 '07 #2
I have a feeling I'm doing this whole dynamic array thing wrong, or Im misunderstanding it.
Expand|Select|Wrap|Line Numbers
  1. private:
  2.     int degree;
  3.     int numCoef;
  4.     double *coef;
  5.  
  6. Polynomial::Polynomial( int hdegree)
  7. {
  8.     degree = hdegree;
  9.     numCoef = degree + 1;
  10.     coef = new double [numCoef];
  11.     FillCoef();
  12. }
These are just some snipits of code. When coef creates a new double, all I get is a one element array. No matter what is put in. I have a feeling I'm very confused, helps very appreciated.
Thanks
How are you determining that it's a one element array?
Oct 8 '07 #3
Heres the code for filling the array.
Expand|Select|Wrap|Line Numbers
  1. int c;
  2.  
  3.     for(int index =0; index < numCoef ;index++)
  4.     {
  5.         cout<<"What coefficient do you want for x^"<<index<<": ";
  6.         cin>>c;
  7.         coef[index] = c;
  8.     }
  9.     cout<<endl;
When I debugg using f10, I can look at the elements in coef and there is only ever one element.

*EDIT: I have a feeling every thing works Ok. I think I just don't understand pointers fully. I say this becuase now that my cout overload works everything is prinitng ok. So this problem is fixed, now I just have to fix my +- and * overload statments. Thanks for the help.
Oct 8 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: meyousikmann | last post by:
I am having a little trouble with dynamic memory allocation. I am trying to read a text file and put the contents into a dynamic array. I know I can use vectors to make this easier, but it has to...
6
by: Materialised | last post by:
Hi Everyone, I apologise if this is covered in the FAQ, I did look, but nothing actually stood out to me as being relative to my subject. I want to create a 2 dimensional array, a 'array of...
10
by: Russell Mangel | last post by:
I have written the following program using VS2005. The program is a Dynamic Array similar to System.Collections.ArrayList in .NET. The program works okay until I reach 65536, I can't seem to figure...
13
by: Krivenok Dmitry | last post by:
Hello all! Perhaps the most important feature of dynamic polymorphism is ability to handle heterogeneous collections of objects. ("C++ Templates: The Complete Guide" by David Vandevoorde and...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
3
blackstormdragon
by: blackstormdragon | last post by:
It seems pointers and dynamic arrays are giving me a hard time. Heres part of the assignment. We have to create a class named Student that has three member variables. One of the variables is called...
2
by: ayan4u | last post by:
ok i have two problems... firstly in strict C enviornment is it possible to have a true dynamic charecter array with no predefined length...i mean to say... suppose.. char *array =NULL;...
1
by: Tinku | last post by:
Hi friends I know Static Hashing and i know about Dynamic Hashing, still i have problem to make program with Dynamic Hashing I am new in "C" world, please help me, my problem is: i have to...
13
by: kwikius | last post by:
Does anyone know what a C99 dynamic array is, and if it will be useable in C++? regards Andy Little
20
by: sirsnorklingtayo | last post by:
hi guys please help about Linked List, I'm having trouble freeing the allocated memory of a single linked list node with a dynamic char* fields, it doesn't freed up if I use the FREE()...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.