2,712 Posted Topics

Member Avatar for Ee Juan

Divide and conquer. In this case, if you break it up into function you will see that the logic is easy to see. [code] #include <iostream> using namespace std; void printN(const char c, int N){ while(N--) cout << c; } void printSeq(int start, int end){ while(start != end){ cout << …

Member Avatar for mrnutty
0
102
Member Avatar for jrw89

Realize that from your code, students and grades might not be the same size. You should instead do something like this: [code] for each students in the vector students:{ get student grades. } [/code]

Member Avatar for mrnutty
0
191
Member Avatar for Aneurinbiker

In your first post you can do this : [code] void print(const char*p){ cout << p << endl; } [/code] and call it like so : [code] int main(){ print("hello"); print("hello"); } [/code] Try that first

Member Avatar for NubTruck
0
191
Member Avatar for alex k

[B]psuedo-code:[/B] [code] create randomAges[N] = {0}: seedRng(); for (i = 0 : N){ randomAges[i] = rand(); } [/code]

Member Avatar for manojwali
0
121
Member Avatar for johnsign11

>>[B]I think vector::reserve() can cause a resize[/B] >>[B]The member functions vector::reserve()... both can cause re-allocation as well[/B] Just to let you know, your first statement is different from your second. reserve does not "resize" the vector as in vector::resize does, so just be weary of the lingo. And as for …

Member Avatar for manojwali
0
157
Member Avatar for koolman123

[B]>>Well this forum likes assuming things doesn't it?[/B] Well you haven't mentioned it wasn't a h.w problem in your first post. And usually most threads here are h.w problem. So as you see, our default assumption is that this post is probably about some h.w problem. [B]>>It was automatically posted …

Member Avatar for mrnutty
0
101
Member Avatar for sinfultom

>>std::auto_ptr Thats being deprecated. So I would avoid that. I would rather use boost smart pointers

Member Avatar for Duki
0
189
Member Avatar for medopunsher
Member Avatar for mrstrong11

[B]1. Do you love what you do? why?[/B] Yes, otherwise I probably wouldn't do it often. [B] 2. Do you interact with other people or other engineers a lot?[/B] I guess, I am a college student in class with other engineering students. [B] 3. How dangerous is your job? Have …

Member Avatar for vegetablevn
0
171
Member Avatar for ftl25

You can't really do that, but there might always be some hack. How about you create the most general lookup table[b]s[/b] and work with that? Maybe something like readMemoryFunctionTable, writeMemoryFunctionTable,...

Member Avatar for vijayan121
0
2K
Member Avatar for AutoC

look into boost::any >>[B]I cannot predefine a structure because I dont know what data types I am gonna be given[/B] Why not? Well do you at least know if its a string or a number?

Member Avatar for embooglement
0
114
Member Avatar for totalwar235

What you showed above is almost like recursion : [code] void func(long i){ if(i > 0) func(i - 1); } [/code] Say "i = 5", then the functin func() will be called 6 times, because of the initial called. So your question is directly related to the question, "whats the …

Member Avatar for Duki
1
157
Member Avatar for xiansen

>>guessResponse( spec, tries) That should be : [i]guessResponse( spec, number)[/i] >>if (count = 10) That should be [i] if (count == 10)[/i] >>[B]void secretNum(int&);[/B] See the difference between that and this : [B]void secretNumber(int &num)[/B]

Member Avatar for Duki
0
294
Member Avatar for GrimJack

I don't know if my link is appropriate, but what the hell. I visit my [URL="http://www.gamedev.net/community/forums/"]porn site[/URL] regularly.

Member Avatar for ithelp
0
112
Member Avatar for helpme87

[B]Step 1: Declare variables[/B] [code] std::map<long,long> report; std::pair<long,long> info; std::ifstream file("data.txt"); [/code] [B]Step 2: Read in data [/B] [code] while( file >> info.first >> info.second ){ / * do stuff*/ } [/code] [B]Step 3: Apply algorithm [/B] [code] while( file >> info.first >> info.second ){ std::map<long,long>::iterator itr = report.find( info …

Member Avatar for mrnutty
0
149
Member Avatar for Kanoisa
Member Avatar for Kanoisa
0
326
Member Avatar for kazkikay12

Here is his code : [code] #include <stdio.h> #include <conio.h> int main() { char wew[7]; int smallest, largest, middle, intNo; int dividend=0; int modolus=0; int valid; do { printf("Enter a seven digit number:\n"); scanf("%s", wew); valid=0; // counter for no of digits for (int a=0;a< sizeof(wew);a++) { intNo=(int)wew[a]-48; // trap …

Member Avatar for Stefano Mtangoo
0
102
Member Avatar for ehsantl

And since it looks like you are already using classes, you can do something like this : [code] //creates a NxN maze template<typename T, int N> class Maze{ private: T _maze[N*N]; public: //some codes T& operator()(int row, int col){ //some validation assert(isPositive(row) && isPositive(col) ); assert(row*col < N*N); return _maze[ …

Member Avatar for mrnutty
0
800
Member Avatar for CzechRock3

>>[B] I want to Convert my input string to a const char[/B] The string class has a [I].c_str[/I]() member function, it returns a const char pointer. >>[B]Because I can not just convert a string directly to a integer[/B] Why can't you? What method are you using for the conversion? >>[B]Basically, …

Member Avatar for CzechRock3
0
403
Member Avatar for AutoC

[code] const char *s = "1abcdef"; string str( (s+1) ); //copy from 'a' onwards. [/code]

Member Avatar for AutoC
0
239
Member Avatar for therobot

The data structure you need is hashmap or hashtable. Like always, boost got you covered. Look into their hashtable if you want. In a typical hashtable implementation, searching is O(1), that is, its constant. If you want to stay with stl, you can use std::map. Their search operation is usually …

Member Avatar for therobot
0
105
Member Avatar for newbie_to_cpp

Are you serious? Narue's is gonna kill you lol. Your question is like comparing oranges to apples. Its really useless.

Member Avatar for NicAx64
0
110
Member Avatar for harris21
Member Avatar for mrnutty
0
738
Member Avatar for Kanoisa

Template specialization like so : [code] //for general types template<typename T> T ask(const std::string& question){ cout << typeid(T).name() << endl; cout << question << endl; T answer; cin >> answer; return answer; } //specialize for string type template<> std::string ask(const std::string& question){ cout << "In string\n"; cout << question << …

Member Avatar for mike_2000_17
0
145
Member Avatar for NicAx64

This is a good idea, me thinks. I think I could use more experience developing 'large' projects and working with other people. So if I can, I would like to join/add people to start a open source. What do you think Nic? As for ideas, I'm not sure yet but …

Member Avatar for mrnutty
0
188
Member Avatar for Kakashi Hatake

Also [URL="http://www.cplusplus.com/reference/clibrary/cfloat/"]see here[/URL] for exact details.

Member Avatar for mike_2000_17
0
104
Member Avatar for Stefano Mtangoo

Your problem is that those function do not belong in you abstract class. It seems like you are not abstracting enough, if you want only some function of the base class to be implemented. Whats wrong with simply letting the child develop the necessary functions? You might not necessarily need …

Member Avatar for Stefano Mtangoo
0
130
Member Avatar for harris21

>>[B]Conversely, you can not call destructors explicitly, except through Dynamic Memory Management[/B] Actually you can : [code] #include <iostream> using namespace std; struct Foo{ Foo(){cout<<"Ctor\n";} ~Foo(){cout<<"Dtor\n";} }; int main(){ Foo f; f.~Foo(); return 0; } [/code] But you see the problem, the destructor is called [b]2[/b] times.

Member Avatar for mrnutty
0
300
Member Avatar for Jackk123

@OP: outfile closes when its destructor is called, and main returns a int implicitly. So all that means is you don't need(according to your program) the [i]outfile.close()[/i] and [i]return(0)][/i] statement. Also as mentioned already, you need to seed the rand(), to see rand, just add [i] srand(time(0))[/i] before [i]ofstream outfile...[/i]. …

Member Avatar for Jackk123
0
147
Member Avatar for group256

@OP: your compare arguments has to be of type myStruct. Here is an example : [code] #include <iostream> #include <list> #include <string> using namespace std; struct Foo{ string name; int age; Foo(){} Foo(const string& n, int a) : name(n), age(a){} void print()const{ cout << "("<<name << "," << age << …

Member Avatar for mrnutty
0
5K
Member Avatar for embooglement

>>Is there any way to only allow insertion into string streams If you want to only insert into streams, then use [i]ostringstream[/i]. Similarly, if you want only extraction into the stream, then use [i]istringstream[/i]. If you want both extraction and insertion into the stream then use [i] stringstream[/i]. But if …

Member Avatar for embooglement
0
2K
Member Avatar for raghamayee

Yea, here is a mediocre way : [code] #include <ctime> #include <iostream> using namespace std; void runFunctionHere(){} int main(){ long start = clock(); runFunctionHere(); long end = clock(); cout << "Time took in milli seconds : " << end - start << endl; } [/code]

Member Avatar for mike_2000_17
0
144
Member Avatar for techie1991

First this code will show you what type null is : [code] cout << "NULL type is " << typeid(NULL).name() << endl; cout << "NULL value is " << NULL << endl; [/code] This is the output you will probably get : [code] NULL type is int NULL value is …

Member Avatar for Ancient Dragon
0
163
Member Avatar for daviddoria

And the reason why your original code didn't work is because your virtual add function hid the 1 parameter function. Thats why you had to use the scope resolution operator.

Member Avatar for mike_2000_17
0
219
Member Avatar for darkroad

You can use some math magic. Or you can get the input as a string, which is much easier. For example here is some not tested code. It gets the input as a string. Then sums the digits inside the string. And displays it. [code] string digits; cin >> digits; …

Member Avatar for ananda2007
0
168
Member Avatar for Duki

@OP: whenever you use const_cast, you have a serious design and logic problem in your code. The cases are very very rare, where it would justify to use const_cast in a program, and I assure you that you case is not one of them. What does this function do, [i]int …

Member Avatar for Duki
0
181
Member Avatar for bleedi

This is what you want : [code] vector<BaseClass*> stuffvector; BaseClass* temp = new DerivedClass(par_a, par_b); stuffvector.push_back(temp); stuffVector.pop_back(); //added, remove all accounts of 'temp' delete temp; [/code] But I lied, this is what you really wanted : [code] std::vector< boost::shared_ptr<BaseClass> > baseVec; baseVec.push_back( new DerivedFromBase() ); //do stuff baseVec.pop_back(); [/code]

Member Avatar for mrnutty
0
132
Member Avatar for glenndr_15

[QUOTE=Narue;1314985]How do you get the hello world program wrong? Any decent C++ programmer should be able to type it out flawlessly while plastered from booze, spun around in a chair for ten minutes, and blindfolded. :D[/QUOTE] ROFLED! @OP : [code] //Try at your own risk. #include <iostream> using namspace std; …

Member Avatar for mrnutty
0
184
Member Avatar for Jackk123

That's nothing a quick google can't help you with. But since you asked here it is : [code] #include <iostream> #include <ctime> using namespace std; int main(){ srand(time(0)); for(int i = 0; i != 10; ++i){ cout << rand() << endl; } } [/code]

Member Avatar for mrnutty
0
108
Member Avatar for mrnutty

Just a beta of what I was working on lately. It evaluates mathematical expressions like [i]2*3[/i]. Anyways, its explained in the program. Report of any bugs would be great because I haven't tested it out that much. Without further ado, you can download the program [URL="http://uploading.com/files/ef3f69c5/ExpressionEvaluatorBETA.zip/"]here[/URL], [URL="http://www.easy-share.com/1912008094/ExpressionEvaluatorBETA.zip"]here[/URL] or [URL="http://www.mediafire.com/?69oo679h46sgtq2"]here[/URL]. Try …

Member Avatar for mrnutty
0
99
Member Avatar for daneuchar
Member Avatar for Ancient Dragon
0
99
Member Avatar for gerard4143

What you are doing is hard coding each stream insertion operator. This is what you want : [code] struct Animal{ int weight, age; string name; Animal(string name = "", int weight = 0, int age = 0) : name(name), weight(weight), age(age){} ~Animal()=0{} }; struct Mammal : Animal{ }; struct Dog …

Member Avatar for gerard4143
0
2K
Member Avatar for timb89

You don't need to use the ignore function, you can just do something like this : [code] const int SPACE = ' '; //peek the next character to see if its a space, if so then discard it if(cin.peek() == SPACE) cin.get(); //opt #1 char ch = 0; cin.get(ch); //Opt …

Member Avatar for timb89
0
90
Member Avatar for mrnutty

Just post random stuff here, anything you want. Say whatever you like. For example, anyone here have a facebook?

Member Avatar for Nick Evan
0
282
Member Avatar for sbrohee

Do you really need to use the "==" operator. Can you settle for something like this : [code] typedef pair<int,int> IntPair; bool hasEqualSecond(const IntPair& lhs, const IntPair& rhs){ return lhs.second == rhs.second; } //.... if(hasEqualSecond(p1,p2)){ /*do something */ } [/code]

Member Avatar for sbrohee
0
209
Member Avatar for brazentongue

Something like this should suffice, although you might want something better : [code] #include <iostream> #include <sstream> #include <string> using namespace std; struct SimpleTime{ int hours; int minutes; int seconds; SimpleTime(int h = 0, int m = 0, int s = 0) : hours(h), minutes(m), seconds(s) {} }; //does no …

Member Avatar for brazentongue
0
156
Member Avatar for tennis

What you are looking for is polymorphism. This example should answer your question : [code] struct Polygon{ int width,height; virtual int area()const = 0; }; struct Rect : Polygon{ int area()const{ return width * height; } }; struct Triangle : public Polygon{ int area()const{ return width*height*0.5f; } } //notice input …

Member Avatar for sfuo
0
126
Member Avatar for Nathaniel10

>>It occurred to me that this only generates numbers uniformly over the range In fact, it dosen't. The only way rand() generate uniform distribution is by using the value it returns as the random number and not manipulate that random number. Thus when you do something like this :[i] int …

Member Avatar for mrnutty
0
183
Member Avatar for Dinnerfortwo

In your last for loop, use an if statement to check if the element in the array is higher or lower than the current highest and the current lowest. Here is a psuedo-code: [code] set minPtr to temps; set maxPtr to temps; for i = 1 to MAXTEMPS{ if temps[i] …

Member Avatar for xuancong
0
202
Member Avatar for lil.jeantle
Member Avatar for mike_2000_17
0
104

The End.