Preview

10738103 4908277722067 220370966 N 1

Good Essays
Open Document
Open Document
479 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
10738103 4908277722067 220370966 N 1
WKES 2401 : Tutorial 4 (chapter 9)

Problem Set

1. Suppose you want to write a method that prints a heading on a new output page with a page number that is 1 in the first activation and that increases by 1 with each subsequent activation. Can this be done without parameters in Java? Suggest a way to do that.

This can be done by using a static (or class) data member for the page number.

2. Consider the following program written in C syntax:

void swap (int a, int b) { int temp; temp = a; a = b; b = temp;
}

Void main() { int value = 1, list [5] = {2, 4, 6, 8, 10);

swap (value , list [0]);

swap (list[0], list[ 1]);
}

For each of the following parameter-passing methods , what are the values of variables value and list after the two calls to swap?

a) Passed by value
With pass by value, none of the actual arguments are changed, so the variables retain the values they were initialized with.

Both first and second call to swap: value = 1 list[5]={2,4,6,8,10} b) Passed by reference
With pass by reference, the arguments are changed. After the first call to swap, value == 2 and list[0] == 1. After the second call to swap, list[0] == 4 and list[1] == 1.

First call to swap: value = 2 list[5]={1,4,6,8,10} Second call to swap: value = 2 list[5]={4,1,6,8,10} c) Passed by value –result In this case, value-result has the same effect as reference.

3. Given the following program in C:

Void fun (int first, int second) {

first += first; second += second;

} void main () {

Int list[2] = { 3,5}; fun (list[0], list[1]);
}

For each of the following parameter passing methods, what the values of the list array after execution?

a. Passed by value copy going into the procedure
3,5
b. Passed by reference pass a pointer to the actual parameter, and indirect through the pointer
6,10
c. Passed by value-result copy going in, and again going out
6,10

NOTES: techniques used for argument passing: call by value call by result call by value-result call by reference

You May Also Find These Documents Helpful

  • Powerful Essays

    1. The program will present a series of user screens that prompts the user for specified input.…

    • 1488 Words
    • 6 Pages
    Powerful Essays
  • Good Essays

    Nt1420 Unit 6

    • 1145 Words
    • 5 Pages

    INSTRUCTIONS: 1. THERE ARE SIX (6) QUESTIONS IN THIS PAPER. 2. ANSWER FIVE (5) QUESTIONS ONLY. Question 1 Arrays are used when storing a large number of values. You are required to create an array named a and answer the following questions regarding array manipulation. a. Write a method fillRandom(int[] a, int min, int max), fill the array a with a random integer value. (Note: Math.random() returns a double in the range of 0.0 and 1.0, therefore it is cast to an integer number, between the minimum and maximum value). [6 marks] b. Write the Bubble sort method to sort array a into descending order. [10 marks] c. In the quicksort, an algorithm an element is chosen from the unsorted list. This element is called the…

    • 1145 Words
    • 5 Pages
    Good Essays
  • Good Essays

    Exercise 1: Review of array-based lists Create a project using the classes in the DocSharing area labeled “User-defined array list." Compile it, run it, and review the code that is given carefully. This code tests the ArrayList class provided in the lecture.…

    • 714 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    Homework Unit 3

    • 354 Words
    • 2 Pages

    6. In passing argument by value- any changes made to the parameter value won't affect argument outside module. In passing argument by reference- Changes will affect actual argument passed to module.…

    • 354 Words
    • 2 Pages
    Satisfactory Essays
  • Powerful Essays

    Activity 1: write a program in java to interchange (swap) values of two variables with a use of 3rd variable.…

    • 2338 Words
    • 10 Pages
    Powerful Essays
  • Satisfactory Essays

    2. Using a long listing and no process modifiers, what is the swap space amount for the bash command?…

    • 537 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    If using a long listing and no process modifiers, what is the swap space amount for the bash command?…

    • 385 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Unit 4 Homework

    • 401 Words
    • 2 Pages

    Not Sure what is going to happen because I wrote that whole program and nothing happen. The Value is passed into the parameter value on this program module though.…

    • 401 Words
    • 2 Pages
    Satisfactory Essays
  • Better Essays

    3) Look at the following pseudocode module header: Module myModule( Integer a, Integer b, Integer c) Now look at the following call to myModule: Call myModule( 3, 2, 1) When this call executes, what value will be stored in a? What value will be stored in b? What value will be stored in c?…

    • 1580 Words
    • 11 Pages
    Better Essays
  • Good Essays

    Land Work

    • 496 Words
    • 2 Pages

    | In the document header, add a page number using the Plain Number 3 style at the Top of Page. In the footer, add the FileName field using the default format. Ensure…

    • 496 Words
    • 2 Pages
    Good Essays
  • Best Essays

    Apa Title Page Analysis

    • 3030 Words
    • 13 Pages

    Select “different first page” then insert page numbers on page 2 and type the title in all…

    • 3030 Words
    • 13 Pages
    Best Essays
  • Powerful Essays

    Apa Devry

    • 2771 Words
    • 12 Pages

    • title page, which includes a running head for publication (also set “header” so the running head title appears on each page with page number), title, name, class, date, and school…

    • 2771 Words
    • 12 Pages
    Powerful Essays
  • Satisfactory Essays

    3. Put your last name and the page number in the upper-right hand corner of each…

    • 925 Words
    • 4 Pages
    Satisfactory Essays
  • Satisfactory Essays

    File Processing Commands

    • 354 Words
    • 2 Pages

    If using a long listing and no process modifiers, what is the swap space amount for the bash command?…

    • 354 Words
    • 2 Pages
    Satisfactory Essays
  • Better Essays

    Final Synthesis Paper

    • 3146 Words
    • 8 Pages

    Include a page header (also known as the "running head") at the top of every page. To create a page header/running head, insert page numbers flush right. Then type "TITLE OF YOUR PAPER" in the header flush left using all capital letters. The running head is a shortened version of your paper 's title and cannot exceed 50 characters including spacing and punctuation.…

    • 3146 Words
    • 8 Pages
    Better Essays