Question

Write a console application that has/does the following • A method that uses a ref parameter...

Write a console application that has/does the following

A method that uses a ref parameter for an integer.
o Change the value of the ref parameter inside the method.
A method that has optional parameters.
A method that uses named arguments.
A Main method that has an integer variable with a value assigned to it.
o Call the method that implements the ref parameter.
o Print the value of the variable both before and after calling the method.
o Call the method that has the optional parameters, both with and without the optional parameter populated in the call.
o Call the named method assigning values to the named arguments.
o In all calls to methods print the arguments before and after the method calls.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

using System;

namespace solution // Chane it according to your programm and filename
{
public class Program
{
public static void refmethod(ref int arg) //method with ref parameter
{
arg = arg+10;
}
public static void optionalParamMethod(String fname,String lname="Martin") // method with optional parameter
{
Console.WriteLine("Fullname : " + fname+" "+lname);
}
public static void namedParamMethod(String country,String capital) // method with named parameter
{
Console.WriteLine("Country : "+country+" Capital : "+capital);
  
}
  
public static void Main(string[] args)
{
int a = 5;
  
Console.WriteLine("Value of a before calling the refmethod : "+a);
refmethod(ref a);
Console.WriteLine("Value of a after calling the refmethod : "+a);
Console.WriteLine();
Console.WriteLine();
  
Console.WriteLine("Calling method with optional parameter with the optional argument");
String fname = "Joe";
String lname = "Columbus";
optionalParamMethod(fname,lname);
  
Console.WriteLine("Calling method with optional parameter without the optional argument");
optionalParamMethod(fname);
Console.WriteLine();
Console.WriteLine();
  
Console.WriteLine("Calling method with named parameter argument in same order ");
namedParamMethod(country:"France",capital:"Paris");
  
  
Console.WriteLine("Calling method with named parameter argument in different order ");
namedParamMethod(capital:"Paris",country:"France");

  

}
}
}

Add a comment
Know the answer?
Add Answer to:
Write a console application that has/does the following • A method that uses a ref parameter...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Task 4: a) Write a function named change() that has an integer parameter and six integer...

    Task 4: a) Write a function named change() that has an integer parameter and six integer reference parameters named hundreds, fifties, twenties, tens, fives, and ones. The function is to consider the passed integer value as a dollar amount and convert the value into the fewest number of equivalent bills. Using the reference parameters, the function should alter the arguments in the calling function. b) Include the function written in part a in a working program. Make sure your function...

  • In Java Write a method factorial that accepts an integer parameter n and that uses recursion...

    In Java Write a method factorial that accepts an integer parameter n and that uses recursion to compute and return the value of n factorial (also known as n!). Your method should throw an IllegalArgumentException if n is negative. Several calls and their return values are shown below. Call Output factorial(0); 1 factorial(1); 1 factorial(3); 6 factorial(5); 120 factorial(10); 3628800 factorial(-4); IllegalArgumentException

  • 3. Write a C++ program that repeatedly inputs 50 positive integers that represent consumption of gas...

    3. Write a C++ program that repeatedly inputs 50 positive integers that represent consumption of gas measured in gallons, one at a time. Use a loop to do the following steps: 1. Input the gas by calling a function named 'inputGas()' 'inputGas()' will not receive any parameters. It will input the gas and return it to the main function. 2. Convert the value of gallons to its liter equivalent by calling a function named 'convertToLiter'. 'convertToLiter' will receive an integer...

  • Write a Java console application that prompts the user to enter the radius of a circle,...

    Write a Java console application that prompts the user to enter the radius of a circle, then prints its radius, diameter, circumference, and area. Write a JavaFX GUI application to do the same calculation, and draw the circle. The Console Output Enter the radius of the circle: 1.2 The radius is 1.2 The diameter is 2.4 The circumference is 7.5398223686155035 The area is 4.523893421169302 Write and document your program per class coding conventions. Add an instance variable double radius. Generate...

  • Please Write the following program in c# You are to write an application which will create...

    Please Write the following program in c# You are to write an application which will create a company, add agents (their name, ID, and weekly sales) to that company, and printout the details of all agents in the company. The application will contain three classes: Agent.cs, Company.cs, and CompanyTest.cs (this class is already provided). Flow of the application: The CompanyTest class creates an object of the Company class and reserves space for five agents. At this point if you call...

  • using c/c++ Q1 (15 Marks) Console Application for Student Data 1- Write a function named Average...

    using c/c++ Q1 (15 Marks) Console Application for Student Data 1- Write a function named Average that Receives two integer numbers as parameter and returns the average Is used in a main function. Main() stays in a loop and asks user to enter 2 numbers and then shows the average using the Average function above Define a class named Student with following members: private data: 2 grades and a GPA (average). public constructor to initialize the members a public function...

  • JAVA HELP! Question: Write a Java console application that investigates how well Java handles large integers....

    JAVA HELP! Question: Write a Java console application that investigates how well Java handles large integers. Write two loops that iterate from 0 through 35. Before each loop, set an integer variable (IV) to 1. Within each loop, print the loop count and the value of IV formatted in two columns. Within the first loop, multiply IV by 2. Within the second loop, multiply IV by the appropriate StrictMath method. The second loop will not complete since there will eventually...

  • Write a complete Java program, including comments in both the main program and in each method,...

    Write a complete Java program, including comments in both the main program and in each method, which will do the following: 0. The main program starts by calling a method named introduction which prints out a description of what the program will do. This method is called just once.      This method is not sent any parameters, and it does not return a value. The method should print your name. Then it prints several lines of output explaining what the...

  • I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that a...

    I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...

  • You are to write a banking application in c# that keeps track of bank accounts. It will consist of three classes, Account, Bank and BankTest. The Account class is used to represent a savings account i...

    You are to write a banking application in c# that keeps track of bank accounts. It will consist of three classes, Account, Bank and BankTest. The Account class is used to represent a savings account in a bank. The class must have the following instance variables: a String called accountID                       a String called accountName a two-dimensional integer array called deposits (each row represents deposits made in a week). At this point it should not be given any initial value. Each...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT