2,712 Posted Topics
Re: 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. | |
Re: >>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 … | |
Re: >>[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 … | |
Re: >>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++? | |
Re: 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 … | |
Re: >>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 … | |
Re: 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. | |
Re: 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 … | |
Re: 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. | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … ![]() | |
Re: Much easier way : [code] string seq = "1 0 1 0 1"; for i = 0 to N print seq; [/code] | |
Re: 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 … | |
Re: 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] | |
Re: >>ofstream dtfile(""nop"", ios::app); [code] ofstream dtfile(nop.c_str(), ios::app); [/code] | |
Re: 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] … | |
Re: 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 … | |
Re: Do this instead : [code] if(input[i] == "@") //notice the double quotes { //... } [/code] | |
Re: 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. | |
Re: 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] … | |
![]() | Re: 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? ![]() |
Re: Can you show me real code please? That example is not cutting it. And from your example, your code looks badly designed. | |
Re: [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] | |
Re: 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! | |
Re: You should ONLY call [I]delete [/I]to the things you call [I]new[/I] for. | |
Re: 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) ); … | |
Re: >> 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. | |
Re: 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 … | |
Re: 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, … | |
Re: 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; … | |
Re: 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] | |
Re: >>how would you write this?? points[size]->y; ?? Did you try it? | |
Re: It seems as if the more we are technology driven, the more concern we should have of our safety. | |
Re: 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] | |
Re: 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. | |
Re: How are your list of large number stored? Presumably its stored in a .txt file in a specific format. Can you give an example ? | |
Re: You might be able to do this with smart pointers. But then again, its probably better to just use glVertex3f(...); | |
Re: >>. 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. | |
Re: 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 … | |
Re: 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 … | |
Re: 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 ) … | |
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 … | |
Re: 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. | |
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 … | |
Re: 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] | |
Re: 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. | |
Re: 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. | |
Re: [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. |
The End.