2,712 Posted Topics
Re: before the loop ask the user to enter a number and set min/max to that number, then go onto the while loop. | |
Re: having const after a member function means that, that function will not and shall not change any of its variables. | |
Re: [code] char AorB(char A, char B) { char T = rand%2 ? A : B ; return T; } [/code] | |
Re: Also you might want to think about abstract classs. | |
Re: Did you try it? [code] #include <iostream> using namespace std; class A { public: A() { } template<typename T> void Print(T a) { cout<<a<<endl; } }; int main() { A t; t.Print(3.1415f); //implicitly t.Print<unsigned int>(100); //explicitly return 0; } [/code] | |
Re: Yes, use template. You could use template specialization, to make sure that the template parameters is a number. Here is a way to do that : [code] #include <iostream> using namespace std; template<typename Type> struct is_numeric { static const int i = 0; }; //Template specilization template<> struct is_numeric<short> { … | |
| |
Re: you have an infinite loop : [code] while (moreOrder) { } [/code] | |
Re: Search the forum first. See if that helps. Then ask question if it comes empty. | |
Re: use for loop. It will be conceptually easier. [code] int F =5; int R = 1; for i = F to i >1 ; i-- { R equals R times F; F equals F minus 1; } [/code] | |
Re: Here is your code indented with code tags. One problem with your function is that you never declared s1 and s2. Below code fixes that : [code] #include <iostream> using namespace std; void drawShape(int nrP) { int s1 = 0,s2 = 0; //(NEW) for (int i = 1; i <= … | |
Re: [code] //Create a string and initialize it to some string literal for i = 0 to i less than the string.size ; i++) //use string.charAt(i) to print + "\n"; [/code] | |
Re: [URL="http://en.wikipedia.org/wiki/Gauss%E2%80%93Seidel_method"]Link[/URL] | |
Re: Try hitting alt+f6. Then click ok if a window pops up. | |
Re: Your copy constructor is not complete. [code] my_int_vector::my_int_vector(const my_int_vector& b) { numbers=new int[capacit]; for(size_t j=0; j<siz; j++) { numbers[j]=b.numbers[j]; } } [/code] What happens is numbers is already pointing at another memory location. What happens if the copy constructor is copying its self? | |
Re: simplify. 1) Make a bool function that takes a int i as a parameter and checks if it is a prime or not. 2) inside your loop, check if i to MAX is a prime. your function prototype might look like this : bool isPrime(int num); HINTS : a) How … | |
Re: 1) No Code tags 2) [code] int opt,x,y,fact,ans; // right now all variable has junk value for(ans=opt;ans!=0;ans++) //Read as ans = junkvalue, while junk is != 0, junk++ [/code] 3) Didn't bother with the rest | |
Re: [QUOTE=Flapjack;991144]I cant take const out. The teacher wants us to us his function and develop our code around it.[/QUOTE] Well there is [URL="http://www.cppreference.com/wiki/keywords/const_cast"]const_cast[/URL] but generally, you shouldn't have to do this. | |
Re: usually : [code] std::ostream& operator <<(std::ostream& ostrm) { ostrm << "Hello its overloaded\n"; return ostrm; } std::istream& operator >>(std::istream& istrm) { cout<<"Enter a number : "; istrm >> MyClass::myNumber; return istrm; } [/code] note overloading the << operator should be a friend, so you can use it like this : … | |
Re: 1) you could create a vector. 2) Initialize it with the array content 3) use std::sort on the vector 4) use std::unique on vector 5) Then print out the vector | |
Re: [CODE] - error C2143: syntax error : missing ';' before '.' - missing type specifier - int assumed. Note: C++ does not support default-int - 'test_player' : redefinition; different basic types [/CODE] | |
Re: your haven't initialized the variable "a". And it has to be const, when using it to determine the size of an array. [code] const int A = 10; string str[A]; //good int b = 3; string str[b]; //error[/code] | |
Re: NO, it should be : [code] tempate<typename Process> Dheap { //code }; [/code] | |
Re: There is also [URL="http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=/com.ibm.xlcpp8l.doc/language/ref/cplr385.htm"]conversion Function[/URL] : [code] #include<iostream> #include<cstring> using namespace std; class Letters { private: char str[50]; public: Letters() { str[0] = '\0';} Letters(const char * p) { strcpy(str,p); } operator const char *() { return str; } //conversion function }; int main() { Letters str("hello world"); cout<<str; } … | |
Re: First seed your rand function. [code] srand(time(0)); [/code] The this code : [code] for (int toss = 0; toss < coinToss; toss++) { flip(); if (toss == 1) heads++; else tails++; } [/code] is wrong. You need to assign the value return to a variable and then use it to … | |
Re: [QUOTE=gerard4143;990400]The unnamed fields may just be padding so that the structure's data is laid out correctly...Gerard4143[/QUOTE] Yes, structure goes by units of 4. | |
Re: first this is wrong : [code] for (int i=0; i<=arrSize; i++) //it should be i < arrSize myArr[i]=rand(); //creating array with random numbers [/code] The same goes for sorting and displaying numbers. | |
Re: 1) Dont use system's command 2) To answer your question something like this : ? [code] string command = "color "; string input = ""; cin >> input; command += input; system(command.c_str()); [/code] | |
Re: portability : "The actual type of size_t is platform-dependent; a common mistake is to assume size_t is the same as unsigned int, which can lead to programming errors, particularly as 64-bit architectures become more prevalent" | |
Re: [QUOTE=mostermand;990915]Too time consuming. I would rather not do it at all then And about the code snippet, if I create an instance of Mother, and call HandleMessage<10> it would print "It works!\n". But if I call it with any other value it would do nothing, the reason I am not … | |
Re: Have a left, middle, and end variable. Make middle static. Move left up 1, move end down 1. If left == mid || right == mid then stop. | |
Re: opengl is a graphics library while glut is not. You use glut with opengl to handle graphics. glut handles with mostly the input. It could create the graphics window, handle key input and some other fancy stuff. You use opengl to draw primitives onto the window that glut creates. | |
Re: [code] int cnt = 0; for infinite loop { //do stuff if(//do stuff is what i need) // then break; else cnt++; //if cnt is above the limit then break; }[/code] | |
Re: Use the error handling that already built in, called [URL="http://www.cplusplus.com/reference/std/stdexcept/"]stdexcept[/URL] | |
Re: To convert string to numeric datatype look [URL="http://www.daniweb.com/code/snippet217456.html"]here[/URL] | |
Re: [quote] can't I just use a string?[/quote] Yes you can : [code] #include <iostream> #include <string> using namespace std; struct Student { string firstName; string lastName; bool canadianship; int grades[10]; }; Student newStudent[10]; void addFirstName() { string name; cout << "Student Name: "; cin >> name; newStudent[0].firstName = name; } … | |
Re: [QUOTE=sjcomp;990316]Thanks William, thanks for the suggestion. I understand how it can be done. But before I jump in and start implementing it myself I would like to make sure that I can not use the code that already exists. It seems reasonable to expect that such a code exists, though.[/QUOTE] … | |
Re: [QUOTE=Trekker182;988208]I think I just need to tell the sort function sort by ascending order except when you encounter "a" "e" "i" "o" or "u" but am not sure how. Would it have something to do with the p parameter?[/QUOTE] Well if you want to do that, then use a compare … | |
Re: what is link a typedef of ? (h->N+1) is N the number of nodes? | |
Re: //check out the code snippet, [URL="http://www.daniweb.com/code/snippet217455.html"]here[/URL] int random(int low, int high) { return } [code] //use logic to find the min element //assign initial min element to A[0]; //search through loop seeing if other element's value are //greater than min element value if so the reassign min element //other wise … | |
Re: Make a function that return a random int from 1-6; then player1 = randomDiceRoll(); player2 = randomeDiceRoll(); //and so on. have a counter that counts points. int playerPoints =0; int compPoints = 0; //use a while loop while(true) { //roll dice //check winner //add points to winner //check if game … | |
Re: [quote] The errors that I have are: [/quote] [quote] error C2228: left of '.print' must have class/struct/union [/quote] This is from this code : [code] //prompt customer for savings balance and print the balance out savingsAccount.calculateMonthylyInterest().print(); [/code] To solve it you can do 2 things : 1) Make calculate return … | |
Re: Its because of logic : [code] for (int i=0; i<list.size(); i++) { ...} [/code] Lets make a table : [code] i list.size() list.top i < list.size() ---------------------------------------------- 0 3 2323 true 1 2 10 true 1 1 20 false [/code] So what a for loop does is this :[code] for( … | |
Re: google opengl loading texture tutorial. You will find how to load in image files. | |
|
The End.