You are on page 1of 5

# Network Programming and WCF

LABORATOR 2

C#
STRUCTURI FUNDAMENTALE DE CONTROL. STRUCTURI DE DATE: VECTORI UNIDIMENSIONALI
1. Se initializeaza un vector cu note ale studentilor. Sa se calculeze numarul de note pe fiecare interval 1-4, 4-5, 5-6, 6-7, 7-8, 8-9, 9-10. Sa se calculeze media notelor intre 1 si 10. Sa se calculeze media pentru un interval specificat de utilizator

static void Main(string[] args) { int i, note1_4 = 0, note4_5 = 0, note5_6 = 0, note6_7 = 0, note7_8 = 0, note8_9 = 0, note9_10 = 0, note_imposibile = 0; float [] note = {3.7F,4.5F,8,10,9.2F,2,2,7,6,9,5,4,3,1,5.7F,6.3F,10,10,1,7,6.8F,7,9,2,4,8,10, 8.5F,7,8,12}; float medie = 0; for (i = 0; i < note.Length; i++) { if (note[i] >= 1 && note[i] <= 4) { note1_4 = note1_4 + 1; continue; } else if (note[i] > 4 && note[i] <= 5) { note4_5 = note4_5 + 1; continue; } else if (note[i] > 5 && note[i] <= 6) { note5_6 = note5_6 + 1; continue; } else if (note[i] > 6 && note[i] <= 7) { note6_7 = note6_7 + 1; continue; } else if (note[i] > 7 && note[i] <= 8) { note7_8 = note7_8 + 1; continue; } else if (note[i] > 8 && note[i] <= 9) { note8_9 = note8_9 + 1;

Console. } // metoda 1 foreach static float calculeazaMedie(float[] temp_vector) { float medie = 0. Console. Console. Console.WriteLine("Note intre 5-6 : " + note5_6).Network Programming and WCF continue. Console.WriteLine("Note intre 7-8 : " + note7_8). } } medie = suma_elemente / count. i < temp_vector.WriteLine("Media notelor intre 1 si 10 " + medie). Console. int count = 0. Console.WriteLine("Media notelor intre 1 si 10 varianta 1 este: " + medie). foreach (float f in temp_vector) { if (f >= 1 && f <= 10) { count++.WriteLine("Note intre 9-10 : " + note9_10). float suma_elemente = 0. return medie. Console. } else if (note[i] > 9 && note[i] <= 10) { note9_10 = note9_10 + 1. float suma_elemente = 0. i++ ) varianta 2 este: .WriteLine("Media notelor intre 8 si 10 este: " + medie).10.note).WriteLine("Note imposibile : " + note_imposibile).ReadLine().WriteLine("Note intre 4-5 : " + note4_5). Console.WriteLine("Note intre 1-4 : " + note1_4).WriteLine("Note intre 8-9 : " + note8_9). } } medie = calculeazaMedie(note). int count = 0. continue. medie = calculeazaMedie_v2(note). } else { note_imposibile = note_imposibile + 1. Console. suma_elemente = suma_elemente + f.WriteLine("Note intre 6-7 : " + note6_7). Console.Length. Console. medie = calculeazaMedie_v3(8. for (int i = 0. } // metoda 2 for static float calculeazaMedie_v2(float[] temp_vector) { float medie = 0. continue.

} static float calculeazaMedie_v3(int limita_minima.Write("Introduceti cuvantul cautat: "). return medie. float [] tempVector) { int count = 0. int numar_aparitii_cuvant = 0. // Declararea unui string string cuvant_cautat = string.ReadLine(). #endregion s = Console. Impartirea unui string in cuvinte. Console. Cautarea numarului de aparitii ale unui cuvant in cadrul unui string class Program { static void Main(string[] args) { # region declaratii_si_initializari_variabile string s = string. suma = suma + f.ReadLine(). Console. int limita_maxima. float suma = 0. } 2. } } medie = suma_elemente / count. float medie = 0. // 'cuvinte' reprezinta un vector de stringuri // stringul 's' va fi impartit in substringuri la intalnirea unui caracter din setcaractere // fiecare substring va fi salvat in vectorul cuvinte int i = cuvinte.Length. } } medie = suma / count. //Dimensiunea vectorului cuvinte . // Citirea stringului si salvarea in s' string[] cuvinte = s.Write("Introduceti stringul : ").Split(' '). suma_elemente = suma_elemente + temp_vector[i]. foreach (float f in tempVector) { if (f >= limita_minima && f < limita_maxima) { count++.Empty.Empty. cuvant_cautat = Console. return medie.Network Programming and WCF { if (temp_vector[i] >= 1 && temp_vector[i] <= 10) { count++.

Parse(Console. Console. Console. no = int. Console. } } return numar_aparitii. count = 0.")) { cuvantFinal = cuvant. cuvinte). Sa se calculeze si sa se afiseze numerele din seria Fibonnaci static void Main(string[] args) { int first = 1. } return cuvantFinal.WriteLine("\n Numarul nu trebuie sa depaseasca 45 : " + sum).WriteLine("The total number of words in the entered string : " + i). second = 1. third.WriteLine("Cuvantul: " + cuvant_cautat + " a aparut de: " + numar_aparitii_cuvant).Length . long sum = 2. .Network Programming and WCF numar_aparitii_cuvant = cautaCuvant(cuvant_cautat. first = second. string[] vector_cuvinte) { int numar_aparitii = 0.Write("Enter the number uptill which you want the fibonacci numbers :").ReadLine().Write(" " + third). Console. foreach (string temp_string in vector_cuvinte) { if (formateazaCuvant(temp_string) == cuvant) { numar_aparitii++.1).EndsWith(". if (cuvant. } else { Console. Console. } static int cautaCuvant(string cuvant. if (no >= 45) { Console.Remove(cuvant.Write("Fibonacci Series : 1 1"). do { third = first + second.ReadLine()). no. } static string formateazaCuvant(string cuvant) { string cuvantFinal = cuvant. } } 3.

255.Length). A. 510 }.0.Length.WriteLine("\nSum of all fibonacci digits : " + sum). 550). Sa se inverseze valorile vectorului destinatie static void Main(string[] args) { int[] A = { 127.Copy(B. # region metoda 1 for (int i = 0.Sort(C). } #endregion #region metoda 2 Array.Length). 209.550). sum = sum + third. B. #endregion #region diferite metode din clasa vector Array. 0.IndexOf(Vector_Destinatie. int[] B = { 275.ReadLine(). pozitie_numar = Array. Array.Reverse(Vector_Destinatie). contor_C = contor_C + 1.A. int pozitie_numar = Array. int[] Vector_Destinatie = new int[CLength]. Console.Length. } contor_C = contor_C + 1.Length. pozitie_numar = Array. #endregion Console. 550. Sa se copie elementele a doi vectori intr-un al treilea vector. Sa se ordoneze vectorul destinatie. int[] C = new int[CLength]. } while ((count + 3) <= no). j++) { C[contor_C] = B[j].Sort(Vector_Destinatie). 150.Length + B. } } 4.Length). 157. j < B. int contor_C = 0. i++) { C[i] = A[i]. Vector_Destinatie.BinarySearch(Vector_Destinatie.Copy(A. 4 . 7 }.Network Programming and WCF second = third. 157.Vector_Destinatie. i < A. 240. 550). int CLength = (A. 750.0. contor_C = i. count = count + 1. } . 1. for (int j = 0.LastIndexOf(Vector_Destinatie. Array. Array.