565 Posted Topics

Member Avatar for gizmo7008

The problem is that you are passing a particular structure to your printstudent function BUT you are not actually using that data. Let me explain with an example: [code=c++] int main() { Student FirstStudent; // Make a student Student SecondStudent; // Make a DIFFERENT student // Now populate the student …

Member Avatar for gizmo7008
0
6K
Member Avatar for cppgangster

It is another one of these typename instances. First off the solution is this: [code=c++] template<class t> typename Openfile<t>::reference Openfile<t>::rout() { return fin; } [/code] Ok that is the simple part, now I am going to make a complete mess of trying to explain WHY you need a typename. [sorry …

Member Avatar for StuXYZ
0
233
Member Avatar for Christ1m

What doesn't work with this: int main() { VStack<double> A; A.push(10.0); std::cout<<"A =="<<A.size()<<std::endl; } You remember that you have to use a template type in declaring VStack and that you might need to explicitly initialize the template if VStack and Stack are in separate files e.g. Add template class Stack<double>; …

Member Avatar for StuXYZ
0
78
Member Avatar for tKc

This seems a lot like you have coded before you have figured out what you are going to do. So let me point out a number of strange things that you may have overlooked. First you initialize the board to 1,2,3, etc... e.g. [code=c++] for(int y=0; y<n; y++) for(int x=0; …

Member Avatar for StuXYZ
0
214
Member Avatar for Urv73

I think you have almost expressed your own solution, :). If the race is ALWAYS going to be less than 12 hours, or in some way constrained to be in some range which is less than 12 hours, then you simple calculate the time, and if the time goes negative, …

Member Avatar for Urv73
0
172
Member Avatar for Syrne

You main problem is the algorithm that you calculate a continuous average with: you do this: [code=c++] for(int i = 0; i < Student::getCount(); i++) for(int j = 0; j < 5; j++) avg[j] = (avg[j] + (userData + i)->getScores(j)) / i; [/code] So what that does is effectively divide …

Member Avatar for StuXYZ
0
275
Member Avatar for enkidu75

The obvious [once you have seen it] trick to make your output easy to read is this: [code=c++] char first=' '; for(int i=0;i<num_var;i++) { if (equ_1[i]<0) cout<<equ_1[i]<<variable_array[i]; else if (equ_1[i]>0) std::cout<<first<<equ_1[i]<<variable_array[i]; if (equ_1[i]) first='+'; } [/code] You can note that you don't need a separate loop index for variable_array, and …

Member Avatar for StuXYZ
0
170
Member Avatar for georgy9002

This is a classic case of ignoring the compile warnings! It is 99.999% essential to turn on compiler warnings and fix the ALL. [Yes sometimes that means turning a particular warning off, but at least you are aware of exactly what caused it] In your case you have a constructor …

Member Avatar for StuXYZ
0
95
Member Avatar for Annettest

I would like to see all of this class, well in particular the copy and assignment operator, as well as the default constructor. The correct constructor should have: [code=c++] arrayInstance = new T*[rows]; for (int i = 0; i < rows; i++) arrayInstance[i] = new T[cols]; [/code] the destructor should …

Member Avatar for Annettest
0
2K
Member Avatar for vbx_wx

As arkoenig said, as you have written it, it doesn't compile. If you are using the construct operator new, you need to do it like this: [code=c++] class X { X() { std::cout<<"Constructor called "<<std::endl; } ~X() { std::cout<<"Destructor called "<<std::endl; } }; int main() { X *x=new X; X …

Member Avatar for arkoenig
0
94
Member Avatar for massivefermion

First off I would like to second SasseMan's comment, for very high precision you need the GMP. Second your algorithms is going to kill you, you have 27111, copies of a function call on the stack, that is a block of memory for each function call. If you wish to …

Member Avatar for SasseMan
0
363
Member Avatar for Robbiedoes

Almost any algorithm that calculates Pi, [or anything else] is almost completely unlikely to need true-random numbers. What you normally need is certain properties of the pseudo-random number generator. For example, if you decide to calculate pi by simulating a 2x2 square (area 4) and a circle in that square …

Member Avatar for StuXYZ
0
205
Member Avatar for Ivanero

Unfortunately, the a pile of little but important numerical/coding errors. In arrMean, you don't actually get the wrong answer (I think), but you don't need to calculate avr until after the loop which adds up sum. arrMedium: [icode]if (middle % 2)[/icode] implies that the remainder of middle / 2 is …

Member Avatar for Ivanero
0
194
Member Avatar for EngSara

Looking at your code you are almost 100% creating the array incorrectly. And that may cause your problem. By the looks of it you want an 2d array of dimension d and delta. E.g. as if you had known d and delta at compile time you would have written [icode]int …

Member Avatar for shijobaby
0
183
Member Avatar for cclausen7

Can I just add, the code the OP has given will go horribly wrong at some point, since [icode]int random_card = (rand() % cards.size()) - 1;[/icode] can result in -1. That will be a very strange output, and some memory violation later, most likely resulting in a core dump. The …

Member Avatar for StuXYZ
0
74
Member Avatar for Lord_Migit

First off there is not enough code provided to actually compile this. However, if the only error was that you are getting array overrun I am absolutely surprised. The likely error is to do with deletion, and the use of bare-pointers in std::vectors. E.g. Consider struct Population. Now that takes …

Member Avatar for Fbody
0
678
Member Avatar for koolman123

Very sorry to tell you but the operator ^, which you use e.g. [icode]a2=a^2[/icode] is actually the XOR operator. ie. it compares the bits in the value and sets them according to the rule: [code] A B Out 0 0 0 1 0 1 0 1 1 1 1 0 …

Member Avatar for Fbody
0
223
Member Avatar for mskittles

Why don't you capture the salient information before the decision tree. e.g. [code=c++] struct TRes { double pTime; // time in seconds double yVal; // y positions A(const double Y) : pTime(time()),yVal(Y) {} }; // Note this becomes the fixed point TRes A(position); if (A.pTime<0.08) y1=A.yVal; else if (A.pTime<0.15) // …

Member Avatar for mskittles
0
81
Member Avatar for IS_student

Well first off, ALWAYS write a constructor, a copy constructor, an assignment operator and a destructor unless you are 100% absolutely certain you don't have to. If you have to think about it for even a second, write them all. Therefore, what happens, well size is not initialized. [nor is …

Member Avatar for IS_student
0
115
Member Avatar for crossbow25

Ok, first off, I REALLY hope this doesn't compile on VC++ because if it does then VC++ is adding a bracket In addition to not compiling to the standard. So what did you do wrong: You missed a } at the end of insertAfter in SinglyList.h. [The clue is that …

Member Avatar for crossbow25
0
263
Member Avatar for escortcosworth

[QUOTE=;][/QUOTE] Yes you should post life.h, well how can WE run the program, if you don't! -- and you want help with a runtime error!! You seem to have made a mistake in iterateGeneration(). You create an initial line text that has zero characters in it. Then you call findNeighbours, …

Member Avatar for StuXYZ
0
185
Member Avatar for cortez716

Well first off, you can choose to use the abs function, or not as you wish. If you want to use the abs function, then do this [code=c++] int a(93); int b(102); std::cout<<"difference == "<<abs(b-a)<<std::endl; [/code] Note, that you will need to add [icode]#include <cmath>[/icode] to your header. You could …

Member Avatar for StuXYZ
0
139
Member Avatar for aviles

You have made the classic error, that always seems to trip up beginners: That is if you use integers, then you get integer arithmetic : Consider this code: [code=c++] std::cout<<"1/4 == "<<1/4<<std::endl; [/code] That will print the unexpected value: 0. That is because 1 and 4 are both integers and …

Member Avatar for sfuo
0
181
Member Avatar for ana_1234

[QUOTE=;][/QUOTE] First off, yes you need to add a semi-colon. BUT in addition you need to note that GCD is a member function of Mixed and you have extracted the operator to an external friend function [more on that later]. Since GCD does not actually touch the class, or use …

Member Avatar for ana_1234
0
304
Member Avatar for crodriguez08

[QUOTE=;][/QUOTE] Fundarmentaly you have two problems , (a) that you are using the wrong algorithm, (b) that you have put the multiply operator as a friend method, and not a standard method of the class. [code=c++] class Polynominal { // stuff Polynominal operator*(const Polynomial&,const Polynominal&) const; }; [/code] is a …

Member Avatar for crodriguez08
0
2K
Member Avatar for SeanBlack0000

Well a little more information about the actual error message and the compile sequence would help. However, my guess is that you forgot to create an instance of your templated class. If you combine the code into one file, it works. [Not something to do other than for testing !!!!] …

Member Avatar for SeanBlack0000
0
214
Member Avatar for txmikey

Your problem looks like this line: [icode]scanf("%s/n", &ans);[/icode], since ans is a char. But you are reading it as a string. It is not. You perhaps want to do this [icode]scanf("%c",ans);[/icode]. The reason you get a crash, is that your text entry on the command line, is always at least …

Member Avatar for txmikey
0
208
Member Avatar for peterman.k

[QUOTE=;][/QUOTE] Ok in the first instance, using power is plain ugly and inefficient. The typical route for a polynomial in the positive sense, is to do something like this: [code=c++] int total(0); int xpow(1); for(int i=0;i<=degree;i++) { total+=coef[i]*xpow; xpow*=x; } [/code] You can also do it via an internal bracket …

Member Avatar for peterman.k
0
290
Member Avatar for vbx_wx

[QUOTE=;][/QUOTE] Firstly, obviously you can see that you don't need any template specialization for this example. But assuming that this is a example, let us see what you did wrong. It is just that sloppy practices that are allowed in non-template code are not allowed when dealing with templates. (a) …

Member Avatar for sandy#123
0
455
Member Avatar for Supriyo

[QUOTE=;][/QUOTE] I think the issue here is first to define "big". What does that mean to you, size of an OS kernel (2million lines) , size of a big application (500,000 lines) etc. That gives you an idea of how much time a rewrite will take. Next define the problem, …

Member Avatar for xtrmR
0
356
Member Avatar for keekee769

Your biggest problem here is that you (a) are trying to do evergthing at once, (b) cell broad.... You seem to have overlooked that if you have a cell board[SIZE][SIZE]; in your class definition, then you don't put cell in front of broad to used it. That is because your …

Member Avatar for keekee769
0
106
Member Avatar for shafik_s

Sorry, you haven't given us enough code here... We need to know what w, w_temp, h_temp get assigned to and how. If you can, post the fragment of code that they are set in as well please. I guess the you almost certainly have made a memory error with the …

Member Avatar for shafik_s
0
206
Member Avatar for sgw

Your problem is the assignment beyond the end of the array. You wrote this [icode]for (int i=0,j=0; i<row,j<5; i++,j++)[/icode] And that means : do i<row, ignore the result and test j<5. Therefore when you get to this [icode]m[i][j]=2;[/icode] you will definitely run m[4][4]=2; regardless of row. That means you assign …

Member Avatar for burcin erek
0
179
Member Avatar for Bri426

You have made mistakes in the code to do the largest AND smallest. First off, consider the test case of a user inputting ONE number only. Let us say that number is 10. Then your code will report that correctly for the largest BUT report 0 for the smallest. The …

Member Avatar for gju
0
1K
Member Avatar for ccube921

Not surprising because of a tiny bug in your loop: You wrote: [icode]for( int inte = 1; inte = 1; ) { } [/icode] Now a for loop has four parts, first an initializer, that goes from the first open bracket to the semi-colon. Second a conditional, that goes between …

Member Avatar for ccube921
0
290
Member Avatar for chinchan

Just coming back to the assignment of a value. I think this is a little verbose and confusing: [code=c++] if(rand() % 2 == 0) {value = -1;} else {value = 1;} [/code] Can we use the mathematical property that you can linearly map any number set to any other smaller/equally …

Member Avatar for Colezy
0
204
Member Avatar for jtylerboy222

Well done!! I don't think I have seen this error before!! What you have done is this: [icode]calc.Data[SIZE]=(24,21,43,24,43,31,41,42,34,41,45);[/icode] That is your error... You have use round bracket e.g. ( ). That is not what you wanted. So let us see what happens. You first evaluate the contents of the bracket. …

Member Avatar for burcin erek
0
170
Member Avatar for rena0514

Well I don't think this is going to be that welcome, so I sorry. First off I am not 100% you understand why you want to encapsulate something in a class. In this case, you want a fraction type, that behaves as if it is a standard type, e.g. a …

Member Avatar for StuXYZ
0
193
Member Avatar for TheWolverine

So you can't add a virtual function to the base class?? Then your only decision is to make BaseClass completely abstract, i.e a standalone instance is disallowed, or not. If you don't then think about adding the functionality to say class absFunc, which is inherited by BaseClass, then you get …

Member Avatar for TheWolverine
0
302
Member Avatar for bmos31

Well first off, this is good. Insert functions correctly, i.e. does indeed double the memory. It also copies (as far as I have tested) and sorts everything out. However, there is a subtle bug in erase that may hurt. You can get a memory violation. In your shift of moving …

Member Avatar for bmos31
0
1K
Member Avatar for Philosophy

Ok first off, welcome to daniweb, and thank you for writing a clear post with code blocks and not-too much and not too little code! Ok to your problem, you have unfortunately made a couple of logic errors. First, consider your loop, [icode]for(int c=2;c<= num;c++)[/icode]. This will test each possible …

Member Avatar for Philosophy
0
176
Member Avatar for tommyz4

Your problem is the equals sign (=) in your sort function. You cannot e.g. this allows [code=c++] Edge1 A(0,0,1); Edge1 B(0,0,1); // This should not be true to use the algorithm sort. sortFunction(&A,&B) == sortFunction(&B,&A) [/code] Also please use a managed point with vectors, e.g. boost::shared_ptr.

Member Avatar for Ancient Dragon
0
268
Member Avatar for frogster

The error is because this is a definition of a class. You have then put initialization code in it which is not going to work. You could do something like this: [code=c++] class box { public: int x; int y; XMMATRIX world; ConstantBuffer cb; // constructor box(int a, int b) …

Member Avatar for StuXYZ
0
122
Member Avatar for rt0026

First off please use code tags. Second, actually, this is quite a common and slightly difficult problem, and is 100% down to how numbers are represented on a computer. First off float is an inaccurate number, it cannot represent even simple number, like 0.2 without some rounding error, that is …

Member Avatar for StuXYZ
0
184
Member Avatar for effizy

My guess is that you have just landed on the chapter about arrays. I could tell you about the standard library, stuff like vector etc BUT I hope that is a later chapter. In fact, I hope that you do this exercise, three times or something like that, using different …

Member Avatar for effizy
0
127
Member Avatar for utkarsh009

First off C++ has evolved in the last 10 years, hence some changes. These changes were because of unforeseen problems that occurred. Let us start with why [icode]using namespace std;[/icode] and why you might not want to do that anyway. What happens in that there are a large number of …

Member Avatar for Ancient Dragon
0
221
Member Avatar for Eagles36

Two quick comments, AD is correct that you should have deleted line 4 in Fraction.h, [and that you have misspelled fractions in main()] (what it does is define the symbol hbg_cmpsc122 as and empty value. Therefore when you write[icode]namespace hbg_cmpsc122 {[/icode] you have effectively writen [icode]namespace {[/icode]. This is why …

Member Avatar for StuXYZ
0
178
Member Avatar for codergal

I am answering this simple because I can't believe that anyone teaches a class without giving some feel for why. Your code introduces that basic concept of a 2D array, ie. having two coordinates. [The idea can be extended up to many dimensions e.g. 3 or 4 etc.] So when …

Member Avatar for StuXYZ
0
165
Member Avatar for .:Pudge:.

Well first of if you need random numbers to actually compute something else, don't use rand() for anything, it simple isn't random enough. [Basically, rand() has very poor lower bits.] e.g. see [URL="http://www.eternallyconfuzzled.com/arts/jsw_art_rand.aspx"]http://www.eternallyconfuzzled.com/arts/jsw_art_rand.aspx[/URL] So that leads us to looking for a good [enough] random number generator. The current defacto standard …

Member Avatar for StuXYZ
0
383
Member Avatar for alcx88

Nearly working but you have a small tiny problem with your code. In C (and C++) your simple char strings need to be terminated with the value 0. [That is 0x0 and not the character '0']. You didn't do that, and you don't need it for the second loop that …

Member Avatar for chiwawa10
0
96

The End.