Question

In: Computer Science

1_ What is the output? private void btnMethods_Click(object sender, EventArgs e) { int arg1 = 2;...

1_ What is the output?

private void btnMethods_Click(object sender, EventArgs e)

{

int arg1 = 2;

double val = ValReturnMethod(arg1, 2.00);

MessageBox.Show(val.ToString());

}

private void ValReturnMethod(int val, double val2)

{

return val1 * val2 *25.50;

}

_____________________________

2_ What is the output?

private void btnMethods_Click(object sender, EventArgs e)

{

int arg1 = 4;

double val = ValReturnMethod(ref arg1);

MessageBox.Show(arg1.ToString());

}

private double ValReturnMethod(ref int val1)

{

return val1 *25.50;

}

______________________________

3_ What is the output?

private void btnMethods_Click(object sender, EventArgs e)

{

int arg1 = 4;

double arg2 = 10.50;

MessageBox.Show(ValReturnMethod(arg1,arg2).ToString());

}

private double ValReturnMthod (int val1,double val2)

{

return val1 * 25.50;

}

Solutions

Expert Solution

1_ What is the output?
private void btnMethods_Click(object sender, EventArgs e)
{
int arg1 = 2;
double val = ValReturnMethod(arg1, 2.00);
MessageBox.Show(val.ToString());
}
private void ValReturnMethod(int val, double val2)
{
return val1 * val2 *25.50;   //This is trying to return a value from a void method, which leads to error.
                           //Also there is a typo. The variable val1 is used here, where it is declared as val.
}
_____________________________
2_ What is the output?
private void btnMethods_Click(object sender, EventArgs e)
{
int arg1 = 4;
double val = ValReturnMethod(ref arg1);   //val1 is assigned with 102.
MessageBox.Show(arg1.ToString());   //And 102 will be printed to MessageBox.
}
private double ValReturnMethod(ref int val1)
{
return val1 *25.50;   //val1 = 4 is taken as input. And returns 4 * 25.50 = 102.
}
______________________________
3_ What is the output?
private void btnMethods_Click(object sender, EventArgs e)
{
int arg1 = 4;
double arg2 = 10.50;
MessageBox.Show(ValReturnMethod(arg1,arg2).ToString());       //Calling a method that doesn't exist.
                                                           //Note there is a typo in the other method. ValReturnMthod.
                                                           //If not that, this will also return 102.
}
private double ValReturnMthod (int val1,double val2)  
{
return val1 * 25.50;   //Returns 4 * 25.50
}


Related Solutions

private void btnCalculate_Click(object sender, System.EventArgs e) { decimal weightInPounds = 0m; try { weightInPounds = Convert.ToDecimal(txtPounds.Text);...
private void btnCalculate_Click(object sender, System.EventArgs e) { decimal weightInPounds = 0m; try { weightInPounds = Convert.ToDecimal(txtPounds.Text); if (weightInPounds > 0) { decimal weightInKilos = weightInPounds / 2.2m; lblKilos.Text = weightInKilos.ToString("f2"); } else MessageBox.Show("Weight must be greater than 0.", "Entry error"); txtPounds.Focus(); } catch(FormatException) { MessageBox.Show("Weight must be numeric.", "Entry error"); txtPounds.Focus(); } } (Refer to code example 7-1.) If the user enters 118 in the text box and clicks the Calculate button, what does the code do?
   private static void merge(int arr[], int l, int m, int r) {        //...
   private static void merge(int arr[], int l, int m, int r) {        // Find sizes of two subarrays to be merged        int n1 = m - l + 1;        int n2 = r - m;        /* Create temp arrays */        int L[] = new int[n1];        int R[] = new int[n2];        /* Copy data to temp arrays */        for (int i = 0; i...
What is the output of the following C program? #include<stdio.h> int fac (int x); void main(...
What is the output of the following C program? #include<stdio.h> int fac (int x); void main( ) {                         for (int i=1; i<=2; i++)                                     printf("%d", fac(i)); } int fac(int x) {                         x = (x>1) ? x + fac(x-1) : 100);                         return x; }
#include<iostream> using namespace std; class point{ private: int x; int y; public: void print()const; void setf(int,...
#include<iostream> using namespace std; class point{ private: int x; int y; public: void print()const; void setf(int, int); }; class line{ private: point ps; point pe; public: void print()const; void setf(int, int, int, int); }; class rectangle{ private: line length[2]; line breadth[2]; public: void print()const; void setf(int, int, int, int, int, int, int, int); }; int main(){ rectangle r1; r1.setf(3,4,5,6, 7, 8, 9, 10); r1.print(); system("pause"); return 0; } a. Write function implementation of rectangle, line and point. b. What is...
what is the output? int main ( ) { int a = 3, b= 2, c=...
what is the output? int main ( ) { int a = 3, b= 2, c= 1, d, e, f, g; d = a&b;    e = a | c; f = a >> 1, g = a << 1; cout << “d= “ << d << “ e = “ << e << “ f = “ << f << “g = “ << g << endl; }
class Counter{   private int count = 0;   public void inc(){    count++;     }   public int get(){     return...
class Counter{   private int count = 0;   public void inc(){    count++;     }   public int get(){     return count;   } } class Worker extends Thread{ Counter count;   Worker(Counter count){     this.count = count;   }   public void run(){     for (int i = 0; i < 1000;i++){       synchronized(this){         count.inc();       }}   } } public class Test {     public static void main(String args[]) throws InterruptedException   {     Counter c = new Counter();     Worker w1 = new Worker(c);     Worker w2 = new Worker(c);     w1.start();     w2.start();     w1.join();     w2.join();     System.out.println(c.get());      ...
For each call to the following method, indicate what console output is produced: public void mystery2(int...
For each call to the following method, indicate what console output is produced: public void mystery2(int n) { if (n <= 1) { System.out.print(n); } else { mystery2(n / 2); System.out.print(", " + n); } } mystery2(1); mystery2(4); mystery2(16); mystery2(30); mystery2(100);
What is the output of the following program? #include <iostream> using namespace std; void showDouble(int); //Function...
What is the output of the following program? #include <iostream> using namespace std; void showDouble(int); //Function prototype int main() { int num; for (num = 0; num < 10; num++) showDouble(num); return 0; } // Definition of function showDouble void showDouble(int value) { cout << value << ‘\t’ << (value * 2) << endl; } Please do the following Program and hand in the code and sample runs. Write a program using the following function prototypes: double getLength(); double getWidth();...
#include<iostream> using namespace std; void calcSumAndDiff(int ,int, int &, int &); void calcSumAndDiff(int n1,int n2, int...
#include<iostream> using namespace std; void calcSumAndDiff(int ,int, int &, int &); void calcSumAndDiff(int n1,int n2, int &sum, int &diff){ sum = n1 + n2; diff = n1 - n2; } int main() { int n1,n2,sum,diff; n1=30;n2=10; calcSumAndDiff(n1,n2,sum,diff); cout<<"Sum is :"<<sum<<endl; cout<<"Diff is:"<<diff<<endl; system("pause"); }
In Java: int[] A = new int[2]; A[0] = 0; A[1] = 2; f(A[0],A[A[0]]); void f(int...
In Java: int[] A = new int[2]; A[0] = 0; A[1] = 2; f(A[0],A[A[0]]); void f(int x, int y) { x = 1; y = 3; } For each of the following parameter-passing methods, saw what the final values in the array A would be, after the call to f. (There may be more than one correct answer.) a. By value. b. By reference. c. By value-result.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT