118 Posted Topics
Re: you would want two methods: 1st method get all of the sub strings of a length for each input 2nd method find the unique strings of a length [code] #include <vector> #include <string> class sub_string_counter() { public: sub_string_counter(); std::vector<std::string> get_substrs(std::string & from, int len); int unique_strings(std::vector<std::string> &vs); } [/code] the … | |
Re: open is used by programs such as word which is multiple documents and what you are describing would require the intialisation method that could call open() I think it is normally [icode]onInit()[/icode] but you need to be confident that your design of saving the files this way is the right … | |
Re: aPure virtual function needs to be defined in the derived class so you parent needs to have a function called DOB etc that is the same signitaure as the virtual method. [code] class base1 { publc: base1(); virtual int get() {return 0;} virtual int get_int() = 0; } class test1 … | |
Re: Good that you have the project working but with xp the rel file path should be possible. I though I'd mention this just in case you are having a problem that I encountered: Are you using Norton Antivirus if so make sure that you disable their automatic recycle bin. It … | |
Re: I am not sure that you necessarily want to use [icode] malloc[/icode] or [icode]#define[/icode] but there are a couple of obvious errors in your code you have a size mismatch DV is 4 double * where as you try to set it to a random pointer of size 50; What … | |
Re: the `[]` only work if string is defined string has useful methods such `replace()` `find()` if you read up on the methods you will find cleaner solutions but at first glance I think your error is here output += alpha[t] > `output[r] = alpha[t];` | |
Re: std::string is just a wrapper around a char * and from reading the function you do not want to change it back to char[] anyway If you must you would still go via std::string [icode]str.c_str()[/icode] converts a string back to the array pointer which is what you are doing when … | |
Re: to save the data you need to save to a file this uses [icode]#include <fstream>[/icode] and [icode]std::ofstream fout[/icode] there are plenty of articles on this now you need a char * and know how many char need to be reserved if you want to save directly. now you also need … | |
Re: It is not constructive to keep posting what is effectively the same question in new threads. What you should do is work out what precisely you are trying to achieve and why? If you feel that you have solved the first issue and moved on to the next mark the … | |
Re: other than your main function not having a return 0; There isn't an obvious error on your merge function You have not got any reference to a sort function in your code though. | |
Re: I don't use cin very often the easy solution would be to read in your input as a string variable and then parse the line. So you could take in a string and find a char say ':' and then you would have to convert the two sub strings into … | |
Re: The error that you are getting is complaining that there is no definition of a copy constructor. Yet normally this is created without you explicitly requiring it. If I remember right your error is down to using fstream as a member variable I don't think that it is an object … | |
Re: There are a huge amount of resources on minimising errors. Designing the idea before you charge in for classes is a good idea. For this case the use of the word const would cause the compiler to pick up the error [code] void set(const int x); [/code] another common mistake … | |
Re: It is not entirely clear what problem you are having from your description. I assume that this is not just a memory leak that has arisen in your code from calling new() without delete. But from a problem I had recently with new() giving a bad memory alloc exception. I … | |
Re: I assume that your code outputs "cannot open file" and does not crash it is normally a good idea to put markers next to chars when outputting as there are many chars that appear as space and sometimes buffers hold onto return characters for example. I normally use is_open() method … | |
Re: as with any programming maths problem first you need to know roughly what you are trying to by hand. Another important factor in this instance is why you are doing it. If it is just to find the answer then just put the equation in a function. But if it … | |
Re: Why not just iterate through the vector once you have your test condition is_odd() this has to be tested once per element if as you say it is more complicted. then add to v1 if true and v2 if false an example using std::vector<int> sorting on the contents rather than … | |
Re: It sound like quite an ambitious project if you don't have an idea of what algorithms to use. You need to give a bit more information What kind of recognition : Camera footage - > simple recogniser or machine learning techniques are possible Or are you talking about distinguishing between … | |
Re: [QUOTE=lamphan;1149830] [CODE] for (int i=0; i<bit; i++) { std::cout << bin[0]; // should be 11000 } [/CODE][/QUOTE] the bin[0] will always just give you the first digit I expect you meant [icode]std::cout<<bin[i];[/icode] | |
Re: [QUOTE=Kikazaru;1149219]Thanks for the answers. your comment that I might save a few nanoseconds is confusing. It seems to imply that some computation time might be saved. [/QUOTE] You still have to type [icode]const[/icode] just typing this once at about 0.4 seconds = 400, 000, 000 ns. You rely on the … | |
Re: [QUOTE=Ancient Dragon;1149644][URL="http://lmgtfy.com/?q=socket+programming+tutorial"]google will show you lots of information and tutorials[/URL][/QUOTE] I've found google often to be useful for programming 1 - type the problem into google 2 - find a link to daniweb 3 - normally I find a post on the subject from ancient dragon ;) Sockets is something … | |
Re: I take it that this is your first time using classes the first error tells you that there is no definition to the constructor which it needs to create the object, as this can be in a .cpp file the compiler won't complain but the linker will! so somewhere you … | |
Re: fstream is how you read information to and from files and the syntax is messy but you will find their usage in lots of places to read in from a file [code] #include <fstream> //needed for if stream class #include <string> int main() { //std is a namespace saying where … | |
Hi, When using Microsoft Visual Studio, building in release the code just hangs and fails to execute but with Debug it builds and runs to the end. And I don't see why there should be a difference. I did a shutdown then clean and a rebuild of solution but the … | |
Re: To go from the right hand side index to the left handside index the maths computationally is as follows [code] int cycle_rhs(3), cycle_rhs(6); int temp = x/cycle_rhs; //this gives a floor so no remainder int temp2 = cycle_lhs * temp; /* 0 , 1, 2 ->0 3, 4, 5 -> … | |
Re: I mis-interpretted your question intially Are you trying to make a self regitering class in which case you probably want a vector of pointers not objects The problem is where do you define gpGlobals when you create an instance of a class the template has to be defined now as … | |
Re: I did not spot anything obvious but in the main line 36 your while looks a little dangerous [icode] while(que.size() != 1)[/icode] I would have expected [icode]while(que.size() > 1)[/icode] as you are poping off two values. I suspect that changing this will have no effect When you create your new … | |
Re: [QUOTE=TheWolverine;1129123]Hi all, I am just getting into the world of OOP and I'm not totally sure in what situations it's better to use objects and when it's simpler to just revert to arrays. [/QUOTE] For scientific code it is normally best to ensure that the code is clearly readable, and … | |
Re: Following-on from some of your comments in the thread that has been closed on this some basic things to note: This is not a standard way of dealing with matrices and the name of the class is misleading. What is happening is that the data is being logged as a … | |
Re: Identify a project that is of interest to you. Do you have any boardgames that you like the advantage of picking such a project is that you can test that your design ideas are implementable by making test versions of some of the design. This will not be a waste … | |
Re: To test getshape() will take for ever if you don't get it right what you need to do is to test your function first for ideas that you can check by hand. 1000*1000 inputs will take a long time so use smaller MAX values if you need something this big … | |
Re: First at some point you need to add the method for getting the user's input. Your if loop is wrong because you should be using [icode]==[/icode] to see if something is the same as something else and this gives either [icode]true[/icode] or [icode]false[/icode] and if it is true the if … | |
Re: I guess this is another thread that will be closed down and pointed to: [url]http://www.daniweb.com/forums/post1138190.html[/url] Which is why this looks familiar :) [QUOTE=jonsca;1138189]Part of the problem is this line in getVal: [icode] for (j=0;nent--;j++) [/icode] [/QUOTE] | |
Re: don't forget second largest value can be the same as largest value so you will want to count how many times the first value appears in the second while loop too. | |
Re: look at line 89 [icode]m[i,j][/icode] I expect your compiler is complaining that this is undefined you need to define how to set_val in a matrix I think you are missing a few storage so [icode] double val = m.get_val(i, j) + n.get_val(i,j); m.set_val(i, j, val); [/icode] is the approach you … | |
Re: [QUOTE=pinsickle;1137172][CODE]current = queues[i];[/CODE] our old object files so I can't put any kind of access method in singilyLinkedList [/QUOTE] When reusing old code it is still permissible to extend the class as long as the extension does not alter any existing behaviour and the method is something meaningful to the … | |
Re: [QUOTE=PDB1982;1136789]I am trying to start the odometer reading at 0 to start with, but I want it to increase everytime the user inputs MilesDriven. I can't seem to get it to work...any ideas? [/QUOTE] 1st Do you know what a constructor is in you class add in the public [icode]Odometer();[/icode] … | |
Re: [QUOTE=mitrmkar;1135950]Why would you want be doing that kind of thing? [/QUOTE] Good question it looks a lot like a HOOK and dll injection example piece of code. Although, the fact I recognise it is probably not a good thing ;) | |
There is probably a joke in the comment that I am missing but this post is going to give the design approaches to solving the problem posed by FirstPerson in his signature: find the last ten digits of x^x (x raised to the power of x) for all the positive … | |
Re: There are good general prinicples of OO you are adopting. And when your code gets long you want to test things a function at a time. I think there is a potential issue with the player choose function. you might find it simpler to have a function to process the … | |
Re: well you have found the fibonaci series of numbers with a formula if you place this code into a function to find the fibonaci numbers. Here are two approaches: 1 - write a function that stores all of the fibonaci numbers between a lower and upper limit. this would best … | |
Re: One point that I thought I ought to bring up is that if you have a non integer number such as a decimal you can still find the digits but the stop condition is tricky so while [CODE] int i(142), n(10); int remainder = i%10; i = (i - remainder) … | |
Re: There are a few problems with your code first off it is a good idea to work out the logic and method you want on paper first because I suspect that the book method has resulted in you using a method that has confused you a little log10(1) == 0 … | |
Re: Even if you call the system time to do it every 30 minutes requires a trigger device and as such requires some method of checking when the time changes. If you have an external program that sends a message this will still in effect be slowing down the running of … | |
Re: Random numbers need to use srand( ) otherwise you get the same number each time there are a few posts on this and a quick search will show you some demo code you should get the system time and call srand(time); | |
Re: What is it that you want the system to do when [CODE] #tiered test a 005 b 04 a 5 b 3 a 0005 b 5 #no spaces between number and letter y 000a y 00091 #spaces b 5 abc b 5 abcd b 5 abc [/CODE] ? As I … | |
Re: Assuming that your code was showing multiple files including the same file indirectly by adding the preprocessor line to the top of all of your .h files [CODE] #pragma once [/CODE] you can ensure that no single file includes the same file twice. | |
Re: [QUOTE=Fbody;1131574]It's difficult for me to explain, I'll try to, but perhaps someone else can explain better. [/QUOTE] ditto :) When you say: [icode]int x;[/icode] or [icode]alpha my_alpha[/icode] The computer has to create the space in memory that it needs to store all of the information about the variable. So for … | |
Hi I have what at first seemed to be a very simpe problem: I have a Microsoft Package that requires me to use nmake to make a lib file. I am unfamiliar with make files as I use visio and XP. Now I had to move somethings due to restricted … | |
Re: [QUOTE=wolfkrug;1130769]Wow yeah that fixed it. Thanks, now I need to figure out why that works.[/QUOTE] I am probably missing something but your while loop on line 17 is this the logic you want? if you hold at say 70 and the computer rolls a 1 doesn't that mean that you … |
The End.