2,712 Posted Topics

Member Avatar for Nathaniel10

There is another [URL="http://www.cplusplus.com/reference/algorithm/swap/"]swap function/[/URL]. It swaps the two variables. So now its up to you to use that to swap variables around in your vector.

Member Avatar for Nathaniel10
0
194
Member Avatar for smcguffee

>>Could I put a for loop inside an initializer list somehow Just to add a little more, Yea king of, you can do something like this : [code] struct Foo{ int i; Foo() : i( bar() ); }; [/code] and inside the bar function, there could be a loop or …

Member Avatar for StuXYZ
0
99
Member Avatar for chamnab

>>[B]what is the best program that can write C++ more easily?[/B] Best is subjective, but I suggest visual studio, or even Eclipse. >>[B]2.Can you output C++ in different language beside English ?[/B] I think the farthest you can go with C++ is wide characters, which does not contain any other …

Member Avatar for Ancient Dragon
0
188
Member Avatar for mimis

>>Structs are simpler. Structs are old. Structs are not as powerful May I ask why you think structs are not as powerful as classes in C++?

Member Avatar for mrnutty
0
164
Member Avatar for TheWolverine

I think this is a good design for you : [code] #include <iostream> using namespace std; struct Base{ int a,b; Base(int a = 0, int b = 0) : a(a), b(b) {} virtual int calculate()const{ if(!validatePreCondition()) return -1; int res = compute(); if(!validatePostCondition()) return -1; return res; } private: virtual …

Member Avatar for mrnutty
0
76
Member Avatar for Bigbrain99

>>if(isphone=true) You are setting isphone to true in that loop, instead of testing it. You need to use the binary boolean operator : [code] if(isphone == true ); [/code] in fact, you can even do this : [code] if(isphone){ } [/code] And for those errors, you named the boolean variable …

Member Avatar for Bigbrain99
0
155
Member Avatar for vbx_wx

Its called a [URL="http://en.wikipedia.org/wiki/Singleton_pattern"]Singleton_pattern[/URL] EDIT: oops, should have checked to see if sfuo had the same link or not, sorry.

Member Avatar for Stefano Mtangoo
0
94
Member Avatar for smcguffee

I think you are getting confused. Think of the Nested class as a class of its own. The only difference is its scope. You can only access it from the outer class. The nested class has no association with the parent class, besides the scope resolution. What you are doing …

Member Avatar for smcguffee
0
121
Member Avatar for therstonsplace

So do you want to load .bmp or .jpeg? Wiki has a good description of reading in .bmp and .jpeg. All you need to do is follow the psuedo code.

Member Avatar for therstonsplace
0
136
Member Avatar for tennis

You can think of the ternary operator as this : [code] if( condition ) return firstArgument; else return secondArgument; //which is equivalent to this : condition ? firstArgument : secondArgument; [/code] So when you do something like this : [code] var arg = condition ? firstArgument : secondArgument; [/code] it …

Member Avatar for DavidRogers
0
164
Member Avatar for Bigbrain99

Just do something like this : [code] 1 : open file to read 2 : open file to write 3 : create a counter variable starting at 1 4 : get user's input 5 : write to file the value of counter variable 6 : write to file the value …

Member Avatar for mrnutty
0
113
Member Avatar for daggerdvm

Just polished it up a little, and fixed a few things. Take a look it will definitely help you to compare your original to this : [code] #include <iostream> using namespace std; class Calculator{ private: int number1; int number2 ; public: Calculator(){ number1 = number2 = 0; } Calculator(int input1 …

Member Avatar for embooglement
0
153
Member Avatar for samsons17
Member Avatar for Fbody
0
132
Member Avatar for HumanBeing86

First : [code] template<class P> P add(P a, P b){ P result; result = a + b; return result; } [/code] is simply : [code] template<class P> P add(P a, P b){ return a + b; } [/code] second, what are you expecting when adding chars? Do you expect M …

Member Avatar for Fbody
0
200
Member Avatar for kemooo

Sure here it is : [code] #include <iostream> #include <cmath> using namespace std; int main(){ cout << "Please fail me because I asked for this code at www.daniweb.com\n"; cout << "And by the way, the cosine of 45 degrees is : " << cos(45 * 180.0/3.14) << endl; } [/code]

Member Avatar for mrnutty
0
121
Member Avatar for camcam08

>>ofstream dtfile(""nop"", ios::app); [code] ofstream dtfile(nop.c_str(), ios::app); [/code]

Member Avatar for mrnutty
0
79
Member Avatar for come_again

Ughhh, why are you using pointers? None of that is necessary. None of it! Look at your [i] CQuaternion* operator*(CQuaternion& param)[/i], it returns a pointer to CQuaternion, but look at what you are returning in that function, [i] return *temp [/i]. Whats even worse is that this code : [code] …

Member Avatar for StuXYZ
0
173
Member Avatar for enkidu75

No there is no need for a 3d array. You need to use structures. Here is some things to get you going : [code] struct Item{ string day; string time; int count; } std::istream& operator >>(istream& stream, Item& item){ //file format is always : "day - time - count" //so …

Member Avatar for mrnutty
0
116
Member Avatar for Bigbrain99

Do this instead : [code] if(input[i] == "@") //notice the double quotes { //... } [/code]

Member Avatar for Bigbrain99
0
225
Member Avatar for mike42intn

I don't see why gcd would ever be 0. Its minimum should be 1, because 1 can divide into all natural numbers evenly. Also look at the for loop condition, gcd can never reach 0.

Member Avatar for mike42intn
0
154
Member Avatar for Bigbrain99

Take another look at this: [b]input.at[COLOR="red"][[/COLOR]j[COLOR="Red"]][/COLOR][/b]. .at is a function and thus to call a function you need to use the parenthesis, "()" , and not the square brakets, "[]". Also do you really need to use .a()? You aren't even handling if it throws an error. Just use [i] …

Member Avatar for Bigbrain99
0
5K
Member Avatar for embooglement

I hope this is a typo : [code] typedef std::stringstream [COLOR="Green"]StreamString[/COLOR]; [COLOR="Red"]StringStream[/COLOR]& operator<<([COLOR="red"]StringStream[/COLOR]& stream, const TransMatrix& matrix) [/code] I'm not sure whats the problem. Are you sure the errors occurs at line 7?

Member Avatar for embooglement
0
2K
Member Avatar for archana.c07

Can you show me real code please? That example is not cutting it. And from your example, your code looks badly designed.

Member Avatar for archana.c07
0
101
Member Avatar for mrkaran
Member Avatar for vbx_wx

[QUOTE=vbx_wx;1307536]How can i demonstrate that inline functions have internal linkage ?[/QUOTE] <quote> Nevertheless, in C++, inline functions are treated by default as having external linkage, meaning that the program behaves as if there is only one copy of the function ( look below for source) </quote> ------------------------------------------------------------------------------------------- *[URL="http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=/com.ibm.xlcpp8a.doc/language/ref/cplr243.htm"]source[/URL]

Member Avatar for mrnutty
0
101
Member Avatar for gallantlex

You cant treat your Student class as a POD type because its not. Thus casting it to char* is wrong. So these calls are a bug: [code] outfile.write(reinterpret_cast <const char*>(&aStudent), sizeof(Student)); infile.read(reinterpret_cast <char*>(&aStudent2), sizeof(Student)); [/code] Use proper insertion/extraction operators which you defined already!

Member Avatar for gallantlex
0
966
Member Avatar for dflatt

You should ONLY call [I]delete [/I]to the things you call [I]new[/I] for.

Member Avatar for dflatt
0
121
Member Avatar for michdd

When you remove those objects, as said earlier, the objects destructor should delete the pointer. But if you are doing something like this : [code] std::vector<Object*> objVec; objVec.push_back( new Object() ); [/code] then you need to delete the object explicitly : [code] nt main(){ std::vector<int*> vec; vec.push_back( new int(0) ); …

Member Avatar for mrnutty
0
85
Member Avatar for darkangel07

>> a1x1 + b1x2 + c1x3 = d1 a2x1 + b2x2 + c2x3 = d2 a3x1 + b3x2 + c3x3 = d3 Hint : A good way to solve this is by using linear algebra techniques.

Member Avatar for tesuji
0
151
Member Avatar for rowley4

Look at each function and think when it cal fail? For example, what happens when you try to access the top of the list but the list is empty? Is this a case where you think you should throw an exception? What happens when you try to erase a invalid …

Member Avatar for mrnutty
0
93
Member Avatar for AdventGamer

Your problem is here first : [code] //iterate through list and copy to newly allocated memory while(front->next != NULL) { //create new node temp = new node<T>; //set newnode equal to tempHead's next. temp = tempHead->next; } [/code] First, use the condition [i] while( front != NULL) {...} [/i] Second, …

Member Avatar for mrnutty
0
1K
Member Avatar for mrkaran

Why would you want to do that when you can simply use the relational operators : [code] #include <iostream> #include <string> using namespace std; int main(){ string s = "100"; string n = "200"; cout << boolalpha; cout << "s == n : " << (s == n) << endl; …

Member Avatar for NathanOliver
0
102
Member Avatar for TheWolverine

I'm not sure what you are asking for. But Do you want to call [i] Base::computeFunction() [/i] inside of [i] Derived::computeFunction() [/i]

Member Avatar for mrnutty
0
2K
Member Avatar for Dazaa
Member Avatar for mike_2000_17
0
144
Member Avatar for GrimJack

It seems as if the more we are technology driven, the more concern we should have of our safety.

Member Avatar for Agilemind
0
144
Member Avatar for yup790

Muhahahahahaa [code] #include <iostream> using namespace std; #define SAY std::cout << #define startProg int main(){ int i = 0; #define endProg return 0;} #define FOR(MAX) for(i = 0; i != MAX; ++i){ #define ENDFOR } startProg FOR(20) SAY "hello world\n"; ENDFOR endProg [/code]

Member Avatar for mrnutty
0
221
Member Avatar for clement99

I hope you know that there are libraries already made for this. If you are doing this just for practice then go ahead. To get the whole string and not be limited by cin, use [i]getline(cin,stringVariable) [/i]. This puts the whole line into the stringVariable. Work from there.

Member Avatar for clement99
0
725
Member Avatar for frogboy77

How are your list of large number stored? Presumably its stored in a .txt file in a specific format. Can you give an example ?

Member Avatar for frogboy77
0
128
Member Avatar for sfuo

You might be able to do this with smart pointers. But then again, its probably better to just use glVertex3f(...);

Member Avatar for mike_2000_17
0
157
Member Avatar for Fbody

>>. A search will yield a stringstream page, but doesn't give the header name. What you do then is click on the constructor of the object( in that page ), and it will show you a full code, using the object at interest.

Member Avatar for Fbody
-1
159
Member Avatar for babug

Well, The circumference of a circle is 2*pi*r, but 2*r is the diameter so its : C = D*pi, where D is the diameter of the circle. Now if we divide the circumference by the Diameter then we are just left with pi : D*pi / D = pi. In …

Member Avatar for Sriman_Laxmi
0
1K
Member Avatar for AdventGamer

In your compareNode function you cannot just delete the node like that, [code] if (curr->nodeValue < target){ delete curr; //No No No }[/code] Since this is a single linked list, what you need to do, is set the previous pointer, that points to curr, to now point to curr.next. Then …

Member Avatar for AdventGamer
0
119
Member Avatar for rcplguy15

Well since everyone is posting their solution, might as well post mines : [code] void printPattern(char ch1, char ch2, const int MAX){ for(int r = 0; r != MAX; ++r){ for(int c = 0; c != MAX; ++c){ cout << (c % 2 == 0 ? ch1 : ch2 ) …

Member Avatar for sfuo
0
131
Member Avatar for mrnutty

Its a typical implementation of mergesort algorithm. It runs in a stable time of O(n*log(n) ). Just thought, I would add it to the library. Its been tested, although not very throughly, so if any bugs are found, just post it here, so others can be aware of them. Its …

Member Avatar for Rashakil Fol
0
881
Member Avatar for heezay

To do stuff like this you need to right tool for the job. C++ is not the correct tool for this job. I suggest something like php.

Member Avatar for thelamb
0
130
Member Avatar for mrnutty

You are given a number D, for which 0 < D < 1,000,000 [B]Your task[/B] : is to find the number of irreducible fractions for a fraction of the sequence, (D-1)/D , (D-2)/D ... 1/D. For example, let D = 12; Then listing all fraction increments of 1/D we get …

Member Avatar for mrnutty
0
295
Member Avatar for doktor9

I think this calls for a do/while loop : [code] bool driveAnotherCar = false; do{ /* drive car code here*/ char ch = 0; cin >> ch; if( tolower(ch) == 'y') driveAnotherCar = false; }while(driveAnotherCar) [/code]

Member Avatar for mrnutty
0
108
Member Avatar for pdk123

First off thats not polymorphism. Second you need a forward decleration. [code] struct B; struct A{ A a; B b; }; struct B{ A a; B b; }; [/code] Second, why are you using pointers? In C++ you use reference.

Member Avatar for pdk123
0
121
Member Avatar for qqwushi12345

You need to first be able to generate prime numbers. When you are able to do that, you can create some variables to hold the previous and next prime numbers. If their difference is 2, then you got a twin pair. try to code that idea.

Member Avatar for cgcgames
0
3K
Member Avatar for nbaztec

[QUOTE=ezestseo;1298480]C is procedure oriented language.. C++ is a object oriented language[/QUOTE] I beg to differ, C++ is not an OO language.

Member Avatar for mrnutty
0
572

The End.