Array in C#: Employee Salary Computation with Overtime & Weekly Sales Computation
Table of Contents
- Array in C#: Employee Salary Computation with Overtime & Weekly Sales Computation
- Introduction of the Lesson
- Objectives
- Understand
- Learn
- Practice
- Apply
- Beginner-Friendly Source Code (With Namespace)
- Instructions
- Source Code
- Example Output
- Lesson Summary
- Multiple Choice Questions
- Exercises, Assessment, and Lab Exam
- Introduction to Exercises
- Exercises
- Assessment
- Lab Exam
Introduction of the Lesson
Arrays are one of the most essential data structures in C# programming, allowing developers to store and manage multiple values efficiently using a single variable. In real-world business applications, arrays are widely used in systems such as payroll, inventory, and sales tracking, where handling collections of data is critical.
In this lesson, you will explore how arrays can be applied to practical business scenarios, specifically Employee Salary Computation with Overtime and Weekly Sales Computation. These examples simulate real organizational needs, such as calculating employee wages and analyzing sales performance. By combining arrays with loops and conditional logic, you will learn how to process multiple data entries efficiently and accurately.
Objectives
This lesson is designed to guide learners through progressive skill development aligned with Outcome-Based Education (OBE). By the end of this lesson, students are expected to achieve the following:
Understand
Develop a clear understanding of arrays, including their structure, indexing, and how they store multiple values in a single variable. Students will also understand how arrays are used in real-world business computations.
Learn
Acquire knowledge on implementing arrays in C# to solve practical problems such as salary computation with overtime and weekly sales analysis. Students will learn how loops and conditional statements interact with arrays.
Practice
Apply learned concepts by writing and modifying programs that utilize arrays for handling multiple inputs. Students will practice computing salaries and summing weekly sales using structured logic.
Apply
Demonstrate the ability to design simple business-related programs that use arrays effectively. Students will apply their knowledge to create scalable solutions for payroll and sales systems.
Beginner-Friendly Source Code (With Namespace)
Instructions
- Open Visual Studio Code.
- Create a new C# console application.
- Copy and paste the code below.
- Run the program and observe the output.
Source Code
using System;
namespace BusinessArrayApplications
{
class Program
{
static void Main(string[] args)
{
// Employee Salary Computation with Overtime
Console.WriteLine("=== Employee Salary Computation ===");
double[] hoursWorked = { 40, 45, 38 }; // hours per employee
double hourlyRate = 200;
for (int i = 0; i < hoursWorked.Length; i++)
{
double salary;
if (hoursWorked[i] > 40)
{
double overtimeHours = hoursWorked[i] - 40;
salary = (40 * hourlyRate) + (overtimeHours * hourlyRate * 1.5);
}
else
{
salary = hoursWorked[i] * hourlyRate;
}
Console.WriteLine($"Employee {i + 1} Salary: {salary}");
}
// Weekly Sales Computation
Console.WriteLine("\n=== Weekly Sales Computation ===");
double[] weeklySales = { 5000, 7000, 6500, 8000, 7500, 9000, 8500 };
double totalSales = 0;
for (int i = 0; i < weeklySales.Length; i++)
{
totalSales += weeklySales[i];
}
double averageSales = totalSales / weeklySales.Length;
Console.WriteLine($"Total Weekly Sales: {totalSales}");
Console.WriteLine($"Average Daily Sales: {averageSales}");
Console.ReadKey();
}
}
}
Example Output
=== Employee Salary Computation ===
Employee 1 Salary: 8000
Employee 2 Salary: 9500
Employee 3 Salary: 7600
=== Weekly Sales Computation ===
Total Weekly Sales: 51500
Average Daily Sales: 7357.14
Lesson Summary
Arrays provide a powerful and efficient way to manage multiple data values in a structured format. In this lesson, you learned how arrays can be applied to real-world business scenarios such as computing employee salaries with overtime and analyzing weekly sales data. By integrating loops and conditional logic, you were able to process multiple entries dynamically, making your programs more scalable and practical. These foundational skills are essential for developing business applications such as payroll systems, financial trackers, and sales monitoring tools.
Multiple Choice Questions
- What is the primary purpose of an array in C#?
A. To store a single value
B. To store multiple values in one variable
C. To execute loops
D. To display output - Why is a loop used with arrays?
A. To increase memory
B. To access elements one by one
C. To stop the program
D. To create variables - If an employee works 50 hours, how is overtime calculated?
A. 50 × rate
B. 40 × rate only
C. (40 × rate) + (10 × rate × 1.5)
D. 10 × rate - What will happen if you remove the loop in weekly sales computation?
A. Program crashes
B. Only one value is processed
C. All values are processed automatically
D. Output doubles - Which is the best use of arrays in business applications?
A. Storing one-time input
B. Managing multiple related data like sales or salaries
C. Printing messages only
D. Declaring constants
Exercises, Assessment, and Lab Exam
Introduction to Exercises
To strengthen your understanding of arrays and their application in business scenarios, the following exercises, assessments, and lab tasks are designed to enhance your logical thinking and coding skills. These activities will help you transition from basic implementation to more advanced problem-solving.
Exercises
- Modify the program to accept user input for employee hours.
- Add more employees dynamically.
- Display the highest salary among employees.
Assessment
- Create a program that computes monthly salary using arrays.
- Add tax deductions to the salary computation.
- Display total and average salary.
Lab Exam
Task:
Develop a C# program that:
- Accepts 5 employees’ working hours
- Computes salary with overtime
- Stores weekly sales for 7 days
- Displays:
- Total sales
- Highest sales
- Employee with highest salary
You may visit our Facebook page for more information, inquiries, and comments. Please subscribe also to our YouTube Channel to receive free capstone projects resources and computer programming tutorials.
Hire our team to do the project.