国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

幾個C# PROGRAMS

2024-07-21 02:17:50
字體:
來源:轉載
供稿:網友
 

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

菜鳥學堂:
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 唐山市| 威远县| 镇宁| 志丹县| 彩票| 宁河县| 合山市| 惠水县| 荆州市| 玛多县| 偏关县| 乐业县| 霍州市| 定远县| 鄂伦春自治旗| 灵山县| 通州市| 台前县| 祁连县| 托里县| 仙桃市| 开阳县| 玉溪市| 宾川县| 琼海市| 东至县| 达尔| 屏山县| 宁阳县| 察哈| 陆丰市| 新绛县| 青海省| 涞源县| 三亚市| 保山市| 澄城县| 罗平县| 苗栗市| 安宁市| 呈贡县|