Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication1
- {
- class cd
- {
- protected int year;
- protected int cost;
- protected int tracks;
- public void set_year(int x)
- {
- if (1970 <= x && x <= 2013)
- {
- year = x;
- }
- else
- {
- throw new Exception("Rossz évszám!");
- }
- }
- public void set_const(int x)
- {
- if (200 <= x && x <= 10000)
- {
- cost = x;
- }
- else
- {
- throw new Exception("nem jó árat adtál meg");
- }
- }
- public void set_tracks(int a)
- {
- if (1 <= a && a <= 20)
- {
- tracks = a;
- }
- else
- {
- throw new Exception("Nem megfelelő a trackek száma!");
- }
- }
- public int get_year()
- {
- return year;
- }
- public int get_cost()
- {
- return cost;
- }
- public int get_tracks()
- {
- return tracks;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- List<cd> L = new List<cd>();
- Random rand = new Random();
- for (int i = 0; i < 100; i++)
- {
- cd c = new cd();
- c.set_const(rand.Next(200, 10001));
- c.set_tracks(rand.Next(1, 21));
- c.set_year(rand.Next(1970, 2014));
- L.Add(c);
- }
- double summa = 0;
- for (int i = 0; i < L.Count; i++)
- {
- summa += L[i].get_cost();
- }
- double atlag = summa / L.Count;
- Console.WriteLine("Átlagosan egy CD ára: {0}", atlag);
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement