News:

Choose a design and let our professionals help you build a successful website   - ITAcumens

Main Menu

Implementing Method stack Function - Working C Code

Started by Kalyan, Nov 06, 2008, 10:55 AM

Previous topic - Next topic

Kalyan

Implementing Method stack Function

#include
#include
#include
#include
class methodobjects
{
private:int arg1,arg2;
int localvariable;
char returntype[5];
char methodname[6];
public:

methodobjects(){}
methodobjects(int a1,int a2,int lv, char *mn, char *rt)
{
arg1=a1; arg2=a2; localvariable=lv; strcpy(returntype,rt); strcpy(methodname,mn);}

void display()
{
cout<<"methodname="<<
cout<<"returntype="<<
cout<<"arg1="<<<"\t"<<"arg2="<<<"\t"<<"localvariable="<<
}

};

methodobjects s[4];
int top=0;

void push(methodobjects m)
{

s[top++]=m;

}

methodobjects pop()
{
return(s[--top]);
}

int add(int x,int y)
{
int result;
result=x+y;
cout<<"inside the add method"<
return result;
}


void main()
{

clrscr();
char ch;
int x,y;

methodobjects main1(0,0,3,"main","void"),tmp;

cout<<"pushing the main function into the stack"<

push(main1);

cout<<"inside the main function"<

cout<<"do u want to call the next function?"<

cin>>ch;

if(ch=='y')

{
cout<<"give two numbers to add"<
cin>>x>>y;

methodobjects add1(x,y,1,"add","int");

cout<<"pushin add function into the stack"<

push(add1);
x=add(x,y);

cout<<"end of the add method"<

cout<<"popping oout add"<
tmp=pop();


tmp.display();
cout<<"the sum is"<<

}


cout<<"end of the program"<
cout<<"popping out main"<

tmp=pop();

tmp.display();

getch();

}