static void Main(string[] args) { int totalRunningTimes = 20; Stopwatch sw = new Stopwatch(); StreamWriter OurStream; OurStream = File.CreateText("C:/Users/William/Desktop/Clone/CAB301/Assignment_2/Experimental Data Result/BruteForceMedian(Experimental).txt"); for (int size = 1000; size <= 10000; size += 1000) { long totalmilliSecs = 0; double averageMilliSecs = 0; for (int i = 1; i <= totalRunningTimes; i++) { long milliSecs = 0; int[] randomArray = GenerateRandomArray(size); sw.Start(); BruteForceMedian(randomArray); sw.Stop(); milliSecs = sw.ElapsedMilliseconds; totalmilliSecs = totalmilliSecs + milliSecs; } averageMilliSecs = totalmilliSecs * 1.0 / totalRunningTimes; OurStream.WriteLine("Size:" + size + ", Average Running Time (MilliSec)=" + averageMilliSecs); OurStream.WriteLine("Basic operation counter for input size " + size + " is " + counter); OurStream.WriteLine("\n"); } Console.WriteLine("Experiment Completed"); OurStream.Close(); Console.ReadKey(); }
public static void Main(string[] args) { StreamWriter OurStream; OurStream = File.CreateText("C:/Users/William/Desktop/Clone/CAB301/Experimental Data Result/test.txt"); int totalRunningTimes = 20; Stopwatch sw = new Stopwatch(); for (int size = 5000; size <= 100000; size += 5000) { long totalMilliSecs = 0; double averageMilliSecs = 0; for (int i = 1; i <= totalRunningTimes; i++) { long milliSecs = 0; int[] A = GenerateRandomArray(size); sw.Start(); NegBeforePos(A); sw.Stop(); milliSecs = sw.ElapsedMilliseconds; totalMilliSecs = totalMilliSecs + milliSecs; } averageMilliSecs = totalMilliSecs * 1.0 / totalRunningTimes; OurStream.WriteLine("Size:" + size + ", Average Running Time (MilliSec)=" + averageMilliSecs); OurStream.WriteLine("Basic operation counter for input size " + size + " is " + counter); OurStream.WriteLine("\n"); } Console.WriteLine("Test Result created!"); OurStream.Close(); Console.ReadKey(); }
static void Main(string[] args) { StreamWriter OurStream; OurStream = File.CreateText("C:/Users/William/Desktop/Clone/CAB301/Assignment_2/Experimental Data Result/test.txt"); int[] sortedAllPos = { 1, 1, 1, 1, 1, 1, 1 }; int[] sortedAllNeg = { -1, -1, -1, -1, -1, -1, -1 }; int[] sorted = { 1, 2, 3, 4, 5, 6, 7 }; int[] sortedNeg = { -1, -2, -3, -4, -5, -6, -7 }; int[] decending = { 7, 6, 5, 4, 3, 2, 1 }; int[] decendingNeg = { -7, -6, -5, -4, -3, -2, -1 }; int[] singleValue = { 5 }; int[] emptyValue = { }; int[] testOne = { -10, 0, 10 }; int[] testTwo = { -100, 1, 2, 3, 100 }; int[] testThree = { 7, 3, 2, 6, 5, 4, 1 }; int[] evenArray = { 1, 2, 3, 4 }; int[] a = { 4, 1, 10, 9, 7, 12, 8, 2, 15 }; OurStream.WriteLine("The array is [{0}] \nThe returned median value is {1}", string.Join(", ", sortedAllPos), BruteForceMedian(sortedAllPos)); OurStream.WriteLine("The array is [{0}] \nThe returned median value is {1}", string.Join(", ", sortedAllNeg), BruteForceMedian(sortedAllNeg)); OurStream.WriteLine("The array is [{0}] \nThe returned median value is {1}", string.Join(", ", sorted), BruteForceMedian(sorted)); OurStream.WriteLine("The array is [{0}] \nThe returned median value is {1}", string.Join(", ", decending), BruteForceMedian(decending)); OurStream.WriteLine("The array is [{0}] \nThe returned median value is {1}", string.Join(", ", singleValue), BruteForceMedian(singleValue)); OurStream.WriteLine("The array is [{0}] \nThe returned median value is {1}", string.Join(", ", emptyValue), BruteForceMedian(emptyValue)); OurStream.WriteLine("The array is [{0}] \nThe returned median value is {1}", string.Join(", ", testOne), BruteForceMedian(testOne)); OurStream.WriteLine("The array is [{0}] \nThe returned median value is {1}", string.Join(", ", testTwo), BruteForceMedian(testTwo)); OurStream.WriteLine("The array is [{0}] \nThe returned median value is {1}", string.Join(", ", testThree), BruteForceMedian(testThree)); OurStream.WriteLine("The array is [{0}] \nThe returned median value is {1}", string.Join(", ", evenArray), BruteForceMedian(evenArray)); Console.WriteLine("Completed"); OurStream.Close(); Console.ReadKey(); }
static void Main(string[] args) { StreamWriter OurStream; OurStream = File.CreateText("C:/Users/William/Desktop/Clone/CAB301/Assignment_2/Experimental Data Result/BruteForceMedian(Random_Array).txt"); int[] randomArray = GenerateRandomArray(10); OurStream.WriteLine("The array is [{0}] \nThe returned median value is {1}", string.Join(", ", randomArray), BruteForceMedian(randomArray)); Console.WriteLine("Completed"); OurStream.Close(); Console.ReadKey(); }
/// <summary> /// Created this method to update the teacher’s details based on provided teacher’s ID in text file /// </summary> /// <param name="teacherDetail"></param> /// <returns></returns> public bool Update(TeacherDetail teacherDetail) { bool returnVal = false; try { if (!File.Exists(filePath)) { Console.WriteLine("File is not Exist"); return(false); } else { if (!File.ReadAllText(filePath).Contains(teacherDetail.tId.ToString())) { Console.WriteLine("This ID is NOT exist, please enter a valid ID."); return(false); } else { DataTable table = new DataTable(); var fileContents = File.ReadAllLines(filePath); var splitFileContents = (from f in fileContents select f.Split(',')).ToArray(); StreamWriter OurStream; File.Delete(filePath); foreach (var line in splitFileContents) { if (!string.IsNullOrWhiteSpace(line[0])) { if (line[0] == teacherDetail.tId.ToString()) { line[1] = teacherDetail.tName; line[2] = teacherDetail.className; line[3] = teacherDetail.section.ToString(); } OurStream = File.AppendText(filePath); OurStream.WriteLine(line[0] + "," + line[1] + "," + line[2] + "," + line[3]); OurStream.Close(); } } Console.WriteLine("Records is updated successfully......."); return(false); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(returnVal); }
static void Main(string[] args) { StreamWriter OurStream; OurStream = File.CreateText("C:/Users/William/Desktop/Clone/CAB301/Assignment_2/Experimental Data Result/Median(Basic_Random).txt"); for (int size = 999; size <= 9999; size += 1000) { int[] randomArray = GenerateRandomArray(size); Median(randomArray); OurStream.WriteLine("Basic operation counter for input size " + size + " is " + counter); OurStream.WriteLine("\n"); } Console.WriteLine("Completed"); OurStream.Close(); Console.ReadKey(); }
static void Main(string[] args) { Stopwatch sw = new Stopwatch(); StreamWriter OurStream; OurStream = File.CreateText("C:/Users/William/Desktop/Clone/CAB301/Assignment_2/Experimental Data Result/BruteForceMedian(Random_Time).txt"); for (int size = 1000; size <= 10000; size += 1000) { int[] randomArray = GenerateRandomArray(size); sw.Reset(); sw.Start(); BruteForceMedian(randomArray); sw.Stop(); OurStream.WriteLine("The execution time for input size {0} is {1}", size, sw.Elapsed); } Console.WriteLine("Completed"); OurStream.Close(); Console.ReadKey(); }
/// <summary> /// Created this method to store the teacher’s details in text file. /// </summary> /// <param name="teacherDetail"></param> /// <returns></returns> public bool Store(TeacherDetail teacherDetail) { try { if (File.Exists(filePath)) { if (File.ReadAllText(filePath).Length > 0) { if (File.ReadAllText(filePath).Contains(teacherDetail.tId.ToString())) { Console.WriteLine("This ID is already exist, please enter a new ID."); } return(false); } else { StreamWriter OurStream; OurStream = File.AppendText(filePath); OurStream.WriteLine(teacherDetail.tId + "," + teacherDetail.tName + "," + teacherDetail.className + "," + teacherDetail.section); OurStream.Close(); Console.WriteLine("Record is stored successfully........"); return(true); } } else { FileCreation(); Store(teacherDetail); return(false); } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(true); }
static void Main(string[] args) { StreamWriter OurStream; OurStream = File.CreateText("C:/Users/William/Desktop/Clone/CAB301/Assignment_2/Experimental Data Result/BruteForceMedian(Basic).txt"); int[] sortedAllPos = { 1, 1, 1, 1, 1, 1, 1 }; int[] sortedAllNeg = { -1, -1, -1, -1, -1, -1, -1 }; int[] sorted = { 1, 2, 3, 4, 5, 6, 7 }; int[] decending = { 7, 6, 5, 4, 3, 2, 1 }; int[] singleValue = { 5 }; int[] emptyValue = { }; int[] testOne = { -10, 0, 10 }; int[] testTwo = { -100, 1, 2, 3, 100 }; int[] testThree = { 7, 3, 2, 6, 5, 4, 1 }; int[] evenArray = { 1, 2, 3, 4 }; int[] a = { 4, 1, 10, 9, 7, 12, 8, 2, 15 }; BruteForceMedian(sortedAllPos); OurStream.WriteLine("The Basic Operation for [{0}] is equal to {1}", string.Join(", ", sortedAllPos), counter); BruteForceMedian(sortedAllNeg); OurStream.WriteLine("The Basic Operation for [{0}] is equal to {1}", string.Join(", ", sortedAllNeg), counter); BruteForceMedian(sorted); OurStream.WriteLine("The Basic Operation for [{0}] is equal to {1}", string.Join(", ", sorted), counter); BruteForceMedian(decending); OurStream.WriteLine("The Basic Operation for [{0}] is equal to {1}", string.Join(", ", decending), counter); BruteForceMedian(singleValue); OurStream.WriteLine("The Basic Operation for [{0}] is equal to {1}", string.Join(", ", singleValue), counter); BruteForceMedian(emptyValue); OurStream.WriteLine("The Basic Operation for [{0}] is equal to {1}", string.Join(", ", emptyValue), counter); BruteForceMedian(testOne); OurStream.WriteLine("The Basic Operation for [{0}] is equal to {1}", string.Join(", ", testOne), counter); BruteForceMedian(testTwo); OurStream.WriteLine("The Basic Operation for [{0}] is equal to {1}", string.Join(", ", testTwo), counter); BruteForceMedian(testThree); OurStream.WriteLine("The Basic Operation for [{0}] is equal to {1}", string.Join(", ", testThree), counter); BruteForceMedian(evenArray); OurStream.WriteLine("The Basic Operation for [{0}] is equal to {1}", string.Join(", ", evenArray), counter); BruteForceMedian(a); OurStream.WriteLine("The Basic Operation for [{0}] is equal to {1}", string.Join(", ", a), counter); Console.WriteLine("Completed"); OurStream.Close(); Console.ReadKey(); }
static void Main(string[] args) { string filePath = GetFilePath(); var lineCount = File.ReadLines(filePath).Count(); if (lineCount <= 1) { Console.WriteLine("You must include multiple lines in your txt document."); Environment.Exit(-1); } else { List <Customer> customers = new List <Customer>(); List <string> lines = File.ReadAllLines(filePath).ToList(); Console.WriteLine(); foreach (var line in lines) { string[] entries = line.Split(','); Customer newCustomer = new Customer(); newCustomer.FirstName = entries[0]; newCustomer.LastName = entries[1]; newCustomer.Id = entries[2]; newCustomer.MobileNumber = entries[3]; newCustomer.Email = entries[4]; customers.Add(newCustomer); } foreach (var customer in customers) { Console.WriteLine($"{customer.FirstName} {customer.LastName} {customer.Id} {customer.MobileNumber} {customer.Email}"); } foreach (var customer in customers) { string propAnswer = GetPropAnswer(); if (propAnswer == "yes") { string propOrder = GetPropertyOrder(); switch (propOrder) { case "LastName": Console.WriteLine($"{customer.LastName} {customer.FirstName} {customer.Id} {customer.MobileNumber} {customer.Email}"); break; case "Id": Console.WriteLine($"{customer.Id} {customer.FirstName} {customer.LastName} {customer.MobileNumber} {customer.Email}"); break; case "MobileNumber": Console.WriteLine($"{customer.MobileNumber} {customer.FirstName} {customer.LastName} {customer.Id} {customer.Email}"); break; case "Email": Console.WriteLine($"{customer.Email} {customer.FirstName} {customer.LastName} {customer.Id} {customer.MobileNumber}"); break; } break; } break; } string answer = GetAnswer(); if (answer == "yes") { string newFilePath = GetNewFilePath(); StreamWriter OurStream; OurStream = File.CreateText(newFilePath); OurStream.WriteLine(); OurStream.Close(); Console.WriteLine("File created!"); } else { Console.WriteLine("The end of the program"); } Console.ReadLine(); } }