2,712 Posted Topics

Member Avatar for rstep21
Member Avatar for roberto usu

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

Member Avatar for roberto usu
0
137
Member Avatar for killerqb

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 …

Member Avatar for killerqb
0
153
Member Avatar for Lukezzz
Member Avatar for serkan sendur
0
95
Member Avatar for suutukil

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]

Member Avatar for mrnutty
-1
156
Member Avatar for suutukil

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

Member Avatar for suutukil
0
623
Member Avatar for willywonka

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

Member Avatar for willywonka
0
138
Member Avatar for hao001

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

Member Avatar for hao001
0
132
Member Avatar for mrnutty

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 …

Member Avatar for masijade
0
896
Member Avatar for xfreebornx

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

Member Avatar for hao001
0
320
Member Avatar for kreskin

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]

Member Avatar for kreskin
0
141
Member Avatar for ameneh_p
Member Avatar for helpme123456789

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

Member Avatar for VernonDozier
0
227
Member Avatar for Hawkpath

"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é).

Member Avatar for geoffy0404
0
456
Member Avatar for yakovm

change this : [code] template< Base* arr,int size = 10>[/code] to [code] template<typename Type,int size = 10> [/code]

Member Avatar for mrnutty
0
118
Member Avatar for khanalone1

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

Member Avatar for khanalone1
0
528
Member Avatar for yakovm

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]

Member Avatar for mrnutty
0
69
Member Avatar for bil050
Member Avatar for picass0

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

Member Avatar for anupa
0
1K
Member Avatar for D.JOHN
Member Avatar for D.JOHN
0
209
Member Avatar for mrnutty

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 …

Member Avatar for mrnutty
0
173
Member Avatar for kz07

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

Member Avatar for kz07
0
5K
Member Avatar for MattyRobot

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 …

Member Avatar for MattyRobot
0
121
Member Avatar for vbCNEW

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 …

Member Avatar for rob-lozyniak
0
114
Member Avatar for BlackPhoenix

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

Member Avatar for BlackPhoenix
0
110
Member Avatar for niyasc

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

Member Avatar for mrnutty
0
193
Member Avatar for MattyRobot

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 …

Member Avatar for rughead
0
158
Member Avatar for iammfa
Member Avatar for Thomasedicel

Ask the Google god. Type your question into Google and all your questions shall be answered. Note: Not reliable for everything.

Member Avatar for mrnutty
-1
127
Member Avatar for gowth08

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]

Member Avatar for mrnutty
0
166
Member Avatar for smco9

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.

Member Avatar for VernonDozier
0
97
Member Avatar for smco9

"\n" and '\n' are completely different. One is a string literal which is null terminated while other is a newline character.

Member Avatar for Ancient Dragon
0
226
Member Avatar for Gekke11
Member Avatar for jim148

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]

Member Avatar for jim148
0
136
Member Avatar for lancevo3

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 …

Member Avatar for mrnutty
0
105
Member Avatar for D.JOHN

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 …

Member Avatar for D.JOHN
0
704
Member Avatar for chixm8_49

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 …

Member Avatar for codeguru_2009
0
177
Member Avatar for Epi23

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 …

Member Avatar for Epi23
0
103
Member Avatar for mrnutty
0
333
Member Avatar for mrnutty

Random number generator under its own namespace. Its a sample program.

0
301
Member Avatar for roberto usu
Member Avatar for serdengil

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

Member Avatar for mrnutty
0
166
Member Avatar for Acute

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.

Member Avatar for Acute
-2
126
Member Avatar for daviddoria

"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.

Member Avatar for mrnutty
0
151
Member Avatar for daviddoria
Member Avatar for invisi

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

Member Avatar for invisi
0
141
Member Avatar for cmel89
Member Avatar for coud_ren_26

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

Member Avatar for kvprajapati
0
129
Member Avatar for odwa

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

Member Avatar for mrnutty
0
110
Member Avatar for kamos.jura

The End.