Вопрос задан 22.11.2023 в 02:13. Предмет Информатика. Спрашивает Дудыко Ульяна.

Написати програму з використанням додатку Windows Forms для обчислення заробітної плати. Ставка

300$ + відсотки. Продаж до 500$ - 3%, від 500 до 1000$ - 5%, понад 1000 – 8%. Вимоги:  Мінімум для трьох співробітників  перевірка на помилки введення;  створити кнопку для генерації випадкових продажів  знайти найкращий результат та зафарбувати його кольором + премія 200$  передбачити однакові результати  створити кнопку для очищення значень
0 0
Перейти к ответам

Ответы на вопрос

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Калмыков Александр.

Ответ:

```csharp

using System;

using System.Windows.Forms;

namespace SalaryCalculator

{

public partial class Form1 : Form

{

private Random random = new Random();

public Form1()

{

InitializeComponent();

}

private void btnCalculate_Click(object sender, EventArgs e)

{

double rate = 300;

double highestSale = 0;

int count = 0;

double totalSalary = 0;

foreach (TextBox textBox in Controls)

{

if (double.TryParse(textBox.Text, out double saleAmount))

{

double commissionRate;

if (saleAmount <= 500)

{

commissionRate = 0.03;

}

else if (saleAmount <= 1000)

{

commissionRate = 0.05;

}

else

{

commissionRate = 0.08;

}

double commission = saleAmount * commissionRate;

double salary = rate + commission;

totalSalary += salary;

if (saleAmount > highestSale)

{

highestSale = saleAmount;

}

count++;

}

else

{

MessageBox.Show("Введено некоректне значення. Будь ласка, введіть числове значення для продажу.", "Помилка", MessageBoxButtons.OK, MessageBoxIcon.Error);

return;

}

}

double averageSalary = totalSalary / count;

// Очищення попередньо зафарбованих текстових полів

foreach (TextBox textBox in Controls)

{

textBox.BackColor = default;

}

// Зафарбування найкращого результату

foreach (TextBox textBox in Controls)

{

if (double.TryParse(textBox.Text, out double saleAmount))

{

if (saleAmount == highestSale)

{

textBox.BackColor = System.Drawing.Color.Green;

double salary = rate + saleAmount * GetCommissionRate(saleAmount);

salary += 200;

textBox.Text = salary.ToString();

}

}

}

txtTotalSalary.Text = totalSalary.ToString();

txtAverageSalary.Text = averageSalary.ToString();

}

private void btnClear_Click(object sender, EventArgs e)

{

foreach (TextBox textBox in Controls)

{

textBox.Text = string.Empty;

}

txtTotalSalary.Text = string.Empty;

txtAverageSalary.Text = string.Empty;

// Очищення зафарбованих текстових полів

foreach (TextBox textBox in Controls)

{

textBox.BackColor = default;

}

}

private void btnGenerate_Click(object sender, EventArgs e)

{

foreach (TextBox textBox in Controls)

{

textBox.Text = random.Next(100, 2000).ToString();

}

}

private double GetCommissionRate(double saleAmount)

{

if (saleAmount <= 500)

{

return 0.03;

}

else if (saleAmount <= 1000)

{

return 0.05;

}

else

{

return 0.08;

}

}

}

}

```

0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

To write a program using Windows Forms for calculating wages with the given criteria, you can follow these steps:

Step 1: Create a Windows Forms Application

Start by creating a new Windows Forms Application project in your preferred programming language, such as C# or Visual Basic.

Step 2: Design the User Interface

Design the user interface with the necessary controls. Based on the requirements, you will need the following controls: - Three input fields for entering the sales amount for each employee. - A button to calculate the wages. - A button to generate random sales amounts. - A button to clear the values. - A label to display the calculated wages. - A label to display the best result.

Step 3: Implement the Calculation Logic

In the event handler for the "Calculate" button, write the logic to calculate the wages based on the given criteria. Here's an example of how you can implement it in C#:

```csharp private void CalculateButton_Click(object sender, EventArgs e) { // Get the sales amounts for each employee decimal sales1 = decimal.Parse(employee1SalesTextBox.Text); decimal sales2 = decimal.Parse(employee2SalesTextBox.Text); decimal sales3 = decimal.Parse(employee3SalesTextBox.Text);

// Calculate the wages for each employee decimal wages1 = CalculateWages(sales1); decimal wages2 = CalculateWages(sales2); decimal wages3 = CalculateWages(sales3);

// Display the calculated wages employee1WagesLabel.Text = wages1.ToString("C"); employee2WagesLabel.Text = wages2.ToString("C"); employee3WagesLabel.Text = wages3.ToString("C");

// Find the best result and highlight it decimal bestResult = Math.Max(wages1, Math.Max(wages2, wages3)); if (bestResult == wages1) { employee1WagesLabel.BackColor = Color.Yellow; } else if (bestResult == wages2) { employee2WagesLabel.BackColor = Color.Yellow; } else if (bestResult == wages3) { employee3WagesLabel.BackColor = Color.Yellow; } }

private decimal CalculateWages(decimal sales) { decimal rate = 300; decimal commission = 0;

if (sales < 500) { commission = sales * 0.03m; } else if (sales >= 500 && sales < 1000) { commission = sales * 0.05m; } else if (sales >= 1000) { commission = sales * 0.08m; }

return rate + commission + 200; } ```

Step 4: Implement the Random Sales Generation

In the event handler for the "Generate Random Sales" button, you can generate random sales amounts for each employee and populate the corresponding input fields.

Step 5: Implement the Clear Values Functionality

In the event handler for the "Clear Values" button, you can reset all the input fields, labels, and colors to their initial state.

Step 6: Error Handling

To handle input errors, you can use try-catch blocks to catch any exceptions that may occur when parsing the sales amounts. Display an error message to the user if an exception is caught.

Remember to customize the code according to your programming language and control names. This is just a general outline to help you get started.

0 0

Похожие вопросы

Топ вопросов за вчера в категории Информатика

Последние заданные вопросы в категории Информатика

Задать вопрос