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; }
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();...
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.
Given: class Monster {     private:     string name;     int dangerLevel;     public:     Monster(sting, int);     virtual void hunt()
Given: class Monster {     private:     string name;     int dangerLevel;     public:     Monster(sting, int);     virtual void hunt() = 0;     virtual void fight(Monster&);     string getName() const; }; class GiantMonster : public Monster {     protected:         int height;          public:         GiantMonster(string, int, int);         virtual void trample(); }; class Dinosaur : public GiantMonster {     public:     Dinosaur(string, int, int);     void hunt();     void roar(); }; class Kraken : protected GiantMonster {     public:     Kraken(string, int, int);     virtual void hunt();     void sinkShip(); }; Indicate if the code snippets below are...
*/ #include using namespace std; void start (int boxes [10]); void move (int squares [10], int...
*/ #include using namespace std; void start (int boxes [10]); void move (int squares [10], int x, int y, int z); void add (int arr [10], int first, int last); void print (int arr [10]); int main () {     int my_arr [10];         cout << "The original array is:\n";     print (my_arr);         start (my_arr);     cout << "\n\nThe array after start is:\n";     print (my_arr);         move (my_arr, 2, 4, 6);     cout << "\n\nThe...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT