BSc.IT. 3 rd Sem
Object Oriented Programming (304) Assignment-III

  1. Design a class called "Vehicle" which contains appropriate data members. Design
    a class "two-Wheeler" from vehicle which contains data member’s distance and
    mileage. Use overloading techniques. Assume further classes for inheritance and
    demonstrate the use of Multi-level inheritance for the above problem.
  2. Design a base class Patient and IPD(ward_no, bed_no, charge_per_day).Derive a
    class IPD-Patient from these two base classes with no_of_days admitted.
  3. Design Employee Management System.
    a) Design appropriate classes and make use of inheritance.
    b) Make use of constructors to initialize the members.
  4. Design billing system for Super Market.
    a) Design appropriate classes and make use of inheritance.
    b) Make use of constructors to initialize the members.

include<iostream>

using namespace std;
class Patient //Base Class
{
char patient_name[100];
int age;
char sex[50];
public:
void accept_patient_details()
{
cout<<"\n -------------------------------";
cout<<"\n Enter Patient Details";
cout<<"\n -------------------------------";
cout<<"\n Patient Name : ";
cin>>patient_name;
cout<<"\n Patient Age : ";
cin>>age;
cout<<"\n Sex : ";
cin>>sex;
}
void display_patient_details()
{
cout<<"\n -------------------------------";
cout<<"\n Displaying Patient Details";
cout<<"\n -------------------------------";
cout<<"\n Patient Name : "<<patient_name;
cout<<"\n Patient Age : "<<age;
cout<<"\n Sex : "<<sex;
}
};
class IPD //Base Class
{
int ward_no;
int bed_no;
int charge_per_day;
public:
void accept_ipd_details()
{
cout<<"\n -------------------------------";
cout<<"\n Enter IPD Details ";
cout<<"\n -------------------------------";
cout<<"\n Ward No. : ";
cin>>ward_no;
cout<<"\n Bed No. : ";
cin>>bed_no;
cout<<"\n Charge Per Day : ";
cin>>charge_per_day;
}
void display_ipd_details()
{
cout<<"\n -------------------------------";
cout<<"\n Displaying IPD Details";
cout<<"\n -------------------------------";
cout<<"\n Ward No. : "<<ward_no;
cout<<"\n Bed No. : "<<bed_no;
cout<<"\n Charge Per Day : "<<charge_per_day;
}
};
//Class IPDPatient is derived from Class IPD and Class Patient
class IPDPatient : public IPD, public Patient
{
int no_of_days_admitted;
public:
void accept_ipd_patient_details()
{
accept_patient_details();
accept_ipd_details();
cout<<"\n\n Enter No. of Days Admitted : ";
cin>>no_of_days_admitted;
}
void display_ipd_patient_details()
{
display_patient_details();
display_ipd_details();
cout<<"\n -------------------------------";
cout<<"\n\n No. of Days Admitted : "<<no_of_days_admitted;
}
};
int main()
{
IPDPatient *ipdt; // Object ipdt is created of class IPDPatient <-- Child Class
int i,cnt;
cout<<"\n Enter No. of Patient Details You Want : ";
cin>>cnt;
ipdt=new IPDPatient[cnt];
for(i=0;i<cnt;i++)
{
ipdt[i].accept_ipd_patient_details();
ipdt[i].display_ipd_patient_details();
}
return 0;
}

include <iostream>

using namespace std;

class vehicle{
protected:
int rating;
public:
void getno(int a)
{
rating=a;
}
void putno()
{
cout<<"\n vehicle number= "<<rating<<endl;
}

};

class twowheeler :public vehicle{
protected:
float distance;
float mileage;
public:
void getinfo(float x, float y)
{
distance=x;//distance is consider as speed of that vehicle.
mileage=y;
}
void putinfo()
{
cout<<"\n speed of vehicle= "<<distance<<endl;
cout<<"\n mileage= "<<mileage<<endl;
}

};
class show_room:public twowheeler
{
float rating;
public:
void display()
{
putno();
putinfo();
}

};
int main()
{
show_room car1;
car1.getno(1779);
car1.getinfo(26,60);
car1.display();

⎗
✓
return 0;

}

include<iostream>

using namespace std;

//multiple inheritance
//base class= emp cmp derive class=salary

class emp{

protected:
int empid;
char empname[40];
float bs;
float bonus=20000;
public:
void getid()
{
cout<<"\n employee id=";
cin>>empid;
cout<<"\n employee name=";
cin>>empname;
cout<<"\n basic salary=";
cin>>bs;
}
void putid()
{

⎗
✓
}

};

class cmp
{

protected:
char cmpname[25];
char branch[25];
public:
void getinfo()
{
cout<<"\n company name =";
cin>>cmpname;
cout<<"\n branch =";
cin>>branch;

⎗
✓
1
2
3
4
5
}
void putinfo()
{

}

};

class salary:public cmp,public emp
{
protected:

⎗
✓
float total;

public:
void display()
{
putid();
putinfo();

⎗
✓
1
2
3
4
5
6
    total=bs+bonus;

    cout<<"\n ~~~EMPLOYEE DETAIL~~~\n ";
    cout<<" "<<"cmp_name"<<" "<<"branch"<<" "<<"empid"<<" "<<"emp_name"<<" "<<"salary"<<" "<<endl;
    cout<<"  "<<cmpname<<"  "<<branch<<"  "<<empid<<"  "<<empname<<"  "<<total<<endl;
}

};

int main()
{
salary emp1;

⎗
✓
int n;
cout<<"how many number of employee detail you want to insert=";
cin>>n;

for(int i=0;i<n;i++)
{
emp1.getid();
emp1.getinfo();

}
for(int i=0;i<n;i++)
{

emp1.display();
}


return 0;

}

/*

  • linkdlist.c
    *
  • Created on: 05-Sep-2022
  • Author: root
    */

include<stdio.h>

include<stdlib.h>

struct node
{
int data;
struct node next;
}
first=NULL,last=NULL,nn=NULL,temp,cur,prev,nn;
int ch,x;

void main()
{
create();
do
{

⎗
✓
    printf("\n1.insert at first");
    printf("\n2.insert at middle");
    printf("\n3.insert at last");
    printf("\n4.delete from first");
    printf("\n5.delete from middle");
    printf("\n6.delete from last");
    printf("\n7.display");
    printf("\n8.exit");
    scanf("%d",&ch);
    switch(ch)
    {
    case 1:
        insert_first();
        break;

    case 2:
        insert_middle();
        break;

    case 3:
        insert_last();
        break;

    case 4:
        delete_first();
        break;

    case 5:
        delete_middle();
        break;

    case 6:
        delete_last();
        break;

    case 7:
        display();
        break;

    case 8:
        printf("\nThanks for using program");
        exit(0);
        break;
    }

}while(ch!=8);

}

void create()
{
int x=0;

⎗
✓
printf("enter the value(-1 for and): ");
scanf("%d",&x);
while(x!=-1)
{
    nn=(struct node*)malloc(sizeof (nn));
    nn->data=x;
    nn->next=NULL;
    if(first==NULL)
    {
        first=nn;
        last=nn;
    }
    else
    {
        last->next=nn;
        last=nn;
    }
    printf("enter the value(-1 for end):");
    scanf("%d",&x);
}

}

void display()
{
temp=first;
while(temp!=NULL)
{
printf("linked list elements %d \n",tempdata);
temp=temp
next; }

}

void insert_first()
{
printf("enter the value:");
scanf("%d",&x);
nn=(struct node*)malloc(sizeof(nn));
nndata=x;
nn
next=NULL; first=nn;
}

void insert_middle()
{
int count,pos;
printf("enter the position");
scanf("%d",&pos);
count=1;
printf("enter the value:");
scanf("%d",&x);
nn=(struct node*)malloc(sizeof (nn));
nndata=x;
nn
next=NULL; prev=NULL;
cur=first;
while(count<pos)
{
prev=cur;
cur=curnext;
count++;
}
prev
next=nn; nn->next=cur;
}

void insert_last()
{
printf("enter the value:");
scanf("%d",&x);
nn=(struct node*)malloc(sizeof (nn));
nndata=x;
nn
next=NULL; last->next=nn;
last=nn;
}

void delete_first()
{
if(first==NULL)
{
printf("list is empty!!!");
}
else
{
printf("delete element is %d",firstdata);
temp=first;
first=first
next; free(temp);
}
}

void delete_middle()
{
int count,pos;
printf("enter the position");
scanf("%d",&pos);
count=1;
prev=NULL;
cur=first;
while(count<pos)
{
prev=cur;
cur=curnext;
count++;
}
printf("delete element is %d",cur
data); if(cur==last)
{
free(last);
last=prev;
lastnext=NULL;
}
else
{
prev
next=cur->next; free(cur);
}
}

void delete_last()
{
if(first==NULL)
{
printf("list is empty!!!");
}
else
{
printf("delete element is %d",lastdata);
temp=first;
while(temp
next !=last) {
temp=tempnext;
}
free(last);
last=temp;
last
next=NULL; }
}

include<stdio.h>

include<stdlib.h>

struct node{

⎗
✓
int data;
struct node *next;

}first=NULL,last=NULL,nn,cur=NULL,pre=NULL,temp;

int x,ch;

void create()
{
int x=0;
printf("\n enter value (-1 for end):");
scanf("%d",&x);

⎗
✓
while(x!=-1)
{
    nn=(struct node *)malloc(sizeof(nn));
    nn->data=x;
    nn->next=NULL;

    if(first==NULL)
    {
        first=nn;
        last=nn;
    }
    else
    {
        last->next=nn;
        last=nn;
    }

    printf("\n enter value (-1 for end):");
    scanf("%d",&x);


}

}

void display()
{
temp=first;

⎗
✓
1
2
3
4
5
while(temp!=NULL)
{
   printf("\n display elements %d",temp->data);
   temp=temp->next;
}

}

void insert_first()
{
printf("\n enter value :");
scanf("%d",&x);
nn=(struct node *)malloc(sizeof(nn));
nndata=x;
nn
next=first; first=nn;

}
void insert_middle()
{

⎗
✓
 int count,pos;
 printf("\n enter position:");
 scanf("%d",&pos);
 count=1;
 printf("\n enter value :");
 scanf("%d",&x);
 nn=(struct node *)malloc(sizeof(nn));
 nn->data=x;
 nn->next=NULL;

pre=NULL;
cur=first;

while(count<pos)
{
    pre=cur;
    cur=cur->next;
    count++;
}

pre->next=nn;
nn->next=cur;

}

void insert_last()
{
printf("\n enter value :");
scanf("%d",&x);
nn=(struct node *)malloc(sizeof(nn));
nndata=x;
nn
next=NULL; last->next=nn;
last=nn;

}

void delete_first()
{
if(first==NULL)
{
printf("\n linked lisr is empty:");
}
else
{
printf(" delete elements %d",firstdata);
temp=first;
first=first
next; free(temp);

⎗
✓
}

}

void delete_middle()
{
int count,pos;
printf("\n enter position:");
scanf("%d",&pos);
count=1;
nn=(struct node *)malloc(sizeof(nn));
nndata=x;
nn
next=NULL;

⎗
✓
pre=NULL;
cur=first;

while(count<pos)
{
    pre=cur;
    cur=cur->next;
    count++;
 }


if(cur==last)
{
    free(last);
    last=pre;
    last->next=NULL;


}
else
{
    printf("\n display elements:%d",cur->data);
    pre->next=cur->next;
    free(cur);
}

}

void delete_last()
{

⎗
✓
if(first==NULL)
{
    printf("\n linked lisT is empty:");
}
else
{
    printf(" delete elements %d",last->data);
    temp=first;
    while(temp->next!=last)
    {
        temp=temp->next;
    }
    free(last);
    last=temp;
    last->next=NULL;

}

}

int main()
{

⎗
✓
create();
do{

    printf("\n**********");
    printf("\n click 1:insert first:");
    printf("\n click 2:insert middle:");
    printf("\n click 3:insert last:");
    printf("\n click 4:delete first:");
    printf("\n click 5:delete middle:");
    printf("\n click 6:delete last:");
    printf("\n click 7:display:");



    printf("\n enter choice:");
    scanf("%d",&ch);


    switch(ch)
    {


    case 1:
         insert_first();
         break;

    case 2:
        insert_middle();
        break;

    case 3:
        insert_last();
        break;


    case 4:
        delete_first();
        break;

  case 5:
        delete_middle();
        break;

    case 6:
        delete_last();
        break;

    case 7:
        display();
        break;



    }

}while(ch!=8);

}

/*

  • dll.c
    *
  • Created on: 07-Sep-2022
  • Author: root
    */

include<stdio.h>

include<stdlib.h>

struct node{

⎗
✓
1
2
3
int data;
struct node *right;
struct node *left;

}first=NULL,last=NULL,nn,cur=NULL,pre=NULL,temp;

int x,ch;

void create()
{
int x=0;
printf("\n enter value (-1 for end):");
scanf("%d",&x);

⎗
✓
while(x!=-1)
{
    nn=(struct node *)malloc(sizeof(nn));
    nn->data=x;
    nn->right=NULL;
    nn->left=NULL;

    if(first==NULL)
    {
        first=nn;
        last=nn;
    }
    else
    {
        last->right=nn;
        nn->left=last;
        last=nn;
    }

    printf("\n enter value (-1 for end):");
    scanf("%d",&x);


}

}

void display()
{
temp=first;

⎗
✓
1
2
3
4
5
while(temp!=NULL)
{
   printf("\n display elements %d",temp->data);
   temp=temp->right;
}

}

void display_2()
{
temp=last;

⎗
✓
1
2
3
4
5
while(temp!=NULL)
{
   printf("\n display elements %d",temp->data);
   temp=temp->left;
}

}

void insert_first()
{
printf("\n enter value :");
scanf("%d",&x);
nn=(struct node *)malloc(sizeof(nn));
nndata=x;
nn
right=first; first->left=nn;
first=nn;

}
void insert_middle()
{

⎗
✓
 int count,pos;
 printf("\n enter position:");
 scanf("%d",&pos);
 count=1;
 printf("\n enter value :");
 scanf("%d",&x);
 nn=(struct node *)malloc(sizeof(nn));
 nn->data=x;
 nn->right=NULL;
 nn->left=NULL;

pre=NULL;
cur=first;

while(count<pos)
{
    pre=cur;
    cur=cur->right;
    count++;
}

pre->right=nn;
nn->left=pre;
nn->right=cur;
cur->left=nn;

}

void insert_last()
{
printf("\n enter value :");
scanf("%d",&x);
nn=(struct node *)malloc(sizeof(nn));
nndata=x;
last
right=nn; nn->left=last;
last=nn;

}

void delete_first()
{
if(first==NULL)
{
printf("\n linked lisr is empty:");
}
else
{
printf(" delete elements %d",firstdata);
temp=first;
first=first
right; first->left=NULL;
free(temp);

⎗
✓
}

}

void delete_middle()
{
int count,pos;
printf("\n enter position:");
scanf("%d",&pos);
count=1;
nn=(struct node *)malloc(sizeof(nn));
nndata=x;
nn
right=NULL; nn->left=NULL;

⎗
✓
pre=NULL;
cur=first;

while(count<pos)
{
    pre=cur;
    cur=cur->right;
    count++;
 }
 cur->right->left=pre;
 pre->right=cur->right;
 free(cur);

}

void delete_last()
{

⎗
✓
if(first==NULL)
{
    printf("\n linked lisT is empty:");
}
else
{
    printf(" delete elements %d",last->data);
    last=last->left;
    free(last->right);
    last->right=NULL;

}

}

int main()
{

⎗
✓
create();
do{

    printf("\n**********");
    printf("\n click 1:insert first:");
    printf("\n click 2:insert middle:");
    printf("\n click 3:insert last:");
    printf("\n click 4:delete first:");
    printf("\n click 5:delete middle:");
    printf("\n click 6:delete last:");
    printf("\n click 7:display:");
    printf("\n click 8:display_2:");


    printf("\n enter choice:");
    scanf("%d",&ch);


    switch(ch)
    {


    case 1:
         insert_first();
         break;

    case 2:
        insert_middle();
        break;

    case 3:
        insert_last();
        break;


    case 4:
        delete_first();
        break;

  case 5:
        delete_middle();
        break;

    case 6:
        delete_last();
        break;

    case 7:
        display();
        break;

    case 8:
          display_2();
          break;



    }

}while(ch!=9);

}

STUDENT LINKLIST

include<stdio.h>

include<string.h>

include<stdlib.h>

struct student{

⎗
✓
1
2
3
4
5
int rno;
char name[10];
char div[10];
int mark;
struct student *next;

}first=NULL,last=NULL,nn=NULL,cur=NULL,pre=NULL,temp=NULL;
int i;

int r,m;
char n[10],d[20];

void create()
{

⎗
✓
printf("\n enter roll no:");
scanf("%d",&r);
printf("\n enter name:");
scanf("%s",n);
printf("\n enter division:");
scanf("%s",d);
printf("\n enter marks:");
scanf("%d",&m);


while(r!=0)
{
    nn=(struct student *)malloc(sizeof(struct student));
    nn->rno=r;
    strcpy(nn->name,n);
    strcpy(nn->div,d);
    nn->mark=m;

    nn->next=NULL;

    if(first==NULL)
    {
        first=nn;
        last=nn;
    }
    else
    {
        last->next=nn;
        last=nn;
    }



    printf("\n enter roll no:");
    scanf("%d",&r);
    printf("\n enter name:");
    scanf("%s",n);
    printf("\n enter division:");
    scanf("%s",d);
    printf("\n enter marks:");
    scanf("%d",&m);


}

}

void search()
{
temp=first;

⎗
✓
int max=first->mark;

while(temp!=NULL)
{
    if(max<temp->mark)
    {
        max=temp->mark;
    }
    temp=temp->next;
}
printf("\n heighest marks:%d",max);

}

void display()
{

⎗
✓
temp=first;
if(first==NULL && last==NULL)
{
    printf("\n data not found:");
}
else

{
    while(temp!=NULL)
    {
         printf("\n roll no: %d",temp->rno);
         printf("\n name : %s",temp->name);
         printf("\n division : %s",temp->div);
         printf("\n marks : %d",temp->mark);
        temp=temp->next;
    }

}

}

void delete()
{
int count;
printf("\n enter position you want to delete roll no:");
scanf("%d",&r);
count=1;

⎗
✓
pre=NULL;
cur=first;

while(count!=r)
{
    pre=cur;
    cur=cur->next;
    count++;
 }

if(r==first->rno)
{
   printf("delete:%d",first->rno);
   temp=first;
   first=first->next;
   free(temp);
}
else if(r==last->rno)
{
     printf("delete:%d",last->rno);
     temp=first;
     while(temp->next!=last)
     {
         temp=temp->next;
     }
     free(last);
     last=temp;
     last->next=NULL;

}
else
{
    printf("\n delete record:%d",cur->rno);
    pre->next=cur->next;
    free(cur);
}

}

int main()
{
int ch;

⎗
✓
create();
do{
    printf("\n**********");
    printf("\n click 1:display:");
    printf("\n click 2:search:");
    printf("\n click 3:delete:");
    printf("\n enter choice:");
    scanf("%d",&ch);


    switch(ch)
    {

      case 1:
         display();
         break;

      case 2:
          search();
          break;

      case 3:
      delete();
       break;

    }

}while(ch!=4);

}

merge:

/*

  • merge.c
    *
  • Created on: 20-Sep-2022
  • Author: root
    */

include<stdio.h>

include<string.h>

include<stdlib.h>

struct n1{

⎗
✓
1
2
3
int data;
char name[10];
struct n1 *next;

}first=NULL,last=NULL,nn,temp=NULL;

struct n2{

⎗
✓
1
2
3
int data1;
char name1[10];
struct n2 *next;

}f=NULL,l=NULL,nn1,temp1=NULL;

struct n3{
int data3;
struct n3 next;
}
f3=NULL,l3=NULL,nn3,*temp3=NULL;

struct n4{

⎗
✓
char name4[10];
struct n4 *next;

}f4=NULL,l4=NULL,nn4,temp4=NULL;

int x,y,ch,s=0;
char n[10];
char na1[10],na3[10],na4[10];

void create()
{
int x=0;
printf("\n enter value (-1 for end):");
scanf("%d",&x);
printf("\n enter name:");
scanf("%s",n);

⎗
✓
while(x!=-1)
{
    nn=(struct n1 *)malloc(sizeof(nn));
    nn->data=x;
    strcpy(nn->name,n);
    nn->next=NULL;

    if(first==NULL)
    {
        first=nn;
        last=nn;
    }
    else
    {
        last->next=nn;
        last=nn;
    }

    printf("\n enter value (-1 for end):");
    scanf("%d",&x);
    printf("\n enter name:");
    scanf("%s",n);


}

}

void create1()
{
printf("\n second linklist:");
int y=0;
printf("\n enter value (-1 for end):");
scanf("%d",&y);
printf("\n enter name:");
scanf("%s",na1);

⎗
✓
while(y!=-1)
{
    nn1=(struct n2 *)malloc(sizeof(nn1));
    nn1->data1=y;
    strcpy(nn1->name1,na1);
    nn1->next=NULL;

    if(f==NULL)
    {
        f=nn1;
        l=nn1;
    }
    else
    {
        l->next=nn1;
        l=nn1;
    }

    printf("\n enter value (-1 for end):");
    scanf("%d",&y);
    printf("\n enter name:");
    scanf("%s",na1);


}

}

void display1()
{

⎗
✓
temp=first;
if(first==NULL && last==NULL)
{
    printf("\n data not found:");
}
else

{
    while(temp!=NULL)
    {
         printf("\n value: %d",temp->data);
         printf("\n name : %s",temp->name);

        temp=temp->next;
    }

}

}

void display2()
{

⎗
✓
temp1=f;
if(f==NULL && l==NULL)
{
    printf("\n data not found:");
}
else

{
    while(temp1!=NULL)
    {
         printf("\n value: %d",temp1->data1);
         printf("\n name : %s",temp1->name1);

        temp1=temp1->next;
    }

}

}

void merge()
{
lastnext=f;
temp=first;
while(temp!=NULL)
{
printf("\n value: %d",temp
data); printf("\n name : %s",temp->name);

⎗
✓
    temp=temp->next;
}

}

void divide()
{
temp=first;
while(temp!=NULL)
{
nn3=(struct n3 )malloc(sizeof(nn3));
nn3data3=tempdata; nn4=(struct n4
)malloc(sizeof(nn4));
strcpy(nn4name4,tempname);

⎗
✓
    if((f3==NULL) && (f4==NULL) )
    {
        f3=nn3;
        l3=nn3;
        f4=nn4;
        l4=nn4;
    }
    else
    {
        l3->next=nn3;
        l3=nn3;
        l4->next=nn4;
        l4=nn4;
    }


     temp=temp->next;

}

}

void display3()
{

⎗
✓
temp3=f3;
if(f3==NULL && l3==NULL)
{
    printf("\n data not found:");
}
else

{
    while(temp3!=NULL)
    {
         printf("\n value: %d",temp3->data3);

        temp3=temp3->next;
    }

}

}

void display4()
{

⎗
✓
temp4=f4;
if(f4==NULL && l4==NULL)
{
    printf("\n data not found:");
}
else

{
    while(temp4!=NULL)
    {
         printf("\n name : %s",temp4->name4);

        temp4=temp4->next;
    }

}

}

void sum()
{

⎗
✓
temp3=f3;
if(f3==NULL && l3==NULL)
{
    printf("\n data not found:");
}
else

{
    while(temp3!=NULL)
    {
        s=s+temp3->data3;

         temp3=temp3->next;
    }
    printf("\n sum=%d",s);
}

}

int main()
{
int ch;

⎗
✓
do{
    printf("\n**********");
    printf("\n click 1:insert:");
    printf("\n click 2:display:");
    printf("\n click 3:merge:");
    printf("\n click 4:divide:");
    printf("\n click 5:sum:");
    printf("\n enter choice:");
    scanf("%d",&ch);


    switch(ch)
    {
       case 1:
           create();
           create1();
           break;


       case 2:
           display1();
           printf("\n second:");
           display2();
           break;


       case 3:
           merge();
           break;


       case 4:
           divide();
           printf("\n firsts:");
           display3();
           printf("\n second:");
           display4();
           break;

       case 5:
           sum();
           break;




    }

}while(ch!=6);

}

polinomial:

include<stdio.h>

include<stdlib.h>

struct node{

⎗
✓
1
2
3
int coeef;
int exp;
struct node *next;

}first=NULL,last=NULL,nn,cur=NULL,pre=NULL,temp;

int coeff=0,exp=0,ch;

void create()
{
int x=0;
printf("\n enter value (-1 for end):");
scanf("%d",&coeff);
printf("\n enter value (-1 for end):");
scanf("%d",&exp);

⎗
✓
while((exp!=-1) && (coeff!=-1))
{
    nn=(struct node *)malloc(sizeof(nn));
    nn->exp=exp;
    nn->coeef=coeff;
    nn->next=NULL;

    if(first==NULL)
    {
        first=nn;
        last=nn;
    }
    else
    {
        last->next=nn;
        last=nn;
    }


    printf("\n enter value (-1 for end):");
    scanf("%d",&coeff);
    printf("\n enter value (-1 for end):");
    scanf("%d",&exp);


}

}

void display()
{
temp=first;

⎗
✓
1
2
3
4
5
6
while(temp!=NULL)
{
   printf("\n  %d\t%d",temp->coeef,temp->exp);

   temp=temp->next;
}

}

int main()
{
create();
printf("\n display: ");
display();
return 0;
}
evalution:
/*

  • e_postfix.c
    *
  • Created on: 17-Aug-2022
  • Author: root
    */

include<stdio.h>

define N 30

int top=-1;
int stack[N];

void push(int a)
{
if(top>N)
{
printf("\n stack will be overfow");
}
else
{
stack[++top]=a;
}
}

int pop(void)
{
if(top==-1)
{
printf("\n stack will be underflow ");
return 0;
}
else
{
return stack[top--];
}
}

int main()
{
char postfix[N];
int a,b,c,i,value;

printf("\n enter postfix expression:");
scanf("%s",postfix);

i=0;

while(postfix[i]!='\0')
{
switch(postfix[i])
{

⎗
✓
 case '+':
    a=pop();
    b=pop();
    c=a+b;
    push(c);
    break;


 case '-':
        a=pop();
        b=pop();
        c=a-b;
        push(c);
        break;

 case '*':
        a=pop();
        b=pop();
        c=a*b;
        push(c);
        break;


 case '/':
        a=pop();
        b=pop();
        c=a/b;
        push(c);
        break;


 default:
     value=postfix[i]-48;
     push(value);
     printf("\n value=%d",value);
     break;


}
i++;

}

printf("\n stack:%d",stack[top]);
return 0;

}

Edit

Pub: 21 Aug 2022 13:31 UTC

Edit: 22 Sep 2022 09:26 UTC

Views: 211