Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Exercises 5 Test 3 Programming I Page 1 of 4 Test 3 Description: Solve the following exercises in the same project. They will require the use of methods and loops. Once you are done answering all 5...

1 answer below »

Exercises 5
Test 3 Programming I
Page 1 of 4
Test 3
Description: Solve the following exercises in the same project. They will require the use
of methods and loops.
Once you are done answering all 5 questions, zip the project, name the file with your
student id number and upload it to eCentennial under Assessments / Assignment / Test 3
General Instructions:
Write a new Console Application Program and name it with your student id number only, if you
don’t follow this, 5 points will be deducted.

1. [15 marks] Write a new method that will work as the menu of your application. Details:

• Name: YourNameMenu – replace “YourName” with your first name. For example:

• Parameter: None
• Returns: A string representing the choice the user have done for the menu option
• Displays: The menu below - It should MATCH EXACTLY the output you see below
• Task: Prints out the menu below, collects the user input and returns the input as the
method’s return value.


2. [25 marks] In your Main method, using a “while” loop, not a “do while”, write the code to
call the Menu method you have created on question #1 repeatedly.
Using a “switch” structure, write the code to implement the following required functionality for
all valid responses. Valid responses includes both upper and lower case of the input. The
following must be implemented:

- A will call the DemoQuestion3() method
- B will call the DemoQuestion4() method
- C will call the DemoQuestion5() method
- X will terminate the program

Any other key will produce an e
or message that says “Invalid choice”.
Test 3 Programming I
Page 2 of 4
3. [20 marks]
Newton's law of universal gravitation states:
“Every object in the universe attracts every other object with a force along a line joining them.
The force is directly proportional to the product of their masses and inversely proportional to the
square of the distance between their centers of mass.”
3.1. [10 marks] Write a method with the following details:
• Name: CalculateGravitationalAttraction
• Parameters:
o A double representing the mass of the first body - name it "mass1"
o A double representing the mass of the second body - name it "mass2"
o A double representing the distance between them - name it "distance"
• Returns: A double representing the attractive force between the bodies
• Displays: Nothing
• Task: Calculate and return the force of attraction between them. Formula:
o Force = G * (mass1 * mass2) / distance ^ 2
▪ where G = 6.673e-11 (“G” should be a constant)
▪ for the power of 2 use Math.Pow() method
3.2. [10 marks] Using the method below, write the statements to call the above method with
the masses of the earth, moon and the distance between them and display the resulting force.

- Mass of Earth: 5.972E24
- Mass of Moon: 7.348E22
- Distance: 384,400,000 meters
- Answer: 1.99e020N - You should use “E” as a format specifier in your output (like when you
use N, F, N2)

static void DemoQuestion3()
{
Console.WriteLine("\n\n**********Begin Question 3 **********");


code for calling "CalculateGravitationalAttraction" goes here

Console.WriteLine("\n**********End Question 3 **********\n\n");
}
Note: --- question 4 in on the next page
Test 3 Programming I
Page 3 of 4
4. [15 marks]
4.1. [10 marks] Write a method with the following details:
• Name: HeightConversion
• Parameter: An integer representing the height value in cm
• Returns: Nothing
• Displays: Both the centimetres and meters equivalent
• Task: Converts the argument to metres from cm and display it on the console.
4.2. [5 marks] Using the method below, write the code to call the above method three times
with arguments 75, 100 and 290.

static void DemoQuestion4()
{
Console.WriteLine("\n\n**********Begin Question 4 **********");


code for calling "HeightConversion" three times goes

Console.WriteLine("\n\n**********End Question 4 **********\n\n");
}
Note: --- question 5 is on the next page
Test 3 Programming I
Page 4 of 4
5. [25 marks]
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, XXXXXXXXXXand printout the values for the
angle, resulting sine and cosine in a tabular format. Use a “for” looping structure.

static void DemoQuestion5()
{
Console.WriteLine("\n\n**********Begin Question 5 **********");


code for looping from 0.500 to 0.509, invoking SineCosine method and
printing the result

Console.WriteLine("\n**********End Question 5 **********\n\n");
}

The output must MATCH EXACTLY the output you see below:
Answered Same Day Dec 14, 2021

Solution

Bikram answered on Dec 15 2021
110 Votes
Technical details:
· Visual Studio 2019
· C#
· Console Application
1. Main Menu
2. Option a selected
3. Option b selected
4. Option c selected
5. Invalid option selected
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here