BSc.IT. 3 rd Sem
Object Oriented Programming (304) Assignment-III
- 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. - 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. - Design Employee Management System.
a) Design appropriate classes and make use of inheritance.
b) Make use of constructors to initialize the members. - 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();
}
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;
};
class salary:public cmp,public emp
{
protected:
public:
void display()
{
putid();
putinfo();
};
int main()
{
salary emp1;
}
/*
- 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
{
}
void create()
{
int x=0;
}
void display()
{
temp=first;
while(temp!=NULL)
{
printf("linked list elements %d \n",tempdata);
temp=tempnext;
}
}
void insert_first()
{
printf("enter the value:");
scanf("%d",&x);
nn=(struct node*)malloc(sizeof(nn));
nndata=x;
nnnext=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;
nnnext=NULL;
prev=NULL;
cur=first;
while(count<pos)
{
prev=cur;
cur=curnext;
count++;
}
prevnext=nn;
nn->next=cur;
}
void insert_last()
{
printf("enter the value:");
scanf("%d",&x);
nn=(struct node*)malloc(sizeof (nn));
nndata=x;
nnnext=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=firstnext;
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",curdata);
if(cur==last)
{
free(last);
last=prev;
lastnext=NULL;
}
else
{
prevnext=cur->next;
free(cur);
}
}
void delete_last()
{
if(first==NULL)
{
printf("list is empty!!!");
}
else
{
printf("delete element is %d",lastdata);
temp=first;
while(tempnext !=last)
{
temp=tempnext;
}
free(last);
last=temp;
lastnext=NULL;
}
}
include<stdio.h>
include<stdlib.h>
struct node{
}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);
}
void display()
{
temp=first;
}
void insert_first()
{
printf("\n enter value :");
scanf("%d",&x);
nn=(struct node *)malloc(sizeof(nn));
nndata=x;
nnnext=first;
first=nn;
}
void insert_middle()
{
}
void insert_last()
{
printf("\n enter value :");
scanf("%d",&x);
nn=(struct node *)malloc(sizeof(nn));
nndata=x;
nnnext=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=firstnext;
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;
nnnext=NULL;
}
void delete_last()
{
}
int main()
{
}
/*
- dll.c
* - Created on: 07-Sep-2022
- Author: root
*/
include<stdio.h>
include<stdlib.h>
struct node{
}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);
}
void display()
{
temp=first;
}
void display_2()
{
temp=last;
}
void insert_first()
{
printf("\n enter value :");
scanf("%d",&x);
nn=(struct node *)malloc(sizeof(nn));
nndata=x;
nnright=first;
first->left=nn;
first=nn;
}
void insert_middle()
{
}
void insert_last()
{
printf("\n enter value :");
scanf("%d",&x);
nn=(struct node *)malloc(sizeof(nn));
nndata=x;
lastright=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=firstright;
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;
nnright=NULL;
nn->left=NULL;
}
void delete_last()
{
}
int main()
{
}
STUDENT LINKLIST
include<stdio.h>
include<string.h>
include<stdlib.h>
struct student{
}first=NULL,last=NULL,nn=NULL,cur=NULL,pre=NULL,temp=NULL;
int i;
int r,m;
char n[10],d[20];
void create()
{
}
void search()
{
temp=first;
}
void display()
{
}
void delete()
{
int count;
printf("\n enter position you want to delete roll no:");
scanf("%d",&r);
count=1;
}
int main()
{
int ch;
}
merge:
/*
- merge.c
* - Created on: 20-Sep-2022
- Author: root
*/
include<stdio.h>
include<string.h>
include<stdlib.h>
struct n1{
}first=NULL,last=NULL,nn,temp=NULL;
struct n2{
}f=NULL,l=NULL,nn1,temp1=NULL;
struct n3{
int data3;
struct n3 next;
}f3=NULL,l3=NULL,nn3,*temp3=NULL;
struct n4{
}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);
}
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);
}
void display1()
{
}
void display2()
{
}
void merge()
{
lastnext=f;
temp=first;
while(temp!=NULL)
{
printf("\n value: %d",tempdata);
printf("\n name : %s",temp->name);
}
void divide()
{
temp=first;
while(temp!=NULL)
{
nn3=(struct n3 )malloc(sizeof(nn3));
nn3data3=tempdata;
nn4=(struct n4 )malloc(sizeof(nn4));
strcpy(nn4name4,tempname);
}
void display3()
{
}
void display4()
{
}
void sum()
{
}
int main()
{
int ch;
}
polinomial:
include<stdio.h>
include<stdlib.h>
struct node{
}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);
}
void display()
{
temp=first;
}
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])
{
}
printf("\n stack:%d",stack[top]);
return 0;
}