Answer to Question #213992 in C++ for zohaib

Question #213992

Create a class template for a class named GeneralStack that holds (3)

 A single data member as an array named stack of size 50 to store certain elements 

 Three member functions i.e. push(type) to add elements in the Stack, pop() to remove elements from the 

stack, and currentStatus() to check whether the array is filled or not. (A filled array is an array that has non￾zero value at all of its indexes). 

In the main() function, create three objects with different data types of class GeneralStack and test the 

functionality of member functions for various values of data members for these objects.


1
Expert's answer
2021-07-06T00:32:25-0400
#include <iostream>
#include <iomanip>
using namespace std;




class GeneralStack
{
	public:
		unsigned int DataMember[50];
		void PushStack(unsigned int *a)
		{
			int n;
			for(n=0;n<50;n++) DataMember[n]=*(a+n);
		}
		
		void PopStack(int n)
		{
			int i;
			for(i=0;i<n;i++) if(DataMember[i]==n) DataMember[i]=0;
		}
	
		int CurrentStatus(void)
		{
			int Flag=0;
			if(DataMember::empty()) Flag=1;
			return(Flag);
		}
};


main(void)
{
	class GeneralStack GS1,GS2,GS3;//3-objects
	unsigned int Arr[50],u;
	
	for(u=0;u<50;u++) Arr[u]=u;
	GS1.PushStack(&Arr[0]);
	
	for(u=0;u<50;u++) Arr[u]=u*10;
	GS2.PushStack(&Arr[0]);


	for(u=0;u<50;u++) Arr[u]=u*100;
	GS3.PushStack(&Arr[0]);
	
	return(0);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS