- Strength to Increase Rep
- +0
- Strength to Decrease Rep
- -0
- Upvotes Received
- 6
- Posts with Upvotes
- 6
- Upvoting Members
- 5
- Downvotes Received
- 0
- Posts with Downvotes
- 0
- Downvoting Members
- 0
66 Posted Topics
Re: You cant use [ICODE]int[/ICODE] for such big numbers as 100!, since [ICODE]int[/ICODE] usually can handle 32bit value. solution is google: "c++ big integer" | |
I've been trying to solve SQL exercises from [url]http://www.sql-ex.ru/[/url] for some time. You can find database description below: Short database description "Computer firm": The database scheme consists of four tables: Product(maker, model, type) PC(code, model, speed, ram, hd, cd, price) Laptop(code, model, speed, ram, hd, screen, price) Printer(code, model, color, … | |
Re: [QUOTE=firstPerson;1243603]Maybe some code would help : [code] Shape allShapes[3] = { Shape(), Rectangle(), Circle() }; [/code][/QUOTE] AFAIK polimorphism works only for pointers and reference, so this should be array of pointers. | |
Re: Looks like missing header. [ICODE]#include <cmath>[/ICODE] should help. | |
Re: It's c-style string. You can read more here: [url]http://www.cprogramming.com/tutorial/lesson9.html[/url] | |
Re: You have problems with semicolons. Lines 48-50: remove semicolon between function name and round brackets. You can also delete semicolon at the end of each of these lines. Line 51: missing semicolon after [ICODE]return totalCost[/ICODE] line 69: missing semicolon at the end of the line | |
Re: You need 3 things: - std::pair ([url]http://www.cplusplus.com/reference/std/utility/pair/[/url]) to keep both (name and the number) connected - std::sort ([url]http://www.cplusplus.com/reference/algorithm/sort/[/url]) - You need to create your own comparision function (You need to compare only second object from your pair object) - some kind of container, f.e. std::vector | |
Re: I can see lot of pointers and [ICODE]new[/ICODE]/[ICODE]delete[/ICODE] stuff in your code. So the question is if You overloaded operator=. Cause maybe shallow copy causes troubles? | |
Re: Use code tags. AFAIK the problem is in your finderase function. Let's assume that your vector looks like this: v[0]=5; v[1]=5; v[2]=6; v[3]=6; so the vector size is 4. Now, you want to delete value 6. Your finderase function looks like this: [CODE]void finderase(vector<int>&v,int &num) { for(int i=0;i < v.size();i++){ … | |
Re: What's more You missed [ICODE]"[/ICODE] at line 28. And read about using arrays, cause this: [CODE]person abc[3]; for (int i=0; i<3; i++) { abc.input(); } [/CODE] is completly wrong. | |
Re: you have some problems with constructing [ICODE]for[/ICODE] loop. How many times this loop will be executed: [CODE]for(i=0; i < 0; i+=2)[/CODE] ? And here, the loop termination 'condition' is wrong: [CODE]for(i=0; vector_b.size(); i++)[/CODE] | |
Re: add line [CODE]cout<<n<<endl;[/CODE] to your constructor and destructor and see results. | |
Re: You mean something like this: [ICODE]int main(int argc, char *argv[])[/ICODE] ? If so, google: c++ int main parameters for more info. | |
Re: Looks like your post is not giving 'correct output' as well... | |
Re: Reference to vector is like just "another name" for your original vector. You still work on memory taken by your original vector. So if you worry, that internal vector could be copied - you don't have to. It won't be copied. | |
Re: 1. Use code tags 2. Looks like you never increase [ICODE]firstNum[/ICODE], so [ICODE]while(firstNum != secondNum) [/ICODE] is always true. | |
Re: That's what I I have found at first look: lines#24-26: [CODE]for (int i = 0; i < 10; i++) { if(a[j] < a[i - 1])[/CODE] if [ICODE]i=0[/ICODE] and you have [ICODE]a[i-1][/ICODE], then You get [ICODE]a[-1][/ICODE]. That's the problem You have to solve. | |
Re: Your numbers ARE being read. In fact if you look closer at your output You can see, that they all are read and something more is read (some trash). Why? You have only 34 values in your data file, but you try to read 124 values ([ICODE]SIZE_MONTH *SIZE_DAYS[/ICODE]) from the … | |
Re: AFAIK you cant call [ICODE]delete[] temp[/ICODE] here (line #21). Am I right? | |
Re: Look closer at line #14: [CODE]cout >> (a + b);[/CODE] | |
Re: I'm really confused, now. Is this valid: [CODE]char word[]="\0"; cin>>word;[/CODE] | |
Re: Maybe [ICODE]map/multimap[/ICODE] is the solution. [ICODE]N2O1[/ICODE] could be used as the key and [ICODE]NitrousOxide[/ICODE] as stored value. All elements in map are implicity sorted. | |
Re: use [ICODE]getline()[/ICODE] and [ICODE]istringstream[/ICODE] and your problem should be solved. | |
Re: If You have 4 cities, you need 4x4 2d array (f.e. dist[4][4]) to store distance between each city. Another array(f.e. cities[4]) is needed to store city's number. Now, everything you need to do is to calculate all possible permutations of array cities (use std::random_shuffle in loop) and calculate total distance … | |
I started to learn SQL recently. I downloaded some kind of assignment, where the goal is to design small database. I have two tables listed below: [CODE]create table SEA ( SEA_NAME varchar(50)constraint sea_prj_key primary key, AREA numeric(18, 0), );[/CODE] and: [CODE]create table NATION ( CTRY_NAME varchar(50)constraint sea_prj_key primary key, AREA … | |
Re: Use std::list to read data from file, than copy all data to std::vector. | |
Re: [CODE] for(r=0; r<board; r++) { //iterate through all elements from chosen row of board array //r is your row number in area array //value of current element from board array is an index of element in r-st row of area array and this element should be set to 1 } … | |
| |
Looks like I miss something, so I need your help, guys. [CODE] #include <iostream> using namespace std; int main() { int* ptr=new int(2); const int* constPtr=ptr; int** ptr2; //... do memory stuff for ptr2 const int** constPtr2=ptr2; typedef int** intPtr; const intPtr ptr3 = ptr2; return 0; } [/CODE] Questions: … | |
Re: You can store all permutations in 2D vector. Then You need to create another vector with M! elements (indexes). Random_shuffle vector with indexes and you have order in which You should read data from 2D vector (with all permutations). But since (N < M) this algorithm is little overkill, because … | |
Re: see this topic: [url]http://www.daniweb.com/forums/thread242984.html[/url] | |
Re: Use code tags. Probably your problem is in `void sequence::read()` method. You store some data to `local vector<int> v2`, then you try to read from `sequence::v2`, but this is completly another vector. And since it's not populated, you get seg fault. There are some other issues in code. You shuold … | |
Re: what's interesting he already used random_shuffle at line #108: [CODE]random_shuffle(item.begin(), item.end());[/CODE] | |
Re: @Clinton Portis: I suppose, at line #3, you wanted to write: [CODE]vector<vector<char*> > words; // this is vector of char* vectors[/CODE] if so, this won't work: [CODE]words.push_back(temp);[/CODE] Can be done like this: [CODE] vector<char*> v_temp; for(int i=0; i<wordcount; i++) { cout << "Enter a word (19 chars or less): "; … | |
Re: 1. Create istringstream (f.e. [icode]istringstream my_stream[/icode]) from string stored in vector. 2. Create a while loop (until you reach eof of the stream) 3. Use operator >> and try to save to int variable (f.e. [icode]int my_int[/icode]). [icode]my_stream>>my_int;[/icode] 4. Check state of the stream. If it returns false, means that … | |
Re: "nothing comes up on the output screen" - what does it mean? Doesn't menu show up on th screen? If it doesn't maybe problem lies here [CODE] void loadList(studentList & students) { ifstream infile; infile.open("registration.dat"); int student; while (!infile.eof() ) { infile >> student; students.push_back(student); } infile.close(); } [/CODE] When … | |
Re: Suppose you have two arrays: [CODE]tab1[]={1,1,1}; tab2[]={1,0,1};[/CODE] First iteration: [ICODE]tab1[0]==tab2[2] =>b=1;[/ICODE] second iteration: [ICODE]tab1[1]!=tab2[1] =>b=0; (so far, so good)[/ICODE] third iteration: [ICODE]tab1[2]==tab1[0] =>b=1 (again!)[/ICODE] The loop is over and you return b, your function says that arrays are equal which is not true. Solution: end the loop after second iteration … | |
Re: or just use random_shuffle if u can. [CODE] #include <ctime> #include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { srand ( unsigned ( time (NULL) ) ); vector<int> numbers(50); vector<int> ordinary(10); vector<int> extra(5); for (int i=0;i<50;++i) numbers[i]=i+1; //roll for ordinary random_shuffle(numbers.begin(),numbers.end()); copy(numbers.begin(),numbers.begin()+10,ordinary.begin()); //roll for extra random_shuffle(numbers.begin(),numbers.end()); copy(numbers.begin(),numbers.begin()+5,extra.begin()); … | |
Re: [CODE] int newsize= size++; Branch *temp=new Branch[newsize]; for(int i=0;i<size;i++){ temp[i]=branches[i]; } temp[size]=b; [/CODE] Let's say size is 10. So newsize is also 10. Then you increase size and now size=11. So your loop goes from 0 to 10. But temp[10] doesnt exist. Also temp[size] (which is temp[11] in this example) … | |
Re: AFAIK this should work: [CODE] const int nulls=atoi(argv[2]); int arry[nulls]; [/CODE] | |
Re: use [iCODE]std::getline()[/iCODE] with delimeter set to ';'. see: [url]http://www.cppreference.com/wiki/string/getline[/url] for more details | |
Re: Line 23. cout<<data[(i*rows)+j]<<" "; Why do You use variable rows here? Think about it:) | |
Re: create do-while loop in main function[CODE] do { //lines #19-#32 //ask user if he wants to quit ("press q to quit") //get his answer while (/*!(check if q was pressed)*/); [/CODE] What's more I suppose You'll have to reset some arrays/variables. | |
Re: You forget to initialize random seed: [CODE]srand ( time(NULL) );[/CODE] and this: [CODE]cards[r][c]=rand()%8+1;[/CODE] gives you just one random number. | |
Re: What's more you should increment count variable at the end of the while loop, not at the beginning (before assignment). | |
Re: I don't see neither your class Manager definition, nor array 'm' def, but I guess something like that, should work: [CODE] Manager man1=(10, "name", "name", "sfsf", 15, 45, 10); m[1]=man1; [/CODE] | |
Re: I have a question. Lines #21, #22 and #23: [CODE] employee *first=NULL; first=new employee; if(first==NULL){ //... [/CODE] If you allocate memory for pointer 'first', is that possible for 'first' to be NULL unless you get some exception? | |
Re: change your do-while loop [CODE]do //.. while (score[x] != -1);[/CODE] to while loop: [CODE]while (cin >> score[x] && score[x]!=-1) { //... } [/CODE] Some other small changes will be necessary as well (x variable starts from zero and it should incremented at the end of the loop). |
The End.