Several C # PROGRAMS

Source: Internet
Author: User
Tags bool

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 ());
}
}
}



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.