Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In c# programming language: Write three classes called Secretary , Director , an

ID: 3767073 • Letter: I

Question

In c# programming language:

Write three classes called Secretary, Director , and Programmer. Each of the classes contains a CalculateSalary method. For simplicity, let each of these methods write “now calculating the salary for...” followed by the name of the class in which the method resides.

Suppose there are many objects of these classes in your program, and that they need to be stored in a collection such as an

array. How can you store them all in one array and also call the CalculateSalary of each object simply by iterating

through the array and making the same method call for all objects? Write the code that implements this scenario.

Explanation / Answer

====================================================

Program name Salary.cs

====================================================

using System;
namespace Program
{
class Secretary
{
public void CalculateSalary() {

double salary;
Console.WriteLine("Enter the salary: ");
salary = double.Parse(Console.ReadLine());
Console.WriteLine(" Secretary Salary : "+salary);
  
}
}

class Director
{
public void CalculateSalary() {

double salary;
Console.WriteLine("Enter the salary: ");
salary = double.Parse(Console.ReadLine());
Console.WriteLine(" Director Salary : "+salary);
  
}
}

class Programmer
{
public void CalculateSalary() {

double salary;
Console.WriteLine("Enter the salary: ");
salary = double.Parse(Console.ReadLine());
Console.WriteLine(" Programmer Salary : "+salary);
  
}
}
class Test
{
static void Main(string[] args)
{

object[] array = new object[3];
array[0] = new Secretary();
array[1] = new Director();
array[2] = new Programmer();
array[0].CalculateSalary();
array[1].CalculateSalary();
array[2].CalculateSalary();

}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote