|
Hi.
Suppose i have a function that takes an array and its length.
That function should search the entire array for each element and return a result.
example:
<br />
<br />
int rec(int arr[], int length)<br />
{<br />
if(length == 0)<br />
return 0;<br />
<br />
searchingarr(arr,length -1);<br />
<br />
rec(arr[],length - 1);<br />
}<br />
Now . i cant use loops(while or for), no static variables. only one function inside the rec and use only recursive. i cant put a sign in the array that points to the end either.
the problem here is that i want that each time im calling "searchingarr" i paste him the length of the array. here, the length is substracted by 1 each time i call rec.
|
|
|
|
|
Could you restate your question exactly?
What is the function looking for? What is it supposed to return?
|
|
|
|
|
the function(searcharr) should take an element and check if there is a sequence of summed elements that is equal to the index of that element.
example arr{ 1 , 3, 2 , 0 , 0 , 3}
arr[2] = 3.
because 2(i=2) + 0(i=3) + 0(i=4) gives us the value 3 that is the length of the sequence that when summed gives us the value of the index(2).
|
|
|
|
|
|
arr{ 1 , 3, 2 , 0 , 0 , 3}
the index 2 in the array have a value that is equal to the sequence of 3 elements(2 , 0 , 0) thus the returning value is 3.
|
|
|
|
|
So what is your algorithm?
Can you write the algorithm in words?
|
|
|
|
|
|
It looks like homework.
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
I'm attempting (and failing horribly) to put a function that draws multiple circles into an array.
I will be using flags to turn the circles on and off, and I need to initialize it in my main function so the random generator won't run every time the screen refreshes. This is what I have so far in putting my circles in an array:
I get an error on this first line here saying : c:26: error: expected identifier or ‘(’ before ‘[’ token
I've no idea why, it looks like it's set up right to me
struct Row1[15] = {drawCircleRow1()}
int drawCircleRow1()
{
for
(o=0; o<15; o++)
{
random_generator(0,3);
glPushMatrix();
glTranslatef((o+1.9)*28,455,1);
if (randomValue == 0)
{
glColor3f(0,.5,0);
}
else if (randomValue == 1)
{
glColor3f(.5,0,0);
}
else
{
glColor3f(0,0,.5);
}
glLineWidth(1.0);
drawCircle(14,200);
glPopMatrix();
}
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
ballPhysics();
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA);
glutInitWindowSize(WIDTH, HEIGHT);
glutCreateWindow("Bubble Buster");
glutDisplayFunc(displayFunction);
glutSpecialFunc(functionSpecial);
glutKeyboardFunc(keyboardFunction);
glutTimerFunc(1,timerFunction,0);
gluOrtho2D(0, WIDTH, 0, HEIGHT);
glClearColor(1, 1, 1, 0);
glutMainLoop();
return 0;
}
|
|
|
|
|
"o" is by far the worst identifier one could possibly choose for a variable as it is short (OK, so are "i" and "n"), and easily confused with "0".
|
|
|
|
|
Nah, 'O ' is worse. And 'thisIsTheOuterLoopIndex' even worse.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
CPallini wrote: 'O' is worse. And 'thisIsTheOuterLoopIndex' even worse.
Nope. 'O' is better than 'o' as you have better probability in finding (and replacing) those in an editor without hitting keywords such as 'for' and 'continue'; and 'thisIsTheOuterLoopIndex' is self-descriptive which is good (unless it were incorrect).
|
|
|
|
|
Luc Pattyn wrote: 'thisIsTheOuterLoopIndex' is self-descriptive which is good
Way too long. Maybe it could be reduced to an acronym? You know, something like tIT_OLI?
|
|
|
|
|
Well, acronym is appropriate with T heO uterO uterL oopO nlyN eededG lolbal...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
You know, I hear that all the time...
|
|
|
|
|
Luc Pattyn wrote: 'thisIsTheOuterLoopIndex' is self-descriptive
Nope: it's idiotic (well, it's a self-descriptive-idiotic identifier).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
|
Good night, Luc.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
You really need to study basic array operations before trying to tackle something like this. There are so many things wrong with the first line alone it's difficult to know where to start...
1) Is Row1 a type you've defined? (It looks like it, since you say it's a struct...)If so, the array declaration is missing a variable name. Or...
2) Is Row1 the variable name? (It looks like it, since you're trying to initialize the array with int's, and not Row1 objects.) If so, you're missing the type, and you misuse the struct keyword...
Like I said, I'd suggest hitting the books and studying array basics. It's really difficult to offer advice on more complicated issues like ball movement if errors with the basics keep us from understanding your intent.
And thanks for using the code block tag. Not to be a nag, but you still need to look at standard indentation practices - reading your code is more difficult than it need be. (Hint - select the code in Visual Studio and simultaneously press Shift+Alt+F.)
Just trying to help, man.
|
|
|
|
|
Alright, I'll go read up on arrays some more, do you know any good sites that explains arrays using C?
I'm using Ubuntu, not Visual Studio, I've been tabbing over myself.
|
|
|
|
|
Chidori-chan wrote: do you know any good sites that explains arrays using C?
Buy any book on C; Kernighan & Ritchie wrote the definitive one some thirty years ago, which explains everything in concise detail.
|
|
|
|
|
Here, check these out -
C++ Arrays[^]
C++ Beginner's Guide[^]
The second one is an ebook that you have to download a chapter at a time. Check out chapter 4.
Don't get discouraged. You just need to get a couple basic concepts under your belt and the program will probably fall into place pretty easily.
|
|
|
|
|
Hi,
I have a small project and I need help on how to get the complete path and filename on Drag and Drop to a listbox. Afterwhich, I have to run another application to process the file and output the result on the same path and with a different filename. I'm using Visual C++ express edition 2005 (windows froms).
roughly like:
private: System::Void listbox1_DragDrop(System::Object^ sender, System::Windows::Forms::DragEventArgs^ e) {
//get filename and complete path
//execute a C++ application .exe to process file with an output
//change the output filename on the same path
//open excel (.csv) application to display the ouput file
}
and I'm planning to improve it further.
Sorry, if this question has been asked before. I'm really new in Visual C++ and want to learn by creating this small project.
The .exe that I want to run was also written by me on a console application (C++) and want to re-use it using GUI.
Thanks and Regards....
|
|
|
|
|
please, just a little help...
|
|
|
|
|
Well,
I have not used the Visual C++ 2005, but in Visual C++ 6 you can get the filename and the complete path with:
extern CMyApp theApp;
CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
char FileName[MAX_PATH];
GetModuleFileName(NULL, FileName, MAX_PATH);
CString m_szName = FileName;
m_szName = m_szName.Left(m_szName.ReverseFind('\\'));
m_szName += "\\MyNewName.ext";
CFile f (m_szName, CFile::modeCreate | CFile::modeReadWrite);
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|