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;
- using System.Threading.Tasks;
- using System.IO;
- namespace V_labaratorinis
- {
- class Lecturer
- {
- const int Cn = 100;
- private string lastname;
- private string name;
- private string faculty;
- private string cathedral;
- private int hours;
- public Lecturer()
- {
- lastname = "";
- name = "";
- faculty = "";
- cathedral = "";
- hours = 0;
- }
- public Lecturer(string lastname, string name, string faculty, string cathedral)
- {
- this.lastname = lastname;
- this.name = name;
- this.faculty = faculty;
- this.cathedral = cathedral;
- }
- public override string ToString()
- {
- string eilute;
- eilute = string.Format("| {0, -12}| {1,-11}| {2,-18}|{3,-35}|",
- lastname, name, faculty, cathedral);
- return eilute;
- }
- public static bool operator <=(Lecturer L1, Lecturer L2)
- {
- int p = String.Compare(L1.faculty, L2.faculty);
- return (p < 0);
- }
- public static bool operator >=(Lecturer L1, Lecturer L2)
- {
- int p = String.Compare(L1.faculty, L2.faculty);
- return p > 0;
- }
- public void PutHours(int hour, Lecturer L)
- {
- L.hours = hour;
- }
- public int Takehours() { return hours; }
- }
- class LecturesByTeacher
- {
- const int CMaxEil = 100; // didžiausias galimas savaičių skaičius
- const int CMaxSt = 30; // didžiausias galimas stulpelių (dienų) skaičius
- private int [,] L; // duomenų matrica
- public int n { get; set; } // eilučių skaičius (savaičių skaičius)
- public int m { get; set; } // stulpelių skaičius (dienų skaičius)
- public LecturesByTeacher()
- {
- n = 0;
- m = 0;
- L = new int [CMaxEil, CMaxSt];
- }
- public void Put(int i, int j, int numb)
- {
- L[i, j] = numb;
- }
- public int TakeNumb(int i, int j)
- {
- return L[i, j];
- }
- }
- class University
- {
- const int Cn = 100;
- private Lecturer[] L;
- public int k = 0;
- public University()
- {
- k = 0;
- L = new Lecturer[Cn];
- }
- public int Took() { return k; }
- public Lecturer Take(int i) { return L[i]; }
- public void Put(Lecturer ob) { L[k++] = ob; }
- public void Rikiuoti()
- {
- for (int i = 0; i < k - 1; i++)
- {
- Lecturer min = L[i];
- int im = i;
- for (int j = i; j < k; j++)
- {
- if (L[j] <= min)
- {
- min = L[j];
- im = j;
- }
- }
- L[im] = L[i];
- L[i] = min;
- }
- }
- }
- class Program
- {
- const int Cn = 100;
- const string Cfd = "Data.txt";
- const string CFr = "Rezults.txt";
- static void Main(string[] args)
- {
- if (File.Exists(CFr))
- File.Delete(CFr);
- University university = new University();
- LecturesByTeacher lecturesByTeacher = new LecturesByTeacher();
- double avelect=0;
- ReadLecturerAndData(Cfd, university, ref lecturesByTeacher, ref avelect);
- WritingToFileFirstDate(CFr, university, lecturesByTeacher);
- int[] D = new int[lecturesByTeacher.m];
- AllWentForLectures(lecturesByTeacher, ref D);
- HowmanyHoursWorked(university, lecturesByTeacher);
- university.Rikiuoti();
- WriteAnsersToFile(CFr, D,university,avelect);
- Console.WriteLine("Baigiu darba!");
- }
- static void ReadLecturerAndData(string fd, University U, ref LecturesByTeacher K , ref double avelect)
- {
- int quantlecturer, daysofmonth;
- string line, name, lastname, faculty, cathedral;
- int hours;
- using (StreamReader reader = new StreamReader(fd))
- {
- line = reader.ReadLine();
- string[] parts;
- quantlecturer = int.Parse(line);
- line = reader.ReadLine();
- daysofmonth = int.Parse(line);
- line = reader.ReadLine();
- avelect = double.Parse(line);
- K.n = quantlecturer;
- K.m = daysofmonth;
- for (int i = 0; i < quantlecturer; i++)
- {
- line = reader.ReadLine();
- parts = line.Split(';');
- lastname = parts[0];
- name = parts[1];
- faculty = parts[2];
- cathedral = parts[3];
- Lecturer L = new Lecturer(lastname, name,faculty, cathedral);
- U.Put(L);
- }
- for (int i = 0; i < quantlecturer; i++)
- {
- line = reader.ReadLine();
- parts = line.Split(';');
- for (int j = 0; j < daysofmonth; j++)
- {
- hours = int.Parse(parts[j]);
- K.Put(i, j, hours);
- }
- }
- }
- }
- static void WritingToFileFirstDate(string CFr, University U, LecturesByTeacher K)
- {
- using (var fr = File.AppendText(CFr))
- {
- fr.WriteLine("Lectures number: {0}",K.n);
- fr.WriteLine("Days: {0}", K.m);
- const string top = "|-----------------|----------------|-------------------------|-----------------------------------|\n" +
- "| LastName | Name | Faculty | Cathedral |\n" +
- "| | | | |\n" +
- "|-----------------|----------------|-------------------------|-----------------------------------|\n";
- fr.Write(top);
- for (int i=0; i<K.n; i++)
- {
- fr.WriteLine("{0}", U.Take(i).ToString());
- }
- fr.WriteLine("|-----------------|----------------|-------------------------|-----------------------------------|");
- fr.WriteLine("---------------------------------------------------");
- fr.Write("Dienos |");
- for (int i = 0; i < K.m; i++)
- fr.Write(" {0,-2}|", i + 1);
- fr.WriteLine();
- for (int i=0; i<K.n; i++)
- {
- fr.Write("Dėstytojas nr.{0} |", i+1);
- for (int j = 0; j < K.m; j++)
- fr.Write(" {0,-2}|",K.TakeNumb(i,j));
- fr.WriteLine("");
- }
- fr.WriteLine("---------------------------------------------------");
- }
- }
- static void AllWentForLectures(LecturesByTeacher K, ref int [] D)
- {
- int days = 0;
- int p = 0; // pozymis
- for (int j=0; j<K.m; j++)
- {
- for (int i=0; i<K.n; i++)
- {
- if (K.TakeNumb(i, j) > 0)
- p = 1;
- else { p = 0; i = K.n; }
- }
- if (p == 1)
- { D[days] = 1; days++; }
- else if (p == 0) { D[days] = 0; days++; }
- }
- }
- static void HowmanyHoursWorked (University U, LecturesByTeacher K)
- {
- int hours = 0;
- for (int i=0; i<K.n; i++)
- {
- for (int j=0; j<K.m; j++)
- {
- hours = K.TakeNumb(i, j) + hours;
- U.Take(i).PutHours(hours, U.Take(i));
- }
- hours = 0;
- }
- }
- static int LecturesAvarageHours(int i, University U,double avarage)
- {
- int p = 0;
- if (U.Take(i).Takehours() < avarage)
- p = 1;
- return p;
- }
- static void WriteAnsersToFile (string CFr,int [] D, University U, double avarage)
- {
- using (var fr = File.AppendText(CFr))
- {
- fr.WriteLine("");
- fr.WriteLine("Rezults");
- fr.WriteLine("------------------------------------------------------------------------------------------------------------");
- fr.Write("Which days all the lecturers taught: ");
- int p = 0;
- for (int i = 0; i < D.Length; i++)
- {
- if (D[i] == 1) p++;
- }
- if (p != D.Length && p != 0)
- {
- for (int i = 0; i < D.Length; i++)
- {
- if (D[i] == 1)
- fr.Write("{0} day ", i + 1);
- }
- fr.WriteLine();
- }
- else if (p == 0)
- {
- fr.WriteLine("There are no such days");
- }
- else fr.WriteLine("Lectures worked all day together");
- fr.WriteLine("------------------------------------------------------------------------------------------------------------");
- fr.WriteLine();
- fr.WriteLine("Table that has lower than avarage lectures for month:");
- int z = 0;
- for (int i = 0; i < U.k; i++)
- {
- if (LecturesAvarageHours(i, U, avarage) == 1)
- z++;
- }
- if (z > 0)
- {
- const string top = "|-----------------|----------------|-------------------------|-----------------------------------|-----------|\n" +
- "| LastName | Name | Faculty | Cathedral | Number of |\n" +
- "| | | | | days |\n" +
- "|-----------------|----------------|-------------------------|-----------------------------------|-----------|\n";
- fr.Write(top);
- for (int i = 0; i < U.k; i++)
- {
- if (LecturesAvarageHours(i, U, avarage) == 1)
- fr.WriteLine("{0} {1,-6}|", U.Take(i).ToString(), U.Take(i).Takehours());
- }
- fr.WriteLine("|-----------------|----------------|-------------------------|-----------------------------------|-----------|");
- }
- else fr.WriteLine("Table can't be done ,becouse no lectures found");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement