• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

我的印度软件老师,给的几个C#PROGRAMS

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

using System;

namespace Wrox.ProCSharp.OOProg     //The first 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 change password for myAccess");
         done = myAccess.ChangePassword("", "AnotherPassword");
         if (done == true)
            Console.WriteLine("Password for myAccess changed");
         else
            Console.WriteLine("Failed to 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 change password for myAccess");
         done = myAccess.ChangePassword("", "AnotherPassword");
         if (done == true)
            Console.WriteLine("Password for myAccess changed");
         else
            Console.WriteLine("Failed to 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());  
      }
   }
}


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
一个21行C#代码实现的神经网络发布时间:2022-07-14
下一篇:
三、基于Flask的Python和C#交互(前篇)发布时间:2022-07-14
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap