2,712 Posted Topics

Member Avatar for aaronmk2

[CODE] //O(n) for (int j = 4; j < n; ++j) { cin >> val; } //O(n) for (int i = 0; i < j; ++i) { b = b * val; } //misformatted? for (int k = 0; k < n; ++k) c = b + c;} } [/CODE]

Member Avatar for mrnutty
0
145
Member Avatar for Fbody

>>I'm aware of the std::map container, and I had considered it. The problem is the strict weak ordering that it requires is not appropriate for the problem domain as the ordering is based on the first member of the pairs and I need the values sorted based on the second …

Member Avatar for Fbody
0
3K
Member Avatar for Tahir33

Ok, does the tower of happiness has all the happiness that I need ? Does it include megan fox in there? How about the best food in the world? How about a infinite power machine? So seriously, whats your problem?

Member Avatar for Tahir33
-3
207
Member Avatar for aaronmk2

For Binary search trees or any data structures that are [i]recursive[/i] in nature, you will want to implement a recursive algorithm to solve most of its problems.Its not only easier to write, but its easier to understand as well. So with that said, consider this recursive algorithm that finds the …

Member Avatar for mrnutty
0
246
Member Avatar for athar89
Member Avatar for mrnutty
0
449
Member Avatar for ilkeamasya
Member Avatar for emmybear

Java is a good source of code that is event driven. For example, when you click a button and event is created, and parties are notified of such events.

Member Avatar for Looben
0
95
Member Avatar for bmos31
Member Avatar for corby

>>Which array-based operations are O(1)? >>inserting item or deleting item in unsorted array not quite, what happens if we insert in the middle of the array. How about accessing the data? >>Which linked-list operations are O(1)? >>inserting and deleteing item in unsorted lsit true. >>Which array-based operations are O(n)? >>traversing …

Member Avatar for corby
0
102
Member Avatar for burcin erek

Note: [icode]bool sayi[10] = {false}; [/icode] will initialize the whole array to false. So there is no need for sifirla function. Its hard for me to understand your code. I suggest you do something like the following : [code] int randRange(int min, int max){ return rand() % (max-min) + min; …

Member Avatar for burcin erek
0
183
Member Avatar for n0de

try [icode] cout << setprecision(10); [/icode] where you need to include [i]iomanip as a header[/i]

Member Avatar for n0de
0
203
Member Avatar for frogboy77

You are not able to create a large array because there isn't enough memory in stack memory. So you have to allocate it and use heap memory like so : [code] int size = 10e10; int array = new int[size]; //..utilize array delete [] array; //release memory for later use …

Member Avatar for frogboy77
0
322
Member Avatar for chintan_1671

>>[B] if((node -> data %2) != 0)[/B] bad coding. Make a [icode] bool isOdd(int n){ return n % 2 == 1; }[/icode] function and use it like so [icode]if( isOdd(node->data) ){ ...} [/icode]

Member Avatar for chintan_1671
0
2K
Member Avatar for Blitze

>>[B]all the vector class is, is a linked list[/B] Are you implying that a std::vector class is implemented using a linked list data structure? Example : [code] template<typename T> class SpecialList : std::list<T>{ public: //add functionalities here }; [/code] Or use composition : [code] class SpecialList{ private: std::list<int> listOfInts; public: …

Member Avatar for Blitze
0
97
Member Avatar for #include<>

Something else to consider : [code] template<typename T, int ROW, int COLUMN> class Array2D{ private: T _array[ROW][COLUMN]; public: Array2D(){/*initialize _array*/} //Array2D methods/operations }; int main(){ Array2D<int,5,5> array; } [/code]

Member Avatar for mrnutty
0
110
Member Avatar for bigwhiteegg

Your saying this doesn't work : [code] struct GrowableArray{ unsigned size; double *array; } void initialize(GrowableArray& g){ g.size = 0; g.array = 0; } [/code] What errors do you get? Post some actual code.

Member Avatar for bigwhiteegg
0
3K
Member Avatar for Ana_Developer

The pointers makes me weary. I don't see a reason why you need to use pointers. Remove all instance of them, and use proper data structures like std::vector or std::list. What type of runtime exception do you get? Stack overflow? Invalid index ? writing into memory exception? Also, do not …

Member Avatar for Ana_Developer
0
223
Member Avatar for it-lady

$100 dollars per homework, plus extra depending on the assignment. Or else you need to do this on your own, with some of us giving you hints.

Member Avatar for it-lady
-1
100
Member Avatar for ganesh_IT

Here is the prototype : [code] friend istream& operator >>(istream& stream, Data_Time& date){ /* code to read here */ /* return ... */ }; [/code] Make that your member function.

Member Avatar for sowmyadantuluri
0
162
Member Avatar for pandaEater

Are you guys sure about that runtime? The first loop runs n times. And for each n, it runs 2^n. Thus the total runtime is O(n*2^n)

Member Avatar for gashtio
0
381
Member Avatar for mrnutty

Just for Fun, and for reference to the web searchers, lets start a series of problems in computer science thats ranges in difficulty from [1,10], where 1 is easy, and 10 is harder. Maybe I and others will learn something useful from this. The following exercise is meant as an …

Member Avatar for csurfer
0
125
Member Avatar for dfxover
Member Avatar for kuchick32

Ok now you need to use a for loop. Have you used it before? Give it a try. Inside the for loop, you ask the user for a number and insert it into the array.

Member Avatar for kuchick32
0
101
Member Avatar for cchase36

Does the getTail() return the last element or one passed the last element? Is it valid to do this [icode]cout << (a.getTail())->Coeff << endl;[/icode] Also what is the exact error message?

Member Avatar for mrnutty
0
50
Member Avatar for _Nestor

I didn't test the below code, but there is no need for the vector in your code. Just go directly to string. [code] //supports only positive numbers string convertToBase(long num, int radix){ assert( radix > 0 && radix < 36); //base range[1,36) assert( num > 0); string ans = ""; …

Member Avatar for Schol-R-LEA
0
171
Member Avatar for diagramatic

Some styles that I use : [code] class Class{ //Classes start with capital letter m_var; }; [/code] [code] bool func(){ //notice the '{' being in the same line as the function } [/code] [code] int *p = 0; [/code] [code] string firstNameList; //naming convention [/code] I use the "//" inline …

Member Avatar for mike_2000_17
0
186
Member Avatar for myk45

easy way out : [code]void doIt(int start, int end){ if(start < end){ printBinaryRepresentation(start); } else doIt(start+1,end); } [/code]

Member Avatar for mrnutty
0
1K
Member Avatar for XodoX

Easy enough. What you need to do is the following : [code] 1) Populate the list with words from the file. 2) Start from the beginning, check if the first word is correct, i.e first letter is capitalized, and spelled correctly. 3) Check if the second word is spelled correclty, …

Member Avatar for XodoX
0
168
Member Avatar for Fbody

Its not possible to do what you are doing. The best you can get is : [code] template<typename T> class CategoricalStats { ... } template<typename T> struct QualitativeStats{ typedef CategoricalStats<T> Type; } //... QualitativeStats<float>::Type qstats; [/code] You have that ugly extra level of indirection, but it gets the job done. …

Member Avatar for nbaztec
0
1K
Member Avatar for qqwushi12345
Member Avatar for Stefano Mtangoo

[B]>>Look up C++ for dummies[/B] HAHAHAHAHA... We can't inherit constructors, so there is no need for them to be virtual.

Member Avatar for Stefano Mtangoo
0
573
Member Avatar for Nandomo

use this simple function, : int getInt(const char *msg){ cout << msg ; int n = 0; while(!(cin >> n)){ cout << "Input failed...try again\n"; cin.clear(); while(cin.get() != '\n'); } return n; } Basically, the `while(!(cin>>n))` checks the cin gets what we are expecting it to get. We are expecting …

Member Avatar for Nandomo
0
2K
Member Avatar for timb89

So if I get this straight, you have a file with "pre-order" data. And your goal is to print out the data in a post order manner correct? If so then, what you could do is, take the pre-order data, store it in an array, call it PREARRAY. Then construct …

Member Avatar for timb89
0
164
Member Avatar for maharjun

All of this could have been avoid by [B]not using raw pointers[/B]. If you can, avoid pointers all together. If not, then use smart pointers.

Member Avatar for mike_2000_17
0
1K
Member Avatar for gwahl

[QUOTE=gwahl;1350134]is it possible to make an array of variables?[/QUOTE] Its not only possible, its also possible to make an [i]arrays of arrays of arrays of pointers to an arrays of arrays that takes values.[/i]

Member Avatar for mrnutty
0
99
Member Avatar for vitin6039

>>[B]int newSize=size*=2;[/B] OUCH! That equivalent to : [icode]size = size * 2; int newSize = size[/icode] Which means that the variable size is twice its value. You wanted [icode]int newSize = size * 2[/icode]. Thus leaving the variable size unchanged. Make sure you call [I]delete [] expandArr[/I] at the end …

Member Avatar for LevyDee
0
114
Member Avatar for Bri426

Also, there are some problems with your letterGrade function. It should look something like this : [code] char letterGrade(int score){ char grade = 0; if(score >= 90) grade = 'A'; else if(score >= 80) grade = 'B'; else if(score >= 70) grade = 'C'; else grade = 'F'; return grade; …

Member Avatar for mrnutty
0
144
Member Avatar for fukki

Don't declare it globally. Your teacher will take points off. Instead do this: [code] void listmodified(Car car[], int size){ /* some code here */ } int main(){ warehouse car[2]; /* some code here */ listmodified(car); } [/code] so that way you are using the same car thats in main inside …

Member Avatar for NathanOliver
0
119
Member Avatar for 1989sam

Do this [code] queue<state> stateQueue; state s; //initialize s stateQueue.push( s ); //...blah blah a blah [/code]

Member Avatar for mrnutty
0
5K
Member Avatar for vikalp-singh

Most people use C++ as base. Meaning that, they use some type of library that can handle the graphics, and use C++ to code the logic. Every time you make a project, you are making software. For example, when you make a program that checks if the string is a …

Member Avatar for mrnutty
0
113
Member Avatar for cogitoergosum18

@OP here is some syntax help: [code] #include<iostream> using namespace std; #include <fstream> //returns the mean of the array double meanArray(double N1[], int size); int main() { const int MAX_DATA = 1000; double fileData[MAX_DATA ] = {0}; //initialize the array to contain 0 ifstream fileInput("data.txt"); //open the file /* read …

Member Avatar for mrnutty
0
299
Member Avatar for daviddoria

The problem you suggested should be fixed by modern compilers. Which one are you using?

Member Avatar for mrnutty
0
220
Member Avatar for Rizwan606

[QUOTE=Rizwan606;1347522]Im not talking about the even numbers stored in array,,But im saying that the numbers which are stored on even index of array could be displayed?[/QUOTE] Think before you speak. Thats exactly whats he talking about. Fir you need to know how to generate even numbers such as {0,2,4...}. Then …

Member Avatar for Rizwan606
0
384
Member Avatar for ToiNKieZ

1010 in decimal = 1 * 2^3 + 0 * 2^2 + 1* 2^1 + 0*2^0 = 8 + 0 + 2 + 0 = 10 Thus 1010 in decimal is 10.

Member Avatar for stereomatching
0
148
Member Avatar for vskumar19

The first one basically reads as follows : "Create a string object called S where S refers to the statically defined string object "abc". The second one reads as follows : "Create a string object called S, where S points to a new dynamically allocated string object with the value …

Member Avatar for ~s.o.s~
0
76
Member Avatar for smeghead007

Pattern # 3 : [code] $$$$$ // Print('$', 5) && Print('5', 0) $$$$5 // Print('$', 4) && Print('5', 1) $$$55 // Print('$', 3) && Print('5', 2) $$555 // Print('$', 2) && Print('5', 3) $5555 // Print('$', 1) && Print('5', 4) [/code]

Member Avatar for smeghead007
0
157
Member Avatar for Rayanjaha

Or another possibility to this stupid problem : [code] struct WidthProperty{ unsigned width; }; struct HeightProperty{ unsigned height; }; class Rectangle{ WidthProperty w; HeightProperty h; public: unsigned area(){ return w.width * w.height; } }; [/code]

Member Avatar for mrnutty
0
117
Member Avatar for daviddoria

>>[B]although library implementations of std::sort usually have optimizations so it doesn't degenerate to O(n^2)).[/B] Does that mean the stl guarantee that they use quicksort for std::sort?

Member Avatar for Narue
0
107
Member Avatar for vbx_wx
Member Avatar for sandy#123
0
455
Member Avatar for kuchick32

Sure, we would be more than glad to help you. But first there are a few things you should know : 1) We tend to help people that are "stuck on a problem" or give them a little push and whatnot. We are not here to do your homework for …

Member Avatar for hpfreak080
0
123

The End.