Question: Modify Astack class so that the program can process stack of class objects. The definition of the class Student is provided as below: Here is
Modify Astack class so that the program can process stack of class objects. The definition of the class Student is provided as below:

Here is AStack
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Stack
{
class AStack
{
int[] arr;
int top;
int size;
public AStack(int Size)
{
arr = new int[Size];
size = Size;
top = -1;
}
public bool Empty()
{
if (top == -1)
return true;
else
return false;
}
public bool Full()
{
if (top == size - 1)
return true;
else
return false;
}
public void Push(int x)
{
if (!Full())
{
top = top + 1;
arr[top] = x;
}
else
Console.WriteLine("The stack is full!\a ");
}
public int Pop()
{
if (!Empty())
{
int x = arr[top];
top = top - 1;
return x;
}
else
{
Console.WriteLine("The stack is empty!\a ");
return -1;
}
}
public void Print()
{
if (top == -1)
Console.WriteLine("The stack is empty!");
else
for (int i = top; i >= 0; i--)
Console.WriteLine(arr[i]);
}
}
class Program
{
static void Main(string[] args)
{
int num, flag, p;
AStack arrStack = new AStack(11);
Random rnd = new Random(100);
for (int i = 0; i
{
num = rnd.Next(1, 100);
arrStack.Push(num);
}
Console.WriteLine("Here is the current content of the statck: ");
arrStack.Print();
Console.WriteLine(" Enter 1 to pop, 2 to push, 3 to exit");
flag = int.Parse(Console.ReadLine());
while (flag != 3)
{
if (flag == 1)
{
p = arrStack.Pop();
Console.WriteLine(" The item poped out is: {0}", p);
Console.WriteLine(" The items in the Stack after poping are:");
arrStack.Print();
}
else
{
if (flag == 2)
{
Console.WriteLine("Enter an integer to push it into the Stack:");
p = int.Parse(Console.ReadLine());
arrStack.Push(p);
Console.WriteLine("The items in the Stack after pushing are:");
arrStack.Print();
}
}
Console.WriteLine("Enter 1 to pop, 2 to push, 3 to exit");
flag = int.Parse(Console.ReadLine());
}
}
}
}
class Student private String name; private int id; private int grade; public int ID get t return id; set { id = value; } public void Input() Console.Write("Enter name:"); name = Console.ReadLine(); Console.Write("Enter ID: "); id = int.Parse(Console.ReadLine()); Console.Write("Enter Grade: "); grade = int.Parse(Console.ReadLine()); public override string Tostring() return string. Format ("Name: e, ID: (1), Grade: (2)", name, id, grade); The following is a test running output
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
