Write a method called DisplayPersonalInfo(). This method will display your name, school, program and your favorite course. Call the DisplayPersonalInfo() method from your program Main() method Write a method called CalculateTuition(). This method will prompt the user for the number of courses that she is currently taking and then calculate and display the tuition cost. (cost = number of course * 569.99). Call the CalculateTuition() method two times from the same Main() method as in question 1.
Method/Function/Procedure/Sub/Routine . Please use only C# programming .
Method – this is the fourth control structure we have worked with in this course. Each control structure brings some advantage to the programmer.
-
Sequence sets the framework to ensure that all the statements are processes exactly once and in order. i.e. no skips or repeats
-
Branching allows the program to perform more than one task
-
Repetition provides a structure to process a block of code possible multiple times
-
Method allows the programmer to assign a name to a block or code
The coder has the luxury to reuse blocks of code, hence the job can be done with less code. In addition, it facilitates the decomposition of a complex problem into simpler sub-tasks that can be implemented and tested separately. This is possible by attaching a name to a block of code statements and then invoking the code when required.
Template of a Method
[modifier] [static] «return_type» «method_name»([parameter_type-name_list])
{
statement 1;
statement 2;
}
Definition of a Method
/*
*This method does not require any parameter
*This method does not return a value
*/
static void DisplayPersonInfo()
{
Console.WriteLine("Narendra");
Console.WriteLine("Centennial College");
}
All method consists of a header and a body. The header includes an accessibility modifier, the static keyword, the return type, the name of the method and a parameter list enclosed within a pair of parentheses as shown in the diagram below. All the parts enclosed within square brackets are optional. However, for this part of COMP100, the static modifier is MANDATORY.
Invocation of a Method
DisplayPersonInfo();
// This method takes a string argument
Console.WriteLine("Programming is the best");
// This method returns a string value
string name = Console.ReadLine();
// The ToInt32 method takes a string argument and returns an int value
int age = Convert.ToInt32(Console.ReadLine());
Methods lays the foundations for building designing and using classes. Classes is integral to Object-Oriented Programming (OOP) and is a simpler approach to implementing large or complex systems. Although newer programming paradigms are better suited to concurrent programming or working with big data or incorporating
Sample solution is available on the public drive.
I provide a menu for all of the parts. This is not required. It is more convenient to demonstrate the solution for each individual questions
Completing these exercises will be an excellent preparation for your last test. For this, you will create a single solution and add a new project for each part i.e. your final revision will consist of a single solution with a separate project for each part. The exercises are grouped into parts based on the arguments (or lack of) and the return value. The problems are graded by difficulty level so the later problems are more challenging than the earlier ones.
Part I ‒ Methods with an empty parameter list and do not return a value: [Questions 1-8 required]
You invoke a method by its name followed by a pair of brackets and the usual semi-colon
-
Write a method called DisplayPersonalInfo(). This method will display your name, school, program and your favorite course. Call the DisplayPersonalInfo() method from your program Main() method
-
Write a method called CalculateTuition(). This method will prompt the user for the number of courses that she is currently taking and then calculate and display the tuition cost. (cost = number of course * 569.99). Call the CalculateTuition() method two times from the same Main() method as in question 1.
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 2 images