2,712 Posted Topics
Re: Whats the error message? And all this math can be avoided by using string. [code] void printN(char ch, int N){ while(N--) cout << ch; } int main(){ string num = "40587"; for(unsigned i = 0; i < num.size() - 1; ++i){ if(num[i] != '0' ){ cout << num[i] << "x1"; … | |
Re: From what I hear, [URL="http://qt.nokia.com/"]QT[/URL] is good. | |
Re: 1) Program in C++ not C. 2) Second : [code] //copy linked list while(curr != NULL){...} //... copy = curr [/code] that exits only when curr is NULL right? So when you set copy = curr, you are setting copy to NULL essentially. Thats why your last loop isn't getting … | |
Re: Your function delcared with a return type of double should return a double. Here is what you should do : [code] double Circle::getArea(){ return _area; } double Circle::getCircumference(){ return _circumference; } [/code] And your area and circumference variable should already be calculated in your constructor like so : [code] Circle::Circle(float … | |
Re: What lines does it crash in? What is the output before it crashes? What does the file look like? | |
Re: Is listNode a even template class? I ask because of this contradiction statements : [code] listNode<LISTDATA>* [/code] vs [code] listNode *tempNode = NULL[/code] | |
Re: You should [URL="http://en.wikipedia.org/wiki/Equations_of_motion"]newtonion equation of motion[/URL]. In all your code might look something like so : [code] Cannon cannon; cannon.add( Ball() ); if(keyLeftPressed){ cannon.decreaseAngle(); } else if(keyRightPressed){ cannon.increaseAngle(); } Vector initVelocity(5,5); if(keySpaceBarPressed){ cannon.shoot( initVelocity() ); } //... void Cannon::shoot(const Vector& initVelocity, int dt = 1){ //x = initVelocity *dt + … | |
Re: Actually, the code suggested to OP isn't quite good. As you guys probably know the random distribution of rand() is one of the top, but usually is good enough. But by using the modular arithmetic, especially when the range is low, causes the random distribution to be even worse. So … | |
Re: In your inList function you are not moving your ptr. You do not even need the index and mySize. Here is something to get you stared : [code] bool isInList(const ElementType& elem){ Node *curr = head; while curr is Not NULL{ check if curr has the elem, if so return … | |
Re: This what you should be doing: [code] int main(){ ifstream fileInput("LinearEquations.txt"): if(!fileInput) return -1; //error //get the n value int numOfMatrices = 0; int squareSize = 0; fileInput >> numOfMatrices >> squareSize; std::vector<Matrix> matrices(numOfMatrices,Matrix(squareSize,squareSize) ): //read in values here in a while loop } [/code] | |
Re: >>[B]In general, a function can not modify the value(s) of the argument(s) used to call it[/B] You say that then you go ahead and disprove that! Lol, what a contradiction. @OP: some helpful things : 1) If you have a choice, use reference over pointers 2) If you do not … | |
Re: Make this change : [code] #include "Product.[COLOR="Red"]h[/COLOR]" #include <string> #include <iostream> using namespace std; int main() { //... } [/code] | |
Re: [B]>> for(int i = 0; i [COLOR="Red"]>[/COLOR] pos; i++)[/B] | |
Re: or if your allowed to : [code] int sum = std::accumulate(resistors.begin(), resistors.end(), 0); [/code] | |
Re: Just set the y-coordinate to 0. And make x-coordinate whatever you want. | |
Re: If you can you should really use something like std::map for this. For example, doing something like this is a little better: [code] #include <map> #include <iostream> #include <cctype> #include <fstream> using namespace std; class AsciiCharacterCount{ public: typedef std::map<char,long>::const_iterator constIterator; private: std::map<char,long> asciiFreq; public: void update(char ch){ if(isalpha(ch)) asciiFreq[ch]++; } … | |
Re: Here is something to get you started : [code] #include <iostream> using namespace std; int main(){ } [/code] Now I am not sure about the specification. Do you ask the user to input a range of Resistor values and compute its parallel or series value, or is it just 2 … | |
Re: >>[B]Rock(enum RockName)[/B] You want : [code] Rock(RockName rockName){ myName = rockName; } [/code] | |
Re: Make your code easier by declaring the function as a boolean function instead of having a found flag. Thus after that change it becomes seemingly simple : [code] bool MyBS::search(const Node* root, int key){ if root is null return false; else if key < root.key search(root.leftChild,key); else if key > … | |
Re: Also whats with pointers? Be smarter about your code and use reference or smart pointers if you have to. | |
Re: Also, if the numbers aren't too far apart, then what you could do is get the average of the 3 numbers, and find the number that is closest to the average. This will work long as the number aren't too far apart, like 1,2,100; for example if the input was … | |
Re: The second one would probably use less memory. And normally you would use the second one unless you have a compelling reason to use the first. | |
Re: [code] try { ... throw("error") } catch { const char *err) [/code] | |
You know when I was in nepal, all I worried about was school. I lived and ate for school. But it was not out of interest, it was out of the society. The society, specifically my mom, was pushing me/us to eat and sleep academia. Now thats exactly what I … | |
Re: Your code to delete linked list should look like this : [code] linkedList::~linkedList{ Node* current = head; while(current != NULL){ move(current,1); //move current to next node destroy(head); //delete head head = current; } } [/code] | |
Re: 1) Forget the pointer crap, don't use it unless you really have to. Or if this is for practice then its ok for now. A easy way to do it is like so : [code] template<typename T> T getInput(const string& msg){ cout << msg ; T var = T(); //check … | |
Re: This should help [code] if(num < 0){ /* the number is negative */ doStuffWithNegativeNumbers(); } else{ /*The number is not negative */ doStuffWithNonNegativeNumbers(); } [/code] | |
Re: Here is something to get you started : [code] int main(){ const int MAX_WORD_ALLOWED= 1000; //1000 words allowed const int MAX_WORD_LENGTH = 256; //words length cannot exceed this amount char listOfWords[MAX_WORD_ALLOWED][MAX_WORD_LENGTH] = {}; ifstream fileInput("test.txt"); unsigned wordNumber = 0; while(fileInput.get(listOfWords[wordNumber++],MAX_WORD_LENGTH) && wordNumber < MAX_WORD_ALLOWED ){ //blah blah blah } } … | |
Re: First this code : [code] class TitleExcept: public exception // Class for handling errors about the book's title. { virtual const char* what() const throw() { return "Please enter the book's title using only letters.\n"; } } errortitle; [/code] there are a few problems with it. The function what() should … | |
Re: The size of myList is found by using the sizeof() operator. It should be a multiple of 4 bytes. | |
Re: [code] struct Info{ string name; int age; Info(const string& name = "", int age = 0) : name(name), age(age){} }; void add(node* & x, const Info& information) { if( x== NULL ) { x= new node(information); } else if( information> x->data ) { add( x->right, information); } else { add( … | |
Re: >>5A72 + 4573 = 9FE5 In an algorithmic way, you can do something like this : [code] string hex1 = "5A72"; string hex2 = "4573" string res; assert(hex1.size() == hex2.size()); bool hasCarry = false; for(size_t n = 0; n < hex1.size(); ++n){ string hexValues = "0123456789ABCDEF"; char addedValue = (hex1[n] … | |
Re: They are just typedefs probably. [code] typedef int INT; typedef float FLOAT; [/code] so INT and int are the same and FLOAT and float are the same. Its just a different way to tell the compiler the data type. | |
Re: Hints : 1) Use a forloop to sum values? 2) Use explicit formula to calculate sum of even integers? 3) Use standard library instead of writing forloops? | |
![]() | Re: Why don't you seperate the randomString(HexOrDecOrOctal) function from the class, and make it a regular function. Like so, [code] MyString genRandomString(int radix){ validate(radix); //... } [/code] No need for enums or IDs, just pass in the base, and the function returns something that has to do with that base. |
Re: To load it when the windows start, you can port the .exe into the directory where the startup programs are located. That way, whenever you start your computer, your program gets executed in the background, just like other startup programs. As for the rest of your question, you need to … | |
Re: How do you know if its working correctly? It looks like a problem with improper initialization. How about you post more code so we can take a look. | |
Re: >>[B]void TimeChild::setTime(miltime)[/B] should be [code]void TimeChild::setTime(string miltime)[/code] >>[B]void TimeChild::setInt(v)[/B] should be [code]void TimeChild::setInt(int v)[/code] | |
Re: [QUOTE=lapunluyang;1325270] 'Is C++ the King of all Languages, it will always be around and is the best programming language ever made.' Well, that was a giveaway. I answered 'YES'. Well I got it wrong.[/QUOTE] Can C++ do graphics? Can C++ do networking? Does C++ contain every data structure that one … | |
Re: If possible, header should contain a skeleton for the desired Object. For example a header might contain a class skeleton named Car, and you might define the actual implementation of Car in a different .cpp file. Another example, you might declare some functions in a header, but do the actual … | |
Re: @OP: Are you allowed to do this : [code] struct StudentInfo{ string name; int id; //more stuff if you need it }; struct StudentNode{ StudentInfo data; StudentNode *next; StudentNode() : data(), next(NULL){} StudentNode( const StudentInfo& info, StudentNode *pNext = NULL) : data(info), next( pNext){} }; class StudentList{ //...details public: void … | |
Re: >>test.setValue(value); [code] test[0].setValue(value); [/code] I'll let someone else criticize your code. Feel too lazy right now. | |
Re: Perhaps, one of the faster way to do this is like so : [code] template<typename ForwardIterator> void makeUnique(ForwardIterator begin, ForwardIterator end){ std::sort(begin,end); std::unique(begin,end); } [/code] | |
Re: Is the format always going to be like this : [code] string eq1 = "2A + 3B = 4"; string eq2 = "3A - 2c = 6"; [/code] is there any multiplication or division involved? How about parenthesis ? | |
Re: Another option: [code] template<class T1, class T2> void foo(T1 a , T2 b){ cout << "default\n"; } template<typename T1> void foo(T1 a, T1 b){ cout << "specialized\n"; } [/code] | |
Re: >>LINK : fatal error LNK1561: entry point must be defined Thats usually means that you haven't defined main. What type of project did you create? What type of IDE? | |
Re: Can you post your question a little more clearly with some context? |
The End.