Form2 Form: Namespace Public Partial Class Public

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 9

Classes within Classes namespace classobjects { public partial class Form2 : Form { public Form2() { InitializeComponent(); } string regno,

rollno, FatherName, MotherName; DateTime DoB; public class sname { string firstName, MiddleName, LastName; public sname() { MessageBox.Show("Executing sname default Constructor"); firstName = ""; MiddleName = ""; LastName = ""; } public void GetData(ref string fn, ref string mn, ref string ln) { MessageBox.Show("Executing GetData(fn,mn,ln) of sname class"); firstName = fn; MiddleName = mn; LastName = ln; } public void ShowData() { MessageBox.Show("Executing ShowData() of sname class"); MessageBox.Show("First Name : " + firstName); MessageBox.Show("Middle Name : " + MiddleName); MessageBox.Show("Last Name : " + LastName); } } private void Form2_Load(object sender, EventArgs e) { string firstname = "Arun";

string midname = "kumar"; string lastName = "Singh"; sname objsn = new sname(); MessageBox.Show("in Form2 calling GetData() of sname class"); objsn.GetData(ref firstname, ref midname, ref lastName); MessageBox.Show("in Form2 calling ShowData() of sname class"); objsn.ShowData(); MessageBox.Show("Back in Form2 Class."); } } }

Classes within same .cs file(same namespace) namespace classobjects { public partial class Form2 : Form { public Form2() { InitializeComponent(); } string regno, rollno, sname, FatherName, MotherName; DateTime DoB; public void GetData(ref string fn, ref string mn, ref string ln) { firstName = fn; MiddleName = mn; LastName = ln; } public void ShowData() { MessageBox.Show("Executing ShowData() of sname class"); MessageBox.Show("First Name : " + firstName); MessageBox.Show("Middle Name : " + MiddleName); MessageBox.Show("Last Name : " + LastName); }

} private void Form2_Load(object sender, EventArgs e) { regno = "11011033"; MessageBox.Show("Creating object of fee class in Form2 class"); fee objFee = new fee(); MessageBox.Show("Calling feeDue() of fee Class from Form2 Class"); objFee.feeDue(ref regno); MessageBox.Show("Calling feepaid() of fee Class from Form2 Class"); objFee.feePaid(ref regno, 20000); MessageBox.Show("Back in Form2 Class."); // collecting fee of another student fee objFee1 = new fee(); regno = "11011034"; objFee1.feeDue(ref regno); objFee1.feePaid(ref regno, 40000); //collecting fee of another student by calling parametrized constructor. fee objfee2 = new fee(40000); regno = "11011035"; objfee2.feePaid(ref regno, 50000); //copy constructor fee objfee3 = new fee(objFee1); objFee.feePaid(ref regno, 30000);

} } public class fee { Double dueFee, FePaid, BalFee; string RegistrationNo; DateTime feePaidDate, dueDate, BalFeeDate, ReceiptDate=DateTime.Today ; static int ReceiptNo=1;

public fee() { dueFee = 0.0; FePaid = 0.0; BalFee = 0.0; } public fee(double Dfe) { dueFee = Dfe; FePaid = 0.0; BalFee = 0.0; dueDate = DateTime.Today; } public fee(fee objfee3) { dueFee = objfee3.dueFee ; FePaid = objfee3.FePaid; BalFee = objfee3.BalFee; dueDate = DateTime.Today; } ~fee() { MessageBox.Show("Executing Destructor"); } public void feeDue(ref string { MessageBox.Show("Executing RegistrationNo = regno; dueFee = 40000; dueDate = DateTime.Today; } public void feePaid(ref string { MessageBox.Show("Executing RegistrationNo = regno; FePaid = tf; regno) feeDue() of fee class");

regno, double tf) feePaid() of fee class");

feePaidDate = DateTime.Today; MessageBox.Show(" Receipt No : " + ReceiptNo.ToString() + " Dated : " + ReceiptDate.ToShortDateString()); if (FePaid < dueFee) { BalFee = dueFee - FePaid; BalFeeDate = DateTime.Today.AddDays(7); } else { BalFee = dueFee - FePaid; BalFeeDate = DateTime.Today; } MessageBox.Show("Fee Due :" + dueFee.ToString() + " Fee Paid : " + FePaid.ToString() + " Balance Fee : " + BalFee.ToString() + " Balance Fee Pay Date : " +BalFeeDate.ToShortDateString()); ReceiptNo++; } } }

Complete Program namespace classobjects { public partial class Form2 : Form { public Form2() { InitializeComponent(); } string regno, rollno, FatherName, MotherName; DateTime DoB; public class sname { string firstName, MiddleName, LastName;

public sname() { MessageBox.Show("Executing sname default Constructor"); firstName = ""; MiddleName = ""; LastName = ""; } public void GetData(ref string fn, ref string mn, ref string ln) { MessageBox.Show("Executing GetData(fn,mn,ln) of sname class"); firstName = fn; MiddleName = mn; LastName = ln; } public void ShowData() { MessageBox.Show("Executing ShowData() of sname class"); MessageBox.Show("First Name : " + firstName); MessageBox.Show("Middle Name : " + MiddleName); MessageBox.Show("Last Name : " + LastName); } } private void Form2_Load(object sender, EventArgs e) { /* string firstname = "Arun"; string midname = "kumar"; string lastName = "Singh"; sname objsn = new sname(); MessageBox.Show("in Form2 calling GetData() of sname class"); objsn.GetData(ref firstname, ref midname, ref lastName); MessageBox.Show("in Form2 calling ShowData() of sname class"); objsn.ShowData(); MessageBox.Show("Back in Form2 Class.");*/ ////using fee class in form2 class regno = "11011033"; MessageBox.Show("Creating object of fee class in Form2 class"); fee objFee = new fee();

MessageBox.Show("Calling feeDue() of fee Class from Form2 Class"); objFee.feeDue(ref regno); MessageBox.Show("Calling feepaid() of fee Class from Form2 Class"); objFee.feePaid(ref regno, 20000); MessageBox.Show("Back in Form2 Class."); // collecting fee of another student fee objFee1 = new fee(); regno = "11011034"; objFee1.feeDue(ref regno); objFee1.feePaid(ref regno, 40000); //collecting fee of another student by calling parametrized constructor. fee objfee2 = new fee(40000); regno = "11011035"; objfee2.feePaid(ref regno, 50000); //copy constructor fee objfee3 = new fee(objFee1); objFee.feePaid(ref regno, 30000);

} } public class fee { Double dueFee, FePaid, BalFee; string RegistrationNo; DateTime feePaidDate, dueDate, BalFeeDate, ReceiptDate=DateTime.Today ; static int ReceiptNo=1; public fee() { dueFee = 0.0; FePaid = 0.0; BalFee = 0.0; } public fee(double Dfe)

{ dueFee = Dfe; FePaid = 0.0; BalFee = 0.0; dueDate = DateTime.Today; } public fee(fee objfee3) { dueFee = objfee3.dueFee ; FePaid = objfee3.FePaid; BalFee = objfee3.BalFee; dueDate = DateTime.Today; } ~fee() { MessageBox.Show("Executing Destructor"); } public void feeDue(ref string regno) { MessageBox.Show("Executing feeDue() of fee class"); RegistrationNo = regno; dueFee = 40000; dueDate = DateTime.Today; } public void feePaid(ref string regno, double tf) { MessageBox.Show("Executing feePaid() of fee class"); RegistrationNo = regno; FePaid = tf; feePaidDate = DateTime.Today; MessageBox.Show(" Receipt No : " + ReceiptNo.ToString() + " Dated : " + ReceiptDate.ToShortDateString()); if (FePaid < dueFee) { BalFee = dueFee - FePaid; BalFeeDate = DateTime.Today.AddDays(7);

} else { BalFee = dueFee - FePaid; BalFeeDate = DateTime.Today; } MessageBox.Show("Fee Due :" + dueFee.ToString() + " Fee Paid : " + FePaid.ToString() + " Balance Fee : " + BalFee.ToString() + " Balance Fee Pay Date : " +BalFeeDate.ToShortDateString()); ReceiptNo++; } } }

You might also like