Using System;
Namespace Wrox.ProCSharp.OOProg//the
{
Class Mainentrypoint
{
static void Main ()
{
Authenticator myaccess = new Authenticator ();
BOOL done;
Done = Myaccess.changepassword ("", "Mynewpassword");
if (done = = true)
Console.WriteLine ("Password for myaccess changed");
Else
Console.WriteLine ("Failed to the Change password for myaccess");
Done = Myaccess.changepassword ("", "Anotherpassword");
if (done = = true)
Console.WriteLine ("Password for myaccess changed");
Else
Console.WriteLine ("Failed to the Change password for myaccess");
if (Myaccess.ispasswordcorrect ("Whatpassword"))
Console.WriteLine ("Verified myaccess\ ' password");
Else
Console.WriteLine ("Failed to verify myaccess\ ' password");
}
}
public class Authenticator
{
Implementation as shown earlier
private String password = "";
public bool Ispasswordcorrect (string Trypassword)
{
return (Trypassword = = password)? True:false;
}
public bool ChangePassword (string OldPassword, String newpassword)
{
if (OldPassword = = password)
{
Password = newpassword;
return true;
}
Else
return false;
}
}
}
Using System;
Namespace Wrox.ProCSharp.OOProg//the Second Program
{
Class Mainentrypoint
{
static void Main ()
{
Authenticator myaccess = new Authenticator ();
BOOL done;
Done = Myaccess.changepassword ("", "Mynewpassword");
if (done = = true)
Console.WriteLine ("Password for myaccess changed");
Else
Console.WriteLine ("Failed to the Change password for myaccess");
Done = Myaccess.changepassword ("", "Anotherpassword");
if (done = = true)
Console.WriteLine ("Password for myaccess changed");
Else
Console.WriteLine ("Failed to the Change password for myaccess");
if (Myaccess.ispasswordcorrect ("Whatpassword"))
Console.WriteLine ("Verified myaccess\ ' password");
Else
Console.WriteLine ("Failed to verify myaccess\ ' password");
}
}
public class Authenticator
{
Implementation as shown earlier
private String password = "";
public bool Ispasswordcorrect (string Trypassword)
{
return (Trypassword = = password)? True:false;
}
public bool ChangePassword (string OldPassword, String newpassword)
{
if (OldPassword = = password)
{
Password = newpassword;
return true;
}
Else
return false;
}
}
}
Namespace Wrox.ProCSharp.OOProg
{
Using System;
public enum Typeofcall
{
Calltocellphone, Calltolandline
}
public class Customer
{
private string name;
private decimal balance;
public string Name
{
Get
{
return name;
}
Set
{
name = value;
}
}
Public decimal Balance
{
Get
{
return balance;
}
}
public void Recordpayment (decimal amountpaid)
{
Balance-= Amountpaid;
}
public void Recordcall (Typeofcall calltype, uint nminutes)
{
Switch (CallType)
{
Case Typeofcall.calltolandline:
Balance + + (0.02M * nminutes);
Break
Case Typeofcall.calltocellphone:
Balance + + (0.30M * nminutes);
Break
Default
Break
}
}
}
public class Mainentrypoint
{
public static void Main ()
{
Customer Arabel = new Customer ();
Arabel. Name = "Arabel Jones";
Customer Mrjones = new Customer ();
Mrjones.name = "Ben Jones";
Arabel. Recordcall (Typeofcall.calltolandline, 20);
Arabel. Recordcall (Typeofcall.calltocellphone, 5);
Mrjones.recordcall (Typeofcall.calltolandline, 10);
Console.WriteLine ("{0,-20} owes ${1:f2}", Arabel. Name, Arabel. Balance);
Console.WriteLine ("{0,-20} owes ${1:f2}", Mrjones.name, mrjones.balance);
}
}
}
Namespace Wrox.ProCSharp.OOProg
{
Using System;
public enum Typeofcall
{
Calltocellphone, Calltolandline
}
public class Customer
{
private string name;
protected decimal balance;
public string getfunnystring ()
{
Return "Plain ordinary customer. Kaark! ";
}
public string Name
{
Get
{
return name;
}
Set
{
name = value;
}
}
Public decimal Balance
{
Get
{
return balance;
}
}
public void Recordpayment (decimal amountpaid)
{
Balance-= Amountpaid;
}
public virtual void Recordcall (Typeofcall calltype, uint nminutes)
{
Switch (CallType)
{
Case Typeofcall.calltolandline:
Balance + + (0.02M * nminutes);
Break
Case Typeofcall.calltocellphone:
Balance + + (0.30M * nminutes);
Break
Default
Break
}
}
}
public class Nevermore60customer:customer
{
private UINT highcostminutesused;
Public new string getfunnystring ()
{
Return "Nevermore60. Nevermore! ";
}
public override void Recordcall (Typeofcall calltype, uint nminutes)
{
Switch (CallType)
{
Case Typeofcall.calltolandline:
Balance + + (0.02M * nminutes);
Break
Case Typeofcall.calltocellphone:
UINT Highcostminutes, lowcostminutes;
UINT Highcostminutestogo =
(Highcostminutesused < 60)? 60-highcostminutesused:0;
if (Nminutes > Highcostminutestogo)
{
Highcostminutes = Highcostminutestogo;
Lowcostminutes = nminutes-highcostminutes;
}
Else
{
Highcostminutes = nminutes;
lowcostminutes = 0;
}
highcostminutesused + = Highcostminutes;
Balance = (0.50M * highcostminutes + 0.20M *
Lowcostminutes);
Break
Default
Break
}
}
}
public class Mainentrypoint
{
public static void Main ()
{
Customer Cust1;
Nevermore60customer Cust2;
Cust1 = new Customer ();
Console.WriteLine ("Customer referencing Customer:"
+ Cust1. Getfunnystring ());
Cust1 = new Nevermore60customer ();
Console.WriteLine ("Customer referencing Nevermore60customer:"
+ Cust1. Getfunnystring ());
Cust2 = new Nevermore60customer ();
Console.WriteLine ("Nevermore60customer Referencing:"
+ Cust2. Getfunnystring ());
}
}
}