Answer to Question #331062 in C# for Mandeep

Question #331062

5.1. [15 marks] Write a method with the following details: 

  • Name: SineCosine 
  • • Parameters: o A double that represents an angle in radians 
  • o A double that represents the sine to the first argument (out parameter) 
  • o A double that represents the cosine of the first argument (out parameter) 
  • Returns: Nothing 
  • Displays: Nothing 
  • Task: Calculates the sine and cosine of the first argument and assigns the result values to the second and third arguments. o The second and third arguments are decorated with "out" so that the method is able to change the actual value of the variable. 
  • o You can use Math.Sin() and Math.Cos() to calculate the Sine and Cosine 

5.2. [10 marks] Using the method below, write the code statements to call this method ten times with angle values of 0.500, 0.501, 0.502, 0.503, ... 0.509 and printout the values for the angle, resulting sine and cosine in a tabular format. Use a “for” looping structure. 


1
Expert's answer
2022-04-19T16:32:46-0400
using System;

namespace SineCosine
{
    class Program
    {
        public static void SineCosine(double angle, out double sin, out double cos)
        {
            sin = Math.Sin(angle);
            cos = Math.Cos(angle);
        }
        
        public static void Main(string[] args)
        {
            double angle, sine, cosine;
            Console.WriteLine("{0}\t\t{1}\t\t\t{2}","Angle", "Sine", "Cosine");
            for(int i=0; i<10; i++)
            {
                angle = 0.500 + Convert.ToDouble(i)/1000;
                SineCosine(angle, out sine, out cosine);
                Console.WriteLine("{0:0.000}\t{1}\t{2}", angle, sine, cosine);
            }
            
            Console.Write("\nPress any key to continue . . . ");
            Console.ReadKey(true);
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS