565 Posted Topics
Re: Introductory Note: You have not written [icode]std::vector<double*> S;[/icode]. Which is a completely different discussion. This is often frowned on because it is SO easy to mess up, the memory [de]allocations. Ok: In the general sense it is perfectly fine to have a point to a vector, or any other stl … | |
Re: First off you haven't give us Rect.h, and that is important. However, guessing that Rect.h looks something like this [code=c++] struct RectStruct { float x; float y; float height; float width; }; [/code] First off, I really like what you are trying to do with this code, you have almost … | |
Re: The first thing that is wrong is that you have written this: [icode]p[i]=str[strlen(str)-i];[/icode] Now apart from re-using strlen(str), which it would have been better to put it in a varaible (although my compiler nicely optimized it out). What happens when you put i==0 into that statement you get:[icode]p[0]=str[strlen(str)];[/icode] and that … | |
Re: Well assuming that you have a string and you want to change it, you can used this [code=c++] std::string test="abcde"; test[4]="X"; std::cout<<"Test == "<<test<<std::endl; [/code] The string class provides the operator[] which allows you to examine and change each letter in the string. That along with a loop will allow … | |
Re: I can guess that isn't going to work well!! You really don't need to include any cxx files in your .h files. [With the possible exceptions of some template classes but even then you should avoid it]. First: Small point , don't use `#include <file.h>` for your files, the < … | |
Re: The quickest way is to put a setprecision into the stream: [code=c++] InputOutputStream>>std::setprecision(12)>>TotalOutputString; [/code] (You may need to add an [icode]#include <iomanip>[/icode] to your file as that is the place for the definition. You don't need the std:: if you have the horrible, [icode]using namespace std;[/icode] line). That still means … | |
Re: Your problem is a combination of reverse and the way you call reverse. You have reverse (char*), as taking a char pointer. That is an area of memory that can be modified. However, when you call it, you pass a constant string. C++ represent that memory as non-mutable, i.e. It … | |
Re: First off I assume that this is a course work/self-learning problem, otherwise, just use a pre-existing library routine. [GSL/ACM/G4 and others] The usual place to look for maths stuff is the wolfram site and you get: [URL="http://mathworld.wolfram.com/QuarticEquation.html"]http://mathworld.wolfram.com/QuarticEquation.html[/URL] Ok, that takes you through the solution of both the real and complex … | |
Re: Not 100% sure what you are after, so I am going to re-iterate your problem as I see it then you can correct me and (hopefully) we can all get closer to the exact problem you are after: You seem to have several problems that need to be separated out. … | |
Re: Sometimes the best way to look at a problem is to reiterate it. So here goes. Feel free to ask questions about this comment. The objective of the code is to write "Hello, NAME" were NAME is replaces with whatever you say your name is. However, it is to have … | |
Re: Your problem is really in replaceString. [code=c++] replaceSubstring(string1,string2, string3); } void replaceSubstring(string string1, string string2, string string3) { int spot1; int spot2; spot1 = string1.find(string2, 0); spot2= string1.find(string2, 3); // From original string string1.replace(spot1, (spot1 + 3), string3); // Now original string is NOT orignal length: // NOTE: Replace(position, length_to_change … | |
Re: Just to ask, you say that it is for a paper in ACM and IEEE. Any of those journals have a fairly high entry level, they are refereed and some of them have a very high rejection rate. That seems a much bigger problem the how your program was written. … | |
Re: Well I am going to try to give you part of the answer, others (more knowledgeable) will hopefully fill the details in. I am going to assume you are talking about class initializers. So let us do this via examples, so consider: class A { const int vInt; // Must … | |
Re: Ok you seem to have made a number of mistakes that stem from a simple mis-understanding of how arrays and pointers interact. So I am going to go through the basics of this : First off an array as defined by [icode]int array1[5];[/icode] reserves a block of memory that is … | |
Re: There are many problems with this code: But the bit that should be stopping you compile and debug it is in the call: [icode]output_result ('largst', a, b, c);[/icode] You see two problems first that single quotes are used for a single character e.g. 'x' etc. You need a string. So … | |
Re: You hopefully have read the rules, no homework help unless you show some effort. This is an easy algorithm, you just implement. You are going to need some simple variables, the count, the previous letter, the current letter and the output string/stream. Loop over the input string/stream and compare the … | |
Re: I first off this is an excellent exercise. If you are doing this yourself, well done, if you have a teacher/class, your prof. certainly has found an excellent problem. So why do I think this is so good, what happened here is that you have designed two classes that can … | |
Re: Couple of small points, since FirstPerson is correct. You should not be using pointers in your quaternion class, but I believe that FP has made a tiny tiny mistype: Conjugate of a quaternion is normally [code=c++]# void CQuaternion::conjugate()const { return CQuaternion(w,-x,-y,-z); // w is not multiplied by -1 here. } … | |
Re: t: Why not convert the file into a ordered vector/list of time:count, using a structure to represent the time. e.g. [code=c++] struct Item { int day; int timeSec; // Number of seconds from midnight int count; }; [/code] Then you can use a std::vector of Item, which you can defined … | |
Re: First off the most scary thing that I see is the global variables defined just below your line using namespace std;. Arrrhh.... don't do this, they are not needed. Next reduction is missing a few brackets. Yes gcd CAN be zero if say numerator and denominator are 1. Now the … | |
Re: Assuming the problem is slightly more general you have a list of number e.g. `int items[]={4,4,4,4};` and you have a target number T. Now you need to clarify the rules: (i) are brackets acceptable: e.g. the given solution (4 / 4 + 4 )* 4 has to have brackets to … | |
Re: I believe that sfuo is correct that the problem is you lack of cast to a double The reason that you had the original problem was that 5/9 is integer/integer. In integer arithmetic you don't change type and an integer is returned: e.g 5/9 is zero. Additionally 8/9 is zero, … | |
Re: You are indeed correct things are not working correctly: You problem is simple, you have forgotten to use a virtual destructor in baseClass. All you have to do is add [icode]virtual baseClass() {}[/icode] to your baseClass and it will work. However, please add virtual to your destructors of both your … | |
Re: The problem may be that you have forgotten to remove the skipws (skip white space) flag from the stream. e.g. [code=c++] std::cin.unsetf(std::ios::skipws); [/code] If that is the case, then please also remember to return the stream to the state you had previously. This is facilitated by setf() and unsetf() because … | |
Re: "nameofbinary" is absolutely anything that you care to type. e.g. image we are making a program that I want to call "sumNumbers". You have written some c++ in a file called firstProgram.cpp and you want the output to be called sumNumbers. you would do this [code] g++ firstProgram.cpp -o sumNumbers … | |
Re: I feel I have a slightly different perspective on this. Yes learning C++ itself will not make you a cool GUI program, but the library routines can be called from C++. However, the libraries keep changing, that is because we have new hardware, better algorithms, different OS which to build … | |
Re: Your mistake is this [code=c++] int random=(rand() % 20)+8; strength=random; dexterity=random; // copy random again. [/code] Random is copied twice. Try this [code=c++] random=(rand() % 20) +8; strength=random; random=(rand() % 20) +8; // GET A NEW VALUE FOR RANDOM dexterity=random; [/code] Obviously you can remove the intermediate variable (random) e.g … | |
Re: Ok First off, there are two while constructions in C++ , [icode]do { } while(condition); [/icode] and [icode]while(condition) { }[/icode] There fore you don't need the do after the welcome statement. In is current form this program should not have compiled. You have written [icode] if(rNumber = uNumber)[/icode] This is … | |
Re: Your problem looks like a lack of an extern + a scope error Let me explain. You seem to "effectively" want to do this [code=c++] int main() { int var(10); // this variable is local to main NOT the program } void foo() { int a=var; // THIS will not … | |
Re: The problem is your copy constructor, for client. So let us see how we get to that : Line 5 of youf first program uses this: [icode]vektori.push_back(Client(account, firstName, lastName, balance));[/icode] This constructs a client object and copies it into the vector. With this line you also call [icode]Client(const Client&);[/icode]. At … | |
Re: If the output is to the console/terminal. The you can do this [code]./program input_data > outputFile.txt 2> errorFile.txt[/code] Note that I created and output file for the normal output and an error txt file for errors. You might want to put them all together with [code]./program input_data > outputFile.txt 2>&1[/code] … | |
Re: Ok there are two types of problem here: (a) that you have made errors in your code that result in you getting the wrong answer, (b) I really don't think you know mathematically what you want to compute. I can address (a) easily and I will hint at (b). Let … | |
Re: Well first off do you have any code/pseudo code. I am surprised that you are going for pointers? (have you inherited from a shape class? and want to use a generic touching/intersect etc. However, that way you would not have onCircle but onShape. I am not going to do this … | |
Re: Several things come to mind: So I will start at the end of your code. First is that [icode] (!(j % 10 )) [/icode]. Is this true if j = 0. Obviously that causes one of your output errors. Now consider the getline function. You have told it that the … | |
Re: The problem is the [icode] while(true); [/icode] iine and the } on the line above. [lines 22,23] The while loop does not allow you to go into the switch statement. Therefore to fix it just move it to the line above you [icode]return 0;[/icode] (between line 93/94). | |
Re: Two problems (initailly). First problem: You are expecting two integers in the first line of the file. I modified your file to have [icode]6 5[/icode] as the first line. Second problem: You are reading double precision number into and integer array. Not good. So remove your definition of num_array, and … | |
Re: Yes: The 2001 ANSI standard added the erfc function ( 1-erf(x) ), for float/double/long double. Not 100% sure when that got built into most version of cmath and math.h. But by now almost every compiler should have it, and should have had it for nearly 8-9 years. Certainly it is … | |
Re: Can I add two more comments to this excellent post. When you have the first answer, you may well be asked a few more detailed questions about your problem. Please try to answer them. Even if you are certain it is not the problem [you can explain that if you … | |
Re: Sorry but there is insufficient code here to run, test and generally play with, a bit more of a working example, e.g. something which runs would have been good. But there are several things that might be a problem: (a) Given the lines [icode]a=(s_axis_1+15)*10;[/icode] and the similar one for b, … | |
Re: Well I can't repeat the first error. the board looks fine. The problem with the second error is a simple mistake, so no problem. You wrote this [code=c++] char coordinate[2]; cout << "What are the coordinates of the square: "; cin >> coordinate[2]; // ERROR HERE: [/code] You input the … | |
Re: First of all I have to agree with firstPerson's advice. Second PLEASE don't use variable names like [icode]exp[/icode] and the do maths operations. You are bound to at some point want to use the maths library (cmath). Then you are in a mess!! Finally why not include the addition and … | |
Re: [QUOTE=;][/QUOTE] I am going to take a long long short here as to what is wrong; You write [code=c++] class Vector3 { float y, z, x; }; [/code] Note the order!! That worries me (slightly) since you are doing a copy construction e.g. your line [icode]result=pre_result;[/icode] will actually call the … | |
Re: You mistake is here: [icode]dynamicArr ( dynamicArr& arr) {myLinkedList(arr.data);}[/icode] What is happening is this. You are calling the copy constructor that MUST construct everything in the class BEFORE it gets to the part in the { }. In the { }, you construct a copy, but then it goes out … | |
Re: Ok -- First off a little help with how big / and how much cpu you have available [and memory] would have helped. OS and compiler would be useful information. however, if you get to 16minutes on anything remotely modern and anything remotely under 250,000 lines of total code + … | |
Re: Looks like you have given us the wrong class. Your problem seems with arrayList not Sort. Which if you add a quick test, works. | |
Re: [QUOTE=;][/QUOTE] Ok I will make some very general comments about the structure of code: First off: Always program to the smallest unit of work that you can do. i.e. don't try to factor your number / add to an array and print in one go. Start with getting one part … | |
Re: Can I just comment (a) Jonsca is correct, you are going to have to define a tolerance and (b) it is going to be lot easier to calculate the cos(angles) of the triangle and go from there.. Also you cannot do this [icode]a==b==c[/icode] It compiles but DOES NOT do what … | |
Re: [QUOTE=;][/QUOTE] I think if you expect us to look at your homework, you should explain how your got to your answers. Many of these questions are a bit vague and deliberately ambiguous , e.g. question 4. Since there are only two points per node, you only update two pointers. Anyway, … | |
Re: There are several ways to do this: Everyone prefers something slightly different, and a fair bit depends on your environment, Linux, windows, embedded etc. But here are a few. First : Debugger route. The quickest way is to add a [icode] try { } catch(...) { // stuff here } … | |
Re: [QUOTE=;][/QUOTE] Your real problem seems that your algorithm is too unclear. I couldn't code this up since I have no idea what is wanted and I think that is your problem too. So what you are going to need to do is make this much more concrete: The quickest way … |
The End.