using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace part_I { class Program { static void Main(string[] args) { Console.WriteLine(""); CalculateTuition(); Console.WriteLine(""); CalculateAreaOfCircle(); Console.WriteLine(""); DisplaySineTable(); Console.WriteLine(""); ShowMenu(); } #region /*2. Write a method called CalculateTuition(), * that prompts the user for the number of courses and then calculate and display the tuition cost. * (cost = number of course * 569.99). * Call the CalculateTuition() method from the same Main() method as in question 1.*/ static void CalculateTuition() { Console.Write("Enter the number of courses: "); int course = Convert.ToInt32(Console.ReadLine()); double cost = course * 569.99; Console.WriteLine("{0:c2}", cost); } #endregion #region /*3. Write a method call CalculateAreaOfCircle(), * that prompts the user for the radius of a circle and then calculate and display the area. * [A = πr2] * Call the CalculateAreaOfCircle() method from the same Main() method as in question 1.*/ static void CalculateAreaOfCircle() { Console.Write("Enter the radius of a circle: "); int r = Convert.ToInt32(Console.ReadLine()); double area = Math.PI * r * 2; Console.WriteLine("Area of the circle: {0:f2}", area); } #endregion #region /*6. Write a method call DisplaySineTable(), * that prompts the user for a starting value and an step size. * The method will calculate and display a table (10 rows) of sine values based on the user input. * Use the built-in method Math.Sin() to obtain the sine of an angle. * e.g. if the starting value is 0.5 and the step size is 0.03 * the method will display the following table: 0.50 0.4794 0.53 0.5055 0.56 0.5311 <--- wrong ?? 0.77 0.6961*/ static void DisplaySineTable() { Console.Write("Enter the starting value: "); double startingValue = Convert.ToDouble(Console.ReadLine()); Console.Write("Enter the step size: "); double stepSize = Convert.ToDouble(Console.ReadLine()); for (int i = 0; i < 10; i++) { double sinValue = Math.Sin(startingValue); Console.WriteLine("{0,10:f2}{1,10:f4}", startingValue, sinValue); startingValue += stepSize; } } #endregion #region /*7. In a new program, write a method called DisplayMenu() to display the following text on screen: =============Narendra’s Computer Systems================== | 1. To calculate area of a Circle | | 2. To calculate the area of a Triangle | | 3. To calculate the volume of a Cube | | 0. To end program | | | ========================================================== Enter the number of your choice -> */ static void DisplayMenu() { Console.WriteLine("\n=============Narendra’s Computer Systems=================="); Console.WriteLine("| 1. To calculate area of a Circle |"); Console.WriteLine("| 2. To calculate the area of a Triangle |"); Console.WriteLine("| 3. To calculate the volume of a Cube |"); Console.WriteLine("| 0. To end program |"); Console.WriteLine("| |"); Console.WriteLine("=========================================================="); Console.Write(" Enter the number of your choice -> "); //Console.Write("=============Narendra’s Computer Systems==================\n| 1. To calculate area of a Circle |\n| 2. To calculate the area of a Triangle |\n| 3. To calculate the volume of a Cube |\n| 0. To end program |\n| |\n==========================================================\nEnter the number of your choice ->\n"); } #endregion #region Q8. /*8. Add another method called ShowMenu() to your project. * This method will call the method in question 7 continuously until the user presses 0. * (You will have to invoke the method in a loop body, read in the user input as well as check the input)*/ static void ShowMenu() { DisplayMenu(); for (; ; ) { double call = Convert.ToDouble(Console.ReadLine()); if ((call == 1) || (call == 2) || (call == 3)) { Console.Write("You choose {0}", call); } else if (call == 0) { Console.WriteLine("\n * * * * * To end program.. * * * * *\n * * * * * To end program.. * * * * *\n\n"); break; } else { Console.Write("You choose {0}", call); Console.Write("\n * * * * * WRONG NUMBER * * * * *\n * * * * * WRONG NUMBER * * * * *\n\n"); } DisplayMenu(); } } #endregion } }
Loading...

















