C++, Please explain me this: http://screencast.com/t/IhtdaF8rdgS Do I need to make the function to prompt the user to enter Array value and n value , or do I need to assign default values from the start ? Please help me I don't understand what I need to do ?
The function jsut does thw work. All prompting or test harness parts would be in the main and call the function.
You could do the work with a loop or recursion.
yea but should the function itself promt the user to enter values or have default values in its parameters ? Do you understand where I am confused ?
@e.mccormick
Parameters. That is what I meant by it just does the work. It does no input or output. All it does it add.
I did it recursivly in python for the heck of it.... if you want to see.
Well, not exactly it. Mine finds the length as it goes.
Did it with the length var too. Hehe.
So basically in this part: http://screencast.com/t/4HdCZqzw1 I don't have to write code at all ? I just call the previews functions and that's it ? or ? @e.mccormick
This is the beginning of object orientated programming. You are learning functions. A function is basically a part of a program that can not necessarily stand on its own. So you made functions that are tools to get specific jobs done. Now you use a main function that will call those tools. There will be some code involved. For example, Equal() returns true or false. It does not print anything. So you will need to output a message based on if Equal() says they are equal or not. But you do not have to write special code for each pair you test. That is because you can reuse the functions you have made.
@e.mccormick Oh I see what you mean. Btw could you please show me your pascal version ? That's my code so far : http://pastebin.com/ewN84eyd
Sorry I ment Python * !
Python. LOL It was just for the first one, but: ``` def Sum(ints, temp=0): if len(ints) == 1: return temp + ints[0] else: temp = ints[-1] + Sum(ints[:-1]) return temp print (Sum([1,2,3,4,5])) def sum_array(ints, l): total = 0 if l > 0: total = ints[-1] + sum_array(ints[:-1], l-1) return total print (sum_array([1,2,3,4,5],5)) ``` The first did not need to know how many were in it. It used len to find it. The second has it passed. They are recursive, which means they call themselves with a smaller version. In C++ this would be called a pop because it is popping off the last value from the end of the array.
At least pascal IS a programming language and they both start with a P. So not too far off.
Join our real-time social learning platform and learn together with your friends!