105 Posted Topics
Re: First question is interesting one, I researched on it, but the below mentioned link has figured out some really good stuff regarding your first question. [url]http://aperiodic.net/phil/archives/Geekery/find-duplicate-elements.html[/url]. will try your 2nd question tomorrow :). | |
Re: What I understand from your question is that, you want your int menu() function to be the entry point of your program, in C99 Standard its defined that the int main() and int main (int argc, char* argv[]) OR int main (int argc, char** argv) should be the starting point … | |
Re: I have interesting solution other than Selection Sort, just for knowledge. You fetched the numbers from the stream and put it in the array, then sort the array using the desired algorithm. What if you make a sorted link list and insert in it directly?. just compare the complexities of … | |
Re: Well ! I don't think you don't know recursion, otherwise you wouldn't have such a good implementation :). good efforts :). let's have a expert look on that implementation, hope you'd agree. I don't like you Copy Constructor's Syntax. [code] void TreeType<ItemType>::operator=(const TreeType& originalTree); [/code] why? would be your question, … | |
Re: I don't know what your code really does, I just check the language semantics. [code] ilc *ob; ob=get_activities(ob); [/code] check the codding of get_activities(..), it returns pointer to array of object of type ilc but within the function get_activities (...). line number 300. [code] delete [] ob; [/code] so according … | |
Re: you just need to include [code] #include <fstream> #include <iostream> [/code] don't use .h suffix. also encapsulate the Dragon's function in some class and make that a static member. and your simplest logger is ready :). | |
Re: Hey! you are not considering all the cases, you are finding the sum of link list, NOT SUM IN THE LINK LIST. let me give you some example. lets suppose we have a link list containing following element 1, 5, 4, 3, 2, 8. and I tell you whether the … | |
Re: agreed with niek_e he has given you the good resource for selection sort. let me discuss what I know about selection sort. selection sort is simple it just select the element and put the selected element in correct position. in your case the data is 50, 90, 40. if you … | |
Re: I think you forgot to push the polygon element in the vertex. first you need to push element in the vector then use vector's at (index) function. if you want to assign, use array operator instead which returns the reference. and let you add element like below [code] m.Polygon.push_back (p); … | |
Re: first let me point out some problems in your existing code [code] //check that price is double/float i.e. 25.5 etc. double total (int qty, double price) { double t; t = qty* price; return t; } [/code] what ever the total is you need to return the total whether its … | |
Re: Try Reading Socket Programming. what you are actually doing is creating a server listening on Port, this can be achieved using WinSock on windows Plateform, same can be done on linux using the socket API defined for linux. [code] int main () { // Initialize the Socket Environment. // Create … | |
Re: Lets do some binary Tree. What your algorithm says. [quote] I pick a pivot p from a database S of strings, compute the median r of the distances of the string objects to p and then divide the objects into roughly equal-sized subsets S1 and S2 as follows: S1={o ε … | |
Re: Are you using Win32 API, MFC, WTL or Managed C++. | |
Re: returning iterator is perfectly valid C++ code. but if you need an object you can derefer the iterator. but the thing is that how will you identify where the object is found or not ( either by returning "" --> empty string) . The semantics of iterator define not found … | |
Re: difference b/w const and #define (macro). 1. Type Checking:- macros are not type safe where as const are type safe. since the macros are replaced by definition at the time of preprocessing (which is done before compilation). the storage area of macros is not defined where as const has static … | |
Re: Hey Sorting is a huge topic and there are several ways of sorting the data. which technique you want to use to sort this data. Radix sort can do a job. lets understand what you want 1 91 25 2 168 20 3 2080 46 4 680 56 5 15 … | |
Re: Hope the following code. helps. [code] int main () { ifstream inputFile ("C:/inputFile.txt"); if ( !inputFile.is_open ()) { cout<<"File not opened"<<endl; } string line; string userId, answers; while (std::getline (inputFile,line, '\n')) { std::stringstream inStream(line); inStream>>userId; std::getline(inStream, answers, '\n'); cout<<"The userId is :"<<userId<<" and answers are: "<<answers<<endl; } inputFile.close (); return … | |
Re: Lets analyze what the mergesort do. The first Function you've written [code] void merge_sort(int low,int high) { int mid; if(low<high) { mid=(low+high)/2; merge_sort(low,mid); print("decomposed", low, mid); merge_sort(mid+1,high); print("decomposed", mid + 1, high); merge(low,mid,high); } } [/code] it simply spit the array of size n from mid and do it untile … | |
Re: great stuff to implement. do you understand the cin, stringstream, check to see the functionality they provide, and what they basically are ( HINT: they are specialization of templates ). if you are good C++ developer then you'll figure out what they exactly do. [code] typedef basic_stringstream<char, char_traits<char>, allocator<char> > … | |
Re: well I can see several errors. I don't know your level of C++, but assume you must be good enough, because you are using STL. [code] struct attribute { const char* name; int id; }; int main () { static attribute attr; std::string str = "Laiq"; attribute* attrPtr = 0; … | |
Re: Narue its a part of utility.h in VS2008 and in Utility.h and xstring on VS2005. | |
Re: you have problem with Fibonacci heaps or Dijikstra algorithm. I think you have coded the algorithm using array, so you might getting the problem with fibonacci heaps, paste your efforts regarding fibonacci heaps. | |
Re: 1. avoid using Magic Numbers 6, 12. make them constants. with meaningfull names. i.e. [code] const int MONTHS=12; [/code] 2. Associate the pointer with type or identifier not in the middle [code] double *monthRanking(double * aYearData) [/code] it should be like this [code] double *monthRanking(double *aYearData) // OR double* monthRanking(double* … | |
Re: make sure you understand the anciant dragon's post completely :). your algorithm doesn't do the right thing in reading it should read after opening file directly remove your first read call one more thing return the vector<>& from readFile function replace the file.read (...) , problem lies there. you will … | |
Re: Lets do some sorting. First of all the sorting technique you are using is sort by swapping. famous as a bubble sort. before sorting lets improve your code. which is more strutured Why are you keeping the two related things separate? why don't keep these two things rainfall & month … | |
Re: I have analysed your code and finds that the nth_element works as it should, I tested it on VC++ 2005 and VC++ 2008. After changing the code you suggested [code] for ( long i = 1 ; i <= 1 ; i++ ) { generate ( arr.begin(), arr.end(), myIntegerRand ); … | |
Re: what about the following code. [code] template<class T> T const& Absolute(T const& v) { if (v < 0) { return (v + (-v*2)); } return v; } [/code] requires minute mathematics. | |
Re: set the prototype of functions like this [code] void setW(); void setL(); [/code] replace above two with [code] void setW(double num1) void setL(double num2) [/code] remember to add semicolon where required. | |
Re: Deleting a node is not difficult. let me tell you the algorithm. Algorithm. Delete (value) 1. Check if head is null return 2. if the value matches head set temp = head set head = head->next free head. 3. Link previous = head; 4. Link temp = head->next; 5. while … | |
Re: why don't you traverse the array and check if the value is non zero add them, [code] // traverse the array. if ( a[i] != 0) sum += a[i]; // after loop cout<< sum; [/code] this is what i understand from your description. | |
Re: writting a better code is not difficult until and unless you think that you will not avoid the things you know and well understand the problem. first of all this is not an OOP. if you are willing to write OO Program you should think in terms of objects and … | |
Re: your link list implementation is stack based implementation, to reverse it you first need to know how to reverse the list. there are three ways of doing this. 1. Recursive. 2. using explicity stack. 3. using iterative approach. ( the one you are using). your code says the following [code] … | |
Re: one thing, return 0 from main not 'o' (not o) your code will work try this [code] j = rand()%50; [/code] and replace your condition [code] if (!(j >= 50&&j<=0)) cout<< j<<endl; else cout<<"out of range"<<endl; [/code] and only print the j what is does ? requires minute mathematics. | |
Re: what it actually does. Let me tell you what it actually does, and what it should do first what it does [code] template <class T> void myVector<T>::grow(){ while(size >= capacity) { T* temp; temp = data; capacity *= 2; data = new T[capacity]; for(int i = 0; i < size; … | |
Re: _cdecl and _stdcall has some difference, I think you are calling the function from the library written using different calling convention than the one you are using. Its basically a name decoration issue, not resolved by linkers. In VC++ 6.0 _cdecl is the default calling convention. _cdecl In this type … | |
Re: Just pass n-1 as the last argument to mergesort function | |
Can any1 tell me about the tutorials and description regarding new c++ standard. specially the improvement in STL. | |
Re: [quote=mapaputsi;325533]Can anyboby help me i really dont get the feeling of big o notation, i just want to understand it.[/quote] Big O Notation is used to denote the complexity of the algorithm ( worst case complexity)... for example the following code has complexity O(n) [code] for(int i=1;i<=n; ++i ) { … | |
I want to generate the following pattern using for() loop only.... how can i do this i've tried but unfortunately failed to solve .... when user inputs 3 [COLOR=#008000]1 1 1 1 1 1 2 2 2 1 1 2 3 2 1 1 2 2 2 1 1 1 … | |
Re: [quote=virsa;320615]access c++ private data members without using the " Friend" type main() can be a friend function?[/quote] its against OOP concept but still... this might help [code] [COLOR=#0000ff]class[/COLOR][COLOR=#000000] A { [/COLOR] [COLOR=#0000ff]private[/COLOR][COLOR=#000000]:[/COLOR] [COLOR=#0000ff]int[/COLOR] a; [COLOR=#0000ff]char[/COLOR] b; [COLOR=#0000ff]public[/COLOR][COLOR=#000000]:[/COLOR] A(): a(1), b([COLOR=#800000]'A'[/COLOR]) {} }; [COLOR=#0000ff]int[/COLOR][COLOR=#000000] main() [/COLOR] { A* obj = [COLOR=#0000ff]new[/COLOR] … | |
i want to calculate the complexity of the following code snippet [code] for(int k=0;k<n; ++k) for(int j=0; j<k; ++j) for(int i=0; i<j; ++i) cout<< "Hello World" <<endl; [/code] here! i got the hint! that summation of natural numbers series would be used if its correct why ? bit confused:sad: | |
please help me understand the folowing code.... [code] class A { int a; public: A() : a ( 0 ) {} int get() { cout << "Hello WOrld " << endl; return 0; } }; int main( int argc, char** argv ) { cout<< ((A*)3)->get() << endl; return 0; } … | |
Re: You can get the [B]effect [/B]of Virtual Constructor by using Factory design pattern...... which doesn't violates the objected oriented rules specifically inheritance structure........ but its helpful. and some times needed.... The vptr not necessarily initialized by the compiler in the constructor it might be initialized during the construction... its totally … | |
Re: This is the first time i found such code to read from the ostream....... i can just help you with the syntax i m also trying to code this... soon i'll conquer or will give up..... :d. [code] [COLOR=#0000ff]class[/COLOR][COLOR=#000000] PhoneNumber {[/COLOR] string area_; string exchange_; string line_; [COLOR=#0000ff]public[/COLOR][COLOR=#000000]:[/COLOR] [COLOR=#000000][/COLOR] PhoneNumber(string … | |
Re: The problem you've described might consists of pair of key value... using pair< T1,T2> template is agood choice .....then. I totally agree with salem, every Data Structure has some advantages and tradsoff, its depends upon your need and how it fits the scenario... in LIFO(Last in First Out) link list … | |
I want to read a Source Code file and separate the lexemes (words) and want to track the line number with the separated words? I just come up with the raw code like that... i) A struct holding a string , int pair; ii) making the link list of above … | |
I've just tried to code the Binder2nd, almost same as standard code provided in functional...... please point out the mistakes........ and suggest me guidelines to write effective code.......... [code] [COLOR=#0000ff]#include[/COLOR][COLOR=#000000] <iostream>[/COLOR] [COLOR=#0000ff]#include[/COLOR][COLOR=#000000] <vector>[/COLOR] [COLOR=#0000ff]#include[/COLOR][COLOR=#000000] <functional>[/COLOR] [COLOR=#0000ff]#include[/COLOR][COLOR=#000000] <algorithm>[/COLOR] [COLOR=#0000ff] using[/COLOR][COLOR=#000000] [/COLOR][COLOR=#0000ff]namespace[/COLOR][COLOR=#000000] std;[/COLOR] [COLOR=#000000][/COLOR] [COLOR=#0000ff] template[/COLOR][COLOR=#000000] <[/COLOR][COLOR=#0000ff]class[/COLOR][COLOR=#000000] _Fn> [/COLOR] [COLOR=#0000ff]class[/COLOR][COLOR=#000000] Binder2: [/COLOR][COLOR=#0000ff]public[/COLOR][COLOR=#000000] … | |
Re: Pointer to function are the pointers which have the ability to call the function pointed to by them.As the ordinary pointers take the address of variable and can change the value pointed by them, the function pointer almost does the same. [code] #include <iostream> #include <string> using std::string; using std::cout; … | |
Re: I can just explain you how to code on code it in any language of your desire Algorithm Suggest: - i) visit the left Subtree ii) visit the Node iii) visit the right Subtree You are interested in making the Non Recursive version of the above traversal. You can make … | |
Re: [quote][I]What is the Importance and uses of data stuctures in Programming using C/C++ when using it?[/quote][/I] [I]I think data storage and retrieval + usage of memory effeciently etc are the concepts that are the basis of Data Structure,...[/I] [I]answer my Few Question: - [/I] [I]In a drawing software can you … |
The End.