annmee吧 关注:1贴子:73
  • 3回复贴,共1


IP属地:上海1楼2014-06-11 21:45回复
    医疗费用(1)
    #include <iostream>
    using namespace std;
    int main ()
    { float x;
    cout<<"实际医疗费:";
    cin>>x;
    if (x<2000) x=0.15*x;
    if (x>=2000&&x<4000) x=0.1*x;
    if (x>=4000&&x<6000) x=0.08*x;
    if (x>=6000) x=0.05*x;
    cout<<"应收取医疗费:"<<x<<endl;
    return 0;
    }
    (2)
    #include <iostream>
    using namespace std;
    int main ()
    { float x;
    int c;
    cout<<"实际医疗费:"<<endl;
    cin>>x;
    c=x/1000;
    switch(c)
    {
    case 0:case 1:x=0.15*x;break;
    case 2:case 3:x=0.1*x;break;
    case 4:case 5:x=0.08*x;break;
    default:x=0.05*x;break;
    }
    cout<<"应收取医疗费:"<<x<<endl;
    return 0;
    }


    IP属地:上海2楼2014-10-17 14:40
    回复
      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      using System.IO ;
      namespace Chapter7Date515
      {
      class Program
      {
      public void writedata()
      {
      FileStream fs = new FileStream("E:\\a.txt", FileMode.Create, FileAccess.Write);
      StreamWriter sw = new StreamWriter(fs);
      sw.WriteLine("JJJesse;27;123");
      sw.WriteLine("Pinkman;30;234");
      sw.WriteLine("Hesinberg;55;789");
      sw.Flush();
      sw.Close();
      fs.Close();
      }
      public void addetails()
      {
      FileStream fs = new FileStream("E:\\a.txt", FileMode.Append , FileAccess.Write);
      StreamWriter sw = new StreamWriter(fs);
      Console.WriteLine("please write the information ");
      string s = Console.ReadLine();
      sw.WriteLine(s);
      sw.Flush();
      sw.Close();
      fs.Close();
      }
      public void searchdata(string find)
      {
      FileStream fs = new FileStream("E:\\a.txt", FileMode.Open, FileAccess.Read);
      StreamReader sr = new StreamReader(fs);
      sr.BaseStream.Seek(2, SeekOrigin.Begin);
      string s = sr.ReadLine();
      string[] ss;
      while (s != null)
      {
      ss = s.Split(';');
      if (ss[0] == find)
      {
      Console.WriteLine("The name is: {0}", ss[0]);
      Console.WriteLine("The age is: {0}", ss[1]);
      Console.WriteLine("The tellphone no is: {0}", ss[2]);
      }
      s = sr.ReadLine();
      }
      sr.Close();
      fs.Close();
      }
      public void readdata()
      {
      FileStream fs = new FileStream("E:\\a.txt", FileMode.Open , FileAccess.Read );
      StreamReader sr = new StreamReader(fs);
      sr.BaseStream.Seek(2, SeekOrigin.Begin);
      string s = sr.ReadLine ();
      string[] ss;
      while (s != null)
      {
      ss = s.Split(';');
      Console.WriteLine("The name is: {0}" , ss[0]);
      Console.WriteLine("The age is: {0}" , ss[1]);
      Console.WriteLine("The tellphone no is: {0}" , ss[2]);
      s = sr.ReadLine();
      }
      sr.Close();
      fs.Close();
      }
      public void filehandle(Program p)
      {
      string ch = "Y";
      Console.WriteLine("Do you want to 1:search the data 2:display all details 3:add data");
      int i = Convert.ToInt32(Console.ReadLine());
      switch (i)
      {
      case 1: Console.WriteLine("Search:"); p.searchdata(Console.ReadLine()); break;
      case 2: p.readdata(); break;
      case 3: p.addetails(); break;
      }
      Console.WriteLine("Do you want to continue ?Y/N");
      ch = Console.ReadLine().ToUpper();
      if (ch=="Y") filehandle (p);
      }
      static void Main(string[] args)
      {
      Program p = new Program();
      p.writedata();
      p.filehandle(p);
      }
      }
      }


      IP属地:上海3楼2015-05-20 14:41
      回复
        using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.Text;
        using System.Threading.Tasks;
        namespace _6_20OverloadingAnOperator
        {
        class Distance
        {
        internal int Length;
        public Distance (){Length=0;}
        public Distance(int l) { Length = l; }
        public static bool operator <(Distance d1,Distance d2)
        {
        return d1.Length < d2.Length;
        }
        public static bool operator >(Distance d1, Distance d2)
        {
        return d1.Length > d2.Length;
        }
        public Distance Max(Distance d1,Distance d2)
        {
        if (d1 < d2) return d2;
        else return d1;
        }
        public static Distance operator &(Distance d1,Distance d2)
        {
        return d1.Length>d2.Length?d1:d2;
        }
        public static Distance operator +(Distance d1,int value)
        {
        d1.Length += value ;
        return d1;
        }
        public void DisplayDistance(Distance d1,int Length)
        {
        Distance Result;
        Console.WriteLine("The distance of travel is{0}",d1 .Length );
        Console.WriteLine("The distance to reach the destination is{0}",Length);
        Result = d1 + Length;
        Console.WriteLine("The total distant you need to travel is {0}", Result.Length);
        }
        }
        class EntryPoint
        {
        static void Main(string[] args)
        {
        Distance d1 = new Distance(15);
        Distance d2 = new Distance(12);
        Distance d3 = d1 & d2;
        d3.DisplayDistance(d3,0);
        // string Location;
        // int TravelledDistance;
        // Console.WriteLine("Enter the Location you have reached :A,B,C");
        // Location = Console.ReadLine().ToUpper();
        // if (Location == "A" || Location == "B" || Location == "C")
        // {
        // Console.WriteLine("Enter the distance you have covered:");
        // TravelledDistance = Convert.ToInt32(Console.ReadLine());
        // d2.Length = TravelledDistance;
        // switch (Location)
        // {
        // case "A":
        // d1.DisplayDistance (d2,15);break;
        // case "B":
        // d1.DisplayDistance(d2, 20); break;
        // case "C":
        // d1.DisplayDistance(d2, 25); break;
        // default :Console .WriteLine ("The Location cannot be found");
        // break;
        // }
        // }
        // else Console.WriteLine ("Incorrect value");
        //Console.ReadLine ();
        }
        }
        }


        IP属地:上海4楼2015-05-20 14:41
        回复