2,712 Posted Topics

Member Avatar for restrictment

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"; …

Member Avatar for burcin erek
0
171
Member Avatar for Nathaniel10
Member Avatar for usagi
0
114
Member Avatar for corby

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 …

Member Avatar for chiwawa10
0
196
Member Avatar for jtylerboy222

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 …

Member Avatar for jtylerboy222
0
105
Member Avatar for Nathaniel10

What lines does it crash in? What is the output before it crashes? What does the file look like?

Member Avatar for Nathaniel10
0
157
Member Avatar for daviddoria
Member Avatar for badllama

Is listNode a even template class? I ask because of this contradiction statements : [code] listNode<LISTDATA>* [/code] vs [code] listNode *tempNode = NULL[/code]

Member Avatar for Valaraukar
0
229
Member Avatar for umairqureshi_6

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 + …

Member Avatar for umairqureshi_6
0
518
Member Avatar for chinchan

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 …

Member Avatar for Colezy
0
204
Member Avatar for bmos31

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 …

Member Avatar for bmos31
0
1K
Member Avatar for dmh22

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]

Member Avatar for dmh22
0
129
Member Avatar for dasari.prasad

>>[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 …

Member Avatar for ben1Greer
0
430
Member Avatar for YingKang

Make this change : [code] #include "Product.[COLOR="Red"]h[/COLOR]" #include <string> #include <iostream> using namespace std; int main() { //... } [/code]

Member Avatar for mike_2000_17
0
749
Member Avatar for bmos31
Member Avatar for cogitoergosum18

or if your allowed to : [code] int sum = std::accumulate(resistors.begin(), resistors.end(), 0); [/code]

Member Avatar for mrnutty
0
204
Member Avatar for plex_Rominus
Member Avatar for mrnutty
0
37
Member Avatar for PrOwr!+3r
Member Avatar for emko

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]++; } …

Member Avatar for mrnutty
0
258
Member Avatar for cogitoergosum18

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 …

Member Avatar for mrnutty
0
141
Member Avatar for aaronmk2

>>[B]Rock(enum RockName)[/B] You want : [code] Rock(RockName rockName){ myName = rockName; } [/code]

Member Avatar for mrnutty
0
140
Member Avatar for hsquared

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 > …

Member Avatar for chiwawa10
0
103
Member Avatar for tommyz4

Also whats with pointers? Be smarter about your code and use reference or smart pointers if you have to.

Member Avatar for Ancient Dragon
0
268
Member Avatar for DoEds

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 …

Member Avatar for krutarth
0
3K
Member Avatar for Xorlium

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.

Member Avatar for mrnutty
0
232
Member Avatar for Lukezzz
Member Avatar for mrnutty

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 …

Member Avatar for alan145
0
316
Member Avatar for NewLegend

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]

Member Avatar for NewLegend
0
197
Member Avatar for winnie89

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 …

Member Avatar for mrnutty
0
244
Member Avatar for glenn612991

This should help [code] if(num < 0){ /* the number is negative */ doStuffWithNegativeNumbers(); } else{ /*The number is not negative */ doStuffWithNonNegativeNumbers(); } [/code]

Member Avatar for Vllinator
0
2K
Member Avatar for Borkoff

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 } } …

Member Avatar for Borkoff
0
151
Member Avatar for Nathaniel10

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 …

Member Avatar for mrnutty
0
131
Member Avatar for Lerner

The size of myList is found by using the sizeof() operator. It should be a multiple of 4 bytes.

Member Avatar for Lerner
0
158
Member Avatar for hsquared

[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( …

Member Avatar for mrnutty
0
103
Member Avatar for coffeewithcream

>>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] …

Member Avatar for mrnutty
0
3K
Member Avatar for LevyDee

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.

Member Avatar for mrnutty
0
89
Member Avatar for MarounMaroun
Member Avatar for eduard77

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?

Member Avatar for Ancient Dragon
0
85
Member Avatar for embooglement

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.

Member Avatar for mrnutty
0
137
Member Avatar for Philip435

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 …

Member Avatar for mrnutty
0
93
Member Avatar for gsfare

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.

Member Avatar for gsfare
0
158
Member Avatar for aikiart

>>[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]

Member Avatar for Fbody
0
159
Member Avatar for lapunluyang

[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 …

Member Avatar for Ancient Dragon
0
163
Member Avatar for Dark Byte

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 …

Member Avatar for Dark Byte
0
183
Member Avatar for hurbano

@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 …

Member Avatar for hurbano
0
148
Member Avatar for Takeshi91k

>>test.setValue(value); [code] test[0].setValue(value); [/code] I'll let someone else criticize your code. Feel too lazy right now.

Member Avatar for Takeshi91k
1
139
Member Avatar for nizbit

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]

Member Avatar for dusktreader
0
538
Member Avatar for jsburkdc

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 ?

Member Avatar for prvnkmr449
1
450
Member Avatar for onako

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]

Member Avatar for LordNemrod
0
113
Member Avatar for asa88

>>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?

Member Avatar for asa88
0
217
Member Avatar for daviddoria
Member Avatar for daviddoria
0
88

The End.