Program.cs
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace Quiz
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);Application.Run(new Form1());
}
}
}
————————————————————
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Quiz
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
foreach (object s in Enum.GetValues(typeof(EmployeeType)))
{
cBoEmployeeType.Items.Add(s);
}
for (int x = 15; x < 70; x++)
{
cBoAge.Items.Add(x);
}
}
private void btnCompute_Click(object sender, EventArgs e)
{
if (cBoEmployeeType.SelectedItem.ToString() == "Supervisor")
{
Supervisor s = new Supervisor(txtName.Text, Convert.ToInt32(cBoAge.SelectedItem));MessageBox.Show("Hello " + s.Name + ". You have a basic salary of\n" + s.ComputeSalary());
}
else if (cBoEmployeeType.SelectedItem.ToString() == "Secretary")
{
Secretary s = new Secretary();
s.Name = txtName.Text;
s.Age = Convert.ToInt32(cBoAge.SelectedItem);
MessageBox.Show("Hello " + s.Name + ". You have a basic salary of\n" + s.ComputeSalary());
}
else
{
Employee em = new Employee(txtName.Text, Convert.ToInt32(cBoAge.SelectedItem));MessageBox.Show("Hello " + em.Name + ". You have a basic salary of\n" + em.ComputeSalary());
}
}
}
}
—————————————————————–
Supervisor.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace Quiz
{
class Supervisor:Employee
{
public Supervisor()
{
}
public Supervisor(string name, int age)
{
}
public override double ComputeSalary()
{
return 15 * 600;
}
}
}
————————————————–
Employee.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace Quiz
{
public enum EmployeeType
{
Supervisor,
Manager,
Secretary
}
class Employee
{
public Employee()
{
}
public Employee(string name, int age)
{
this.name = name;this.age = age;
}
private string name;
public string Name
{
get { return name; }set { name = value; }
}
private int age;
public int Age
{
get { return age; }set { age = value; }
}
public virtual double ComputeSalary()
{
return 15 * 400;
}
}
}
————————————————–
Secretary.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace Quiz
{
class Secretary:Employee
{
public Secretary()
{
}
public Secretary(string name, int age)
{
}
public override double ComputeSalary()
{
return 15 * 250;
}
}
}
—————————————————————–
Form1.Designer.cs
namespace Quiz
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnCompute = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.cBoAge = new System.Windows.Forms.ComboBox();
this.txtName = new System.Windows.Forms.TextBox();
this.cBoEmployeeType = new System.Windows.Forms.ComboBox();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// btnCompute
//
this.btnCompute.Location = new System.Drawing.Point(275, 179);
this.btnCompute.Name = "btnCompute";
this.btnCompute.Size = new System.Drawing.Size(107, 23);
this.btnCompute.TabIndex = 3;
this.btnCompute.Text = "Compute Salary";
this.btnCompute.UseVisualStyleBackColor = true;
this.btnCompute.Click += new System.EventHandler(this.btnCompute_Click);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.cBoAge);
this.groupBox1.Controls.Add(this.txtName);
this.groupBox1.Controls.Add(this.cBoEmployeeType);
this.groupBox1.Location = new System.Drawing.Point(12, 12);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(378, 152);
this.groupBox1.TabIndex = 8;
this.groupBox1.TabStop = false;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(260, 44);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(29, 13);
this.label3.TabIndex = 13;
this.label3.Text = "Age:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(18, 96);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(67, 13);
this.label2.TabIndex = 12;
this.label2.Text = "Job Position:";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(47, 44);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(38, 13);
this.label1.TabIndex = 11;
this.label1.Text = "Name:";
//
// cBoAge
//
this.cBoAge.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cBoAge.FormattingEnabled = true;
this.cBoAge.Location = new System.Drawing.Point(295, 41);
this.cBoAge.Name = "cBoAge";
this.cBoAge.Size = new System.Drawing.Size(66, 21);
this.cBoAge.TabIndex = 10;
//
// txtName
//
this.txtName.Location = new System.Drawing.Point(88, 41);
this.txtName.Name = "txtName";
this.txtName.Size = new System.Drawing.Size(149, 20);
this.txtName.TabIndex = 9;
//
// cBoEmployeeType
//
this.cBoEmployeeType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cBoEmployeeType.FormattingEnabled = true;
this.cBoEmployeeType.Location = new System.Drawing.Point(88, 91);
this.cBoEmployeeType.Name = "cBoEmployeeType";
this.cBoEmployeeType.Size = new System.Drawing.Size(149, 21);
this.cBoEmployeeType.TabIndex = 8;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(417, 217);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.btnCompute);
this.Name = "Form1";
this.Text = "Salary";
this.Load += new System.EventHandler(this.Form1_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button btnCompute;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ComboBox cBoAge;
private System.Windows.Forms.TextBox txtName;private System.Windows.Forms.ComboBox cBoEmployeeType;
}
}