2,712 Posted Topics
| |
Re: [QUOTE=roberto usu;987631]Iwhen to use a void function verses a bool or int or other type of function.[/QUOTE] Whenever you create a function, you need to know what it does first. Does it sort an array, does it return the square of a number, does it print a triangle? Whatever, it … | |
Re: template class and its definition has to be on the same file, unless your compiler supports the keyword export. and you need a forward declaration : [code] #ifndef STACK_H #define STACK_H #include <iostream> using namespace std; [COLOR="Red"]template<typename T> class stack;[/COLOR] template <typename T> class ListNode { public: ListNode(); private: T … | |
Re: std:: [URL="http://www.cplusplus.com/reference/stl/list/unique/"]unique[/URL] | |
Re: How to sort using std [code] int Array[4] = {4,2,2,1}; std::sort(Array,Array+4); //now array is {1,2,3,4}; for(int i = 0; i < 4; i++) Array[i] *=2; //now array is {1,4,6,8}; //print out the array. [/code] | |
Re: What you could do is, since you are getting inputs, you can make sure that the inputs are greater than the last input. example run : [code] Please enter a number : 3 Please enter a number greater than 3 : 5 Please enter a number greater than 5 : … | |
Re: [QUOTE=Salem;986124]So do it in stages, say the spaces up to and including the first hash. You don't have to write the whole thing just to make progress.[/QUOTE] Exactly the idea behind " Divide and conquer " strategy, which in fact is very intuitive. | |
Re: " Why MAX_SIZE = 2 ? " Choosing 2 was for demonstrative purpose, it could have been 1000. It represent the max number of student allowed. "Q: 1. From the function above, why sometime he use MAX sometime use MAX_STUDENT and MAX_SIZE?? " The name does not matter. The function … | |
Does anyone know how to correctly add a 3rd party library to NetBeans? I have NetBeans 6.7.1 The library is from this site : [URL="http://wps.aw.com/aw_sanders_oopjava_1/36/9390/2403930.cw/index.html"]Link[/URL]. Its called wheels, and its for my class. It comes in a zip file. What I tried was this : 1) Set the zip file … | |
Re: Fixed it a little. Please try the rest on your own, until you really need help. [code] #include<iostream> #include<algorithm> //for std::sort #include<string> using namespace std; struct student { int id; string name; string nationality; string gender; }; void insert(student array[],const unsigned int MAX_STUDENT); bool sortByID(const student& a, const student& b) … | |
Re: One way you to solve this is to read char by char. maybe something like this : [code] char ch; string content; ifstream iFile("file.txt"); while( iFile.get(ch) ) { if(ch != ',') content += ch; else { cout<<content<<endl; content = ""; } } [/code] | |
Re: [QUOTE=Dave Sinkula;985247][code]for (int i = 0; i < strlen (address); i++)[/code][URL="http://www.cprogramming.com/tips/showTip.php?tip=59&count=30&page=0"]Don't use strlen in a loop condition.[/URL][/QUOTE] I thought most compiler would optimize it. I'll check to see if it does with Visual Studio Express 2008. | |
Re: "I have heard the horror stories of terrible hours and bad job security in game programming." Its nothing compared to the joy one gets when making games (not to be Cliché). | |
Re: change this : [code] template< Base* arr,int size = 10>[/code] to [code] template<typename Type,int size = 10> [/code] | |
Re: [quote] adds and subtracts for doing encryption and decryption [/quote] If your program justs shifted character x units to the right for encryption then you need the same translation to the left for decryption You cant use 2 different keys for simple shifting encrypt/decrypt Unless for the decrypt, you have … | |
Re: what? I don't really get your question? You can't define template class ? [code] template<typename Type = int> //default type is int class ABC { }; [/code] | |
| |
Re: another idea : read the file until it encounter the word that you are looking for. If found then stop else continue. something like below. I am assuming your text file is like the one shown above. [code] bool findWord(char*Filename, string& find) { ifstream iFile(Filename); if(!iFile) { cerr<<"File not opened!\n"; … | |
Re: Enquiries about printf function is more of a c question don't you think? | |
I haven't ever used CLA so I had to ask. For simplicity sake, Say I have a program that takes in at most 5 arguments. The arguments from args[1] - args[4] has to be some numbers. These number will be used for something, say to calculate its average. How could … | |
Re: " num.at(i) " num is an integer and not an array. This does not work. I think what you are trying to do is something like this : [code] int digits[4] = {0}; int num; cin >> num; int i = 0; while(num) { digits[i] = num%10; //get the last … | |
Re: Well to make a GUI program in opengl, say a basic triangle, all you need to know about c++ is, functions,libraries,if-else,and switch-statements. From that you can make your first triangle. Although it might be hard to understand what which function does from the GUI library. My suggestion would be to … | |
Re: Depends on : the number of row of slots that spins. the number of different symbols. I think generally it would be : let N = number of spinning slots; let S = number of different symbols. then the probability that one will get the same symbol N times in … | |
Re: Your code has a memory leak : [code] Player* temp; //create 3 objects in vector temp = new Player(300, 300); // You ask for memory for temp Players.push_back(temp); Players.back()->Load("enemy.bmp"); temp = new Player(400, 300); // You again ask for memory for temp. //code removed... //... //... temp = new Player(350, … | |
Re: [quote]May I get some instructions to improve it?[/quote] Yes, don't use iostream.h, use iostream, don't use void main, use int main, don't use gotoxy, find a replacement, and don't use goto. Also why do you have a case '8' if you don;t use it? | |
Re: or you can use pointer member function, and pass the class a function to call. [code] #include <iostream> using namespace std; void callThisFunc() { cout<<"This function was called"; } class CallFunc { typedef void(*pF)(); private : int x; public: CallFunc() : x(100){ } CallFunc(int xo) : x(xo) { } void … | |
Re: Ask the Google god. Type your question into Google and all your questions shall be answered. Note: Not reliable for everything. | |
Re: In c++ , recursively, not tested. [code] void printSeq(int num) { cout<<num<<" "; if(num == 1 ) return; if( num & 1) //if odd num = num*3+1; else num /=2; printSeq(num); } [/code] | |
Re: look at the 4th post on this [URL="http://www.daniweb.com/forums/thread214486.html"]link[/URL]. It shows you one way to sort a struct. | |
Re: "\n" and '\n' are completely different. One is a string literal which is null terminated while other is a newline character. | |
| |
Re: There is a header called sstream which is very handy in these types of situations. Here is an example, although not compiled. [code] #include<iostream> #include<sstream> using namespace std; int main() { stringstream convert; string result; int num = 12345; convert << num; convert >> result; cout<<result<<endl; return 0; } [/code] | |
Re: Check if this works. It compiles on Visual studio 2008 express. [code] /**************************************************************** FILE: List.h AUTHOR: Justin R. Smith LOGON ID: Z136340 DUE DATE: 9/8/09 PURPOSE: Contains prototypes and class definitions for a doubly linked list. ****************************************************************/ #include <iostream> template <class T> class Iterator; template <class T> class List; template … | |
Re: I think it would help if you look at it in binary perspective. int x = 0x26; in binary 0x26 = 0010 0110 //its separated for you to see it better now we have this binary number : 0010 0110 and we want to toggle the 3rd bit : the … | |
Re: maybe this will be of some use. Its C++ version of hangman. Its from C++ Primer Plus 5th edition. I copied and pasted for you. [code] // hangman.cpp -- some string methods #include <iostream> #include <string> #include <cstdlib> #include <ctime> #include <cctype> using std::string; const int NUM = 26; const … | |
Re: Here is your program written better. You could have used switch statements, but I wasn't sure if you knew them. Use code-tags. /* Pick a problem and solve */ #include <iostream> using namespace std; int main() { int x; float a,b; cout << "Hello, please pick a type of problem … | |
Convert string to other datatypes via template. See below. | |
Random number generator under its own namespace. Its a sample program. | |
Re: [quote] make user prompt to enter the number in ascending order[/quote] Its limited to only positive numbers though. (not tested) [code] int lastNum = -1; int newNum = 0; int numEntered = 0; while(numEntered != 10) { cout<<"Enter numbers in ascending order : "; cin >> newNum; while(newNum < lastNum) … | |
Re: For your question # 2, you can use the public interface of the elevator, but it should be only allowed to be used by passenger, and not the building class. And I am not sure what question # 1 is asking. Care to elaborate. | |
Re: "cannot acces memory at 0x0" I assume that error means that something is trying to read in an invalid memory location, one which does not exits as 0x0, which is NULL. | |
Re: comment out code by code to see where the error occurs. | |
Re: [QUOTE=NathanOliver;964502]also in the first program there is no memory leak.[/QUOTE] Are you sure. His program is tricky in a sense that there is a memory leak. His function is definitely not doing what he thinks its doing. One way to tell if you have memory leak is to see if … | |
Re: Can you post a example of an input and output? | |
Re: int [] onedee; int [][] twodee; int [][][] threedee; //so on [code] import java.util.Random; public class Main { public static void main(String[] args) { int [][]twodee = { {0,0,0}, {0,0,0} }; Random rand = new Random(); //populate for(int i = 0; i < twodee.length; i++) { for(int j = 0; … | |
Re: How to use sqrt function in c++ : [code] int a = 3; float b = 3; double c = 3; float t = sqrt(a); //invalid error. a is of type int. Only float|double allowed float y = sqrt ( float(a) ); //valid because of typecast float u = sqrt(b); … | |
Re: just pass 2d vector and use only its column? |
The End.