MohammadZaidan فريق هندسة الحواسب
الجنس : عدد المساهمات : 829
| موضوع: برنامج لحساب فاتورة كهرباء 1/6/2011, 20:56 | |
| - الكود:
-
using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace ConsoleApplication37 { class customer { int id; string name; float consum; public int ID { set { id = value; } get { return id; } } public float Consum { set { consum = value; } get { return consum; } } public string Name { set { name = value; } get { return name; } } public customer() { } public customer(int id, string name, double consum) { this.id = id; this.name = name; this.consum = consum; } public customer(customer c) { this.name = c.name; this.id = c.id; this.consum = c.consum; } public double Calc() { if (consum <= 0) return -1; else if (consum <= 1000) return consum * 0.75; else if (consum <= 2000) return 2000 * 0.75 + (consum - 1000) * 2; else return 100 * 0.75 + 1000 * 2 + (consum - 2000) * 6;
} public override string ToString() { string s = "id is " + id + "name is" + name + "Consum is" + consum + "Calc is" + Calc; return s; }
} class Program { static void Main(string[] args) { int n = Convert.ToInt32(Console.ReadLine()); customer[] l = new customer[n]; for (int i = 0; i < n; i++) { l[i] = new customer(); l[i].ID = Convert.ToInt32(Console.ReadLine()); l[i].Name = Console.ReadLine(); l[i].Consum = Convert.ToInt32(Console.ReadLine());
} for (int i = 0; i < n; i++) { Console.WriteLine(l[i].ID); Console.WriteLine(l[i].Name); Console.WriteLine(l[i].Consum); } double sum = 0; for (int i=0;i<l.Length;i++) { sum = sum + l[i].Consum;
}
Console.WriteLine(sum / l.Length); for ( int i=0;i<l.Length;i++) float max = l[0].Name;
int j=0; for (int i=0;i<l.Length;i++) { max=l[i].Consum; j=i;} Console.WriteLine(""+l[j].Name);
} } }
| |
|