Describe how you create and use a method with multiple param

docx

School

Post University *

*We aren’t endorsed by this school

Course

CIS 216_30

Subject

Computer Science

Date

Jan 9, 2024

Type

docx

Pages

7

Uploaded by ColonelTank11764

Report
Advanced Modularization Debbie Nagorski Computer Science Post University CIS 216 Programming Principles Nateysha Poindexter December 3rd, 2023
Advanced Modularization 1. Describe how you create and use a method with multiple parameters. Information can be passed to methods as parameters. Parameters act as inputs to the method. They are also called arguments. Parameters are specified after the method name, inside the parentheses. You can add as many parameters as you want, just separate them with a comma. In some languages you need to specify the type of parameters. For eg: Java method import java.util.* public class Main { public static int addNumbers(int num1, int num2) { return num1 + num2; } public static void main(String[] args){ Scanner sc = new Scanner(System.in); System.out.println("Enter number 1: "); int num1 = sc.nextInt(); System.out.println("Enter number 2: ");
int num2 = sc.nextInt(); int sum = addNumbers(num1, num2); //function call System.out.println("Addition of the two numbers is " + sum); } In other languages such as python, you dont necessarily need to specify parameter type E.g Python method def addNumbers(num1, num2): return num1 + num2 def main(): num1 = int(input("Enter num1: ")) num2 = int(input("Enter num2: ")) sum = addNumbers(num1, num2) print("Addition of two numbers is ", sum) if __name__ == "__main__": main()
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
2. Explain what happens when you call a method, and the method ends. When you call a method, the program looks for the method definition and all the code declared inside the method is executed sequentially. Once the method is done executing, it returns any output, if there is any. A variable declared within a method ceases to exist when the method ends. It goes out of scope. Meaning you cannot call the variables declared inside a method from outside the method. A method can also return "nothing" also known as a void method. E.g code: import java.util.*; public class Main { public static int findArea(int radius){ double pi = 3.142; double area = pi * radius * radius; return area; } public static void main(String[] args){ int radius = 5; double area = findArea(radius); System.out.println("Area of circle: " + area); //prints the area of circle correctly System.out.println("Value of pi: " + pi ); //throws error because pi is not defined in main function, it was defined in findArea but is now out of scope } } 3. Discuss the cumulative summing relationship. A cumulative sum is a sequence of partial sums of a given sequence For eg: You have a list of 10 numbers, then the cumulative sum would be the addition of all numbers inside that list. 4. List the four things you need to know when you call a method from a program or other method
1. Check the name of the function 2. Check any return types of that function 3. Check the parameters of that function 4. Look at the code inside the method to understand what it does To call the function Add parentheses () after the function’s name. Inside the parenthesis, add any parameters that the function requires, separated by commas. End the line with a semicolon ;. 5. Modularized furniture comes with sections that can be assembled in a variety of configurations. What other everyday items are modularized? Modular kitchen Convertible refrigerator Crafting if multiple steps Putting together toys Home Construction putting together a fake Christmas tree toys that need to be put together Legos
6. As a professional programmer, you might never write an entire program. Instead, you might be asked to write specific modules that are destined to become part of a larger system. Is this appealing to you? Yes, it is appealing to me because programming is interesting, no matter what kind of programming it is. It would be fun to collaborate with coworkers or whoever else is putting the program together to each develop the program by only doing sections. Some people may not be as strong as others when developing certain aspects of the program where others are.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
References Farrell, J. (2017). Programming Logic and Design, Comprehensive (9th ed.). Cengage Learning US. https://ambassadored.vitalsource.com/books/9781337517041 (n.d.). Calling Functions . Happy Coding. Retrieved December 3, 2023, from https://happycoding.io/tutorials/processing/calling-functions