Answer:
The csharp program is given below.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button6_Click(object sender, EventArgs e)
{
int total = (Convert.ToInt32(textBox1.Text) + Convert.ToInt32(textBox2.Text) + Convert.ToInt32(textBox3.Text) + Convert.ToInt32(textBox4.Text) + Convert.ToInt32(textBox5.Text));
int dozen = total / 12;
int eggs = total % 12;
textBox6.Text = dozen.ToString();
textBox7.Text = eggs.ToString();
}
private void button7_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
textBox6.Text = "";
textBox7.Text = "";
}
private void button8_Click(object sender, EventArgs e)
{
Close();
}
}
}
Explanation:
1. The integer variables are declared for total eggs, number of dozens and number of eggs.
2. The input of each text box is converted into integer by using the Convert.ToInt32() method on the value of that particular text box.
3. All the inputs are added and the sum is assigned to variable, total.
4. The number of dozens are obtained by dividing total by 12 and assigning the value to the variable, dozen.
5. The number of extra eggs are obtained by taking the modulus of total and 12 and the value is assigned to the variable, eggs.
6. The integer values in the variables, dozen and eggs, are converted into string using the ToString() function with that particular value.
dozen.ToString();
eggs.ToString();
7. The text boxes are assigned the respective values of dozens and number of eggs.
textBox6.Text = dozen.ToString();
textBox7.Text = eggs.ToString();
8. Two additional buttons, clear and exit, are also added.
9. The clear button erases the contents of all the text boxes. The Text property of each textbox is set to “” thereby clearing all the text fields.
10. The exit button closes the application using Close() function.
11. The program is made in visual studio and the output is attached.