Question
6.2 Download and study program P1-2. Modify program P1-2 so that the array is of Employee type. The class Employee is given blow: class Employee
6.2 Download and study program P1-2.
Modify program P1-2 so that the array is of Employee type. The class Employee is given blow:
class Employee
{ public int EmpID; public string name, ssn; public double salary;
public void InputEmployee()
{
Console.Write(" ID: ");
EmpID = int.Parse(Console.ReadLine()); Console.Write("Name: "); name = Console.ReadLine(); Console.Write("SSN: "); ssn = Console.ReadLine(); Console.Write("Salary: $");
salary = double.Parse(Console.ReadLine());
}
public override String ToString()
{
return String.Format("ID: {0,-6} Name: {1,-10} SSN: {2,-14}Salary: {3,-10}", EmpID, name, ssn, salary);
}}
Add a testing class that can test all the operations defined in the Sorted_Array class. The given array capacity is 100. You could modify it to any size.
Make your testing menu-driven.
This is P1-2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace OrderedArray { class Sorted_Array { public int currSize; public int[] a; public int CAPACITY; public Sorted_Array() { CAPACITY = 100; //default capacity 100 a = new int[CAPACITY]; currSize = 0; } public Sorted_Array(int cap) { CAPACITY = cap; a = new int[CAPACITY]; currSize = 0; } public void Insert(int item) { if (currSize > CAPACITY) { Console.Write("Array is full! "); return; } int j = currSize; while (j > 0 && a[j - 1] >= item) { a[j] = a[j - 1]; --j; } a[j] = item; currSize++; } public void Remove() { if (currSize == 0) { Console.WriteLine("Array is already empty!"); return; } currSize--; } public void Delete(int d) { if (currSize == 0) { Console.WriteLine("Array is empty! "); return; } int pos = -1; pos = BinarySearch(d); if (pos == -1) { Console.WriteLine("The number does not exist. "); return; } for (int i = pos; i < currSize-1; i++) a[i] = a[i + 1]; currSize--; if (currSize == 0) Console.Write("Array is empty! "); } public int BinarySearch(int key) { int mid, lowerBound = 0, upperBound = currSize - 1; while (true) { mid = (lowerBound + upperBound) / 2; if (a[mid] == key) return mid; // found it else if (lowerBound > upperBound) return -1; // cant find it else // divide range { if (a[mid] < key) lowerBound = mid + 1; // its in upper half else upperBound = mid - 1; // its in lower half } // end else divide range } // end while } public void OutputArray() { for (int i = 0; i < currSize; i++) Console.Write("{0} ", a[i]); Console.WriteLine(); } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started