· 4 years ago · Nov 19, 2020, 01:58 AM
1 //Prvi
2 //main
3 Console.WriteLine("Broj kontakata za dodati: ");
4 int contactCount = Int32.Parse(Console.ReadLine());
5
6 Contact[] all_contacts = new Contact[contactCount];
7 int number_of_contacts = all_contacts.Length;
8
9 for(int i = 0; i < number_of_contacts; i++)
10 {
11 Console.WriteLine($"Informacije za {i+1}. kontakt: \n");
12 Console.WriteLine("Ime: ");
13 var first_name = Console.ReadLine();
14 Console.WriteLine("Prezime: ");
15 var last_name = Console.ReadLine();
16 Console.WriteLine("Telefonski broj: ");
17 var phone_number = Console.ReadLine();
18 Console.WriteLine("Mail adresa: ");
19 var email = Console.ReadLine();
20 while (!EmailHelper.CheckValidity(email))
21 {
22 Console.WriteLine("Mail adresa nije ispravna!\nMail adresa: ");
23 email = Console.ReadLine();
24 }
25 all_contacts[i] = new Contact(first_name, last_name, phone_number, email);
26
27 }
28 Console.WriteLine("Unesite naziv tekstualne datoteke");
29 string file_name = Console.ReadLine();
30 using (System.IO.StreamWriter file = new System.IO.StreamWriter(file_name + ".txt"))
31 {
32 file.WriteLine("Svi kontakti sa @ferit.hr adresom\n");
33
34 for (int i = 0; i < number_of_contacts; i++ )
35 {
36 if (EmailHelper.IsFeritMail(all_contacts[i].Email))
37 {
38 file.WriteLine($"{i+1}. kontakt: ");
39 file.WriteLine(all_contacts[i].FirstName);
40 file.WriteLine(all_contacts[i].LastName);
41 file.WriteLine(all_contacts[i].PhoneNumber);
42 file.WriteLine(all_contacts[i].Email);
43 }
44 }
45 Console.WriteLine("Dodan file");
46 }
47
48 //Contact.cs
49 using System;
50 using System.Collections.Generic;
51 using System.Text;
52
53 namespace ConsoleApp2
54 {
55 class Contact
56 {
57 private string first_name;
58 private string last_name;
59 private string phone_number;
60 private string email;
61
62 public Contact(string first_name, string last_name, string phone_number, string email)
63 {
64 this.first_name = first_name;
65 this.last_name = last_name;
66 this.phone_number = phone_number;
67 this.email = email;
68 }
69
70 public string FirstName { get => first_name; set => first_name = value; }
71 public string LastName { get => last_name; set => last_name = value; }
72 public string PhoneNumber { get => phone_number; set => phone_number = value; }
73 public string Email { get => email; set => email = value; }
74
75 public string Show()
76 {
77 return("Ime: " + first_name + "\n" + "Prezime: " + last_name + "\n" + "Telefonski broj: " + phone_number + "\n" + "Email: " + email);
78 }
79
80 }
81 }
82
83 //EmailHelper.cs
84 using System;
85 using System.Collections.Generic;
86 using System.Text;
87
88 namespace ConsoleApp2
89 {
90 static class EmailHelper
91 {
92 public static bool CheckValidity(string email_to_check)
93 {
94 if (!email_to_check.Contains('@')) {
95 return false;
96 }
97 string[] full_email = email_to_check.Split('@');
98 string mail_server = full_email[1];
99
100 if (mail_server == "gmail.com" || mail_server == "ferit.hr")
101 {
102 return true;
103 }
104
105 return false;
106 }
107
108 public static bool IsFeritMail(string email_to_check)
109 {
110 string[] full_email = email_to_check.Split('@');
111 string mail_server = full_email[1];
112 if (mail_server == "ferit.hr")
113 {
114 return true;
115 }
116 return false;
117
118 }
119 }
120 }
121
122// drugi
123 //main
124 static void Main(string[] args)
125 {
126 Random generator = new Random();
127 Tensor number1 = generator.NextTensor(10, 20);
128 Tensor number2 = generator.NextTensor(10, 20);
129 Tensor result = new Tensor();
130
131 result = number1 + number2;
132 Console.WriteLine(result.Show());
133
134 }
135
136 //ExtensionsHelper.cs
137 using System;
138 using System.Collections.Generic;
139 using System.Text;
140
141 namespace ConsoleApp2
142 {
143 static class ExtensionsHelper
144 {
145 public static Tensor NextTensor(this Random rnd, int bottom_limit, int upper_limit)
146 {
147 return new Tensor(Math.Round(rnd.Next(bottom_limit, upper_limit) * rnd.NextDouble(), 2), Math.Round(rnd.Next(bottom_limit, upper_limit) * rnd.NextDouble(), 2), Math.Round(rnd.Next(bottom_limit, upper_limit) * rnd.NextDouble(), 2));
148 }
149 }
150 }
151
152 //Tensor.cs
153 using System;
154 using System.Collections.Generic;
155 using System.Text;
156
157 namespace ConsoleApp2
158 {
159 class Tensor
160 {
161 private double i;
162 private double j;
163 private double k;
164
165 public Tensor()
166 {
167 i = 0;
168 j = 0;
169 k = 0;
170 }
171 public Tensor(double i, double j, double k)
172 {
173 this.i = i;
174 this.j = j;
175 this.k = k;
176 }
177
178 public double GetI { get => i; }
179 public double GetJ { get => j; }
180 public double GetK { get => k; }
181
182 public string Show()
183 {
184 return (i.ToString() + "i + " + j.ToString() + "j + " + k.ToString() + "k");
185 }
186
187 public static Tensor operator+ (Tensor first_number, Tensor second_number)
188 {
189 double i = first_number.GetI + second_number.GetI;
190 double j = first_number.GetJ + second_number.GetJ;
191 double k = first_number.GetK + second_number.GetK;
192
193 Tensor resulting_number = new Tensor(i,j,k);
194
195 return resulting_number;
196 }
197 public static Tensor operator -(Tensor first_number, Tensor second_number)
198 {
199 double i = first_number.GetI - second_number.GetI;
200 double j = first_number.GetJ - second_number.GetJ;
201 double k = first_number.GetK - second_number.GetK;
202
203 Tensor resulting_number = new Tensor(i, j, k);
204
205 return resulting_number;
206 }
207
208
209 }
210 }
211
212//treci
213 //main
214 using System;
215 using System.Globalization;
216 using System.Linq;
217
218 namespace ConsoleApp2
219 {
220 class Program
221 {
222 static void Main(string[] args)
223 {
224 string format = "g";
225 CultureInfo provider = new CultureInfo("fr-FR");
226 Console.WriteLine("Datum termina, dan: ");
227 string day = Console.ReadLine();
228 if (int.Parse(day) < 10)
229 {
230 day = "0" + day;
231 }
232 Console.WriteLine("Datum termina, mjesec: ");
233 string month = Console.ReadLine();
234 if (int.Parse(month) < 10)
235 {
236 month = "0" + month;
237 }
238 Console.WriteLine("Godina termina: ");
239 string year = Console.ReadLine();
240 Console.WriteLine("Zakazani sat: ");
241 string hour = Console.ReadLine();
242
243 string date_to_parse = day + "/" + month + "/" + year + " " + hour + ":00";
244 DateTime date = DateTime.ParseExact(date_to_parse, format, provider);
245
246 Console.WriteLine("Unesi trajanje termina, u minutama: ");
247 int duration = int.Parse(Console.ReadLine());
248
249 Appointment first_visit = new Appointment(date, duration);
250
251 Console.WriteLine("Termin pomaknut na slijedecu godinu poradi stanja u zdravstu!");
252 date_to_parse = day + "/" + month + "/" + (int.Parse(year) + 1).ToString() + " " + hour + ":00";
253 first_visit.Reschedule(DateTime.ParseExact(date_to_parse, format, provider), duration);
254 Console.WriteLine("Novi termin zakazan za: ");
255 Console.WriteLine(first_visit.GetAppointmentDateTime.ToString());
256 Console.WriteLine("________________________________");
257 Console.WriteLine("Unesi broj željenih random termina: ");
258 var number_of_wanted_appointments = int.Parse(Console.ReadLine());
259 Random generator = new Random();
260 Appointment[] all_appointments = new Appointment[number_of_wanted_appointments];
261 for (int i = 0; i < all_appointments.Length; i++)
262 {
263 date_to_parse = generator.Next(10, 28).ToString() + "/" + "0" + generator.Next(1, 9).ToString() + "/" + "2020" + " " + generator.Next(10, 19).ToString() + ":00";
264 all_appointments[i] = new Appointment(DateTime.ParseExact(date_to_parse, format, provider), 45);
265 }
266
267 Appointment[] sorted_appointments = all_appointments.OrderBy(appointment => appointment.GetAppointmentDateTime).ToArray();
268
269
270
271 for (int i = 0; i < sorted_appointments.Length; i++)
272 {
273 Console.WriteLine(sorted_appointments[i].GetAppointmentDateTime.ToString());
274 }
275
276 Console.WriteLine("Najveći razmak izmedju termina je: ");
277 Console.WriteLine($"{Math.Round(Appointment.GretestTimeSpan(sorted_appointments), 0)} dana");
278 }
279 }
280 }
281 //Appointment.cs
282 using System;
283 using System.Collections.Generic;
284 using System.Text;
285
286 namespace ConsoleApp2
287 {
288 class Appointment
289 {
290 private DateTime appointment_datetime;
291 private int duration;
292
293 public Appointment(DateTime appointment_datetime, int duration)
294 {
295 this.appointment_datetime = appointment_datetime;
296 this.duration = duration;
297 }
298
299 public DateTime GetAppointmentDateTime
300 {
301 get => appointment_datetime;
302 }
303
304 public int GetDuration
305 {
306 get => duration;
307 }
308
309 public void Reschedule(DateTime appointment_datetime, int duration)
310 {
311 this.appointment_datetime = appointment_datetime;
312 this.duration = duration;
313 }
314
315 public static double GretestTimeSpan(Appointment[] appointments)
316 {
317 TimeSpan span;
318 double total_days = 0;
319 for (int i = 1; i < appointments.Length; i++)
320 {
321 span = appointments[i].GetAppointmentDateTime - appointments[i - 1].GetAppointmentDateTime;
322 if (span.TotalDays > total_days)
323 {
324 total_days = span.TotalDays;
325 }
326 }
327
328 return total_days;
329 }
330 }
331 }
332