































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
































To implement dynamic memory allocation, constructors, destructors, friend function, inheritance and interfaces.
1. String concatenation using dynamic memory allocation concept. 2. Implementation of arithmetic operations on complex numbers using constructor overloading.
function.
1. String concatenation using dynamic memory allocation concept
Aim To implement the string concatenation function by using dynamic memory allocation concept.
Objective To concatenate two or more strings into one string by allocating memory to objects at the time of their construction.
Exercises
Aim To implement arithmetic operations on complex numbers using constructor overloading
Objective To represent complex numbers and to perform arithmetic operations on complex numbers using overloaded constructors in a class.
4. Implementation of + and - operator overloading and implementation of addition operation of octal object with integer using operator overloading
Aim To implement + and ā operator overloading and to implement addition operation of octal object with integer using operator overloading.
Objective (A) To display the number of days between two valid dates and the date after a number of days from a valid date by overloading the operators + and -. (B)To represent octal numbers and to add an octal object with integer by overloading operator ā+ā.
Exercises (A)
5. Implementation of addition and subtraction of two polynomial objects using operator overloading
Aim To implement addition and subtraction operations of two polynomials and display using << operator overloading.
Objective To add and subtract two POLYNOMIAL objects and to display results by overloading the operator <<.
Exercises
Aim To manage the account information of the customer using inheritance concept.
Objective To maintain and update the customer account specific information using inheritance concept.
Exercises
Writing simple programs in Java
Aim To generate random numbers using simple Java program
Objective To generate random numbers using built in function random().
Exercises
Aim To calculate area of rectangle and circle using interfaces.
Objective To create two classes and store the values of distance and to read the values from one class and add with a value in another object using friend function
Exercises
To implement the string concatenation function by using dynamic memory allocation concept.
REQUIREMENTS: Hardware : Pentium IV PC Software : Turbo C++
PROGRAM: /*********************************************************************************************** Pr.No.1 Date: STRING CONCATENATION Name : Reg No. : Objective : To concatenate two or more strings into one string by allocating memory to objects at the time of their construction. ***********************************************************************************************/ #include<iostream.h> #include<string.h> #include<conio.h>
class string { char *name; int length; public: string() { length=0; name=new char[length+1];
name2.display(); name3.display(); s1.display(); s2.display(); getch(); }
OUTPUT: Object Oriented Programming Lab Object Oriented Object Oriented Programming Lab
To implement arithmetic operations on complex numbers using constructor overloading
REQUIREMENTS: Hardware : Pentium IV PC Software : Turbo C++
PROGRAM: /*********************************************************************************************** Pr.No.2 Date:
ARITHMETIC OPERATION ON COMPLEX NUMBERS Name : Reg.No. : Objective : To implement arithmetic operation on complex numbers using constructor over loading. ***********************************************************************************************/ #include<iostream.h> #include<math.h> #include<conio.h>
class complex { float x,y; public: complex(){} complex(float z) { x=y=z;
complex operator/ (complex c1,complex c2) { complex c3; float a; a=((c2.xc2.x)+(c2.yc2.y)); c3.x=((c1.xc2.x)+(c1.yc2.y))/a; c3.y=((c1.y/c2.x)-(c1.y*c2.y))/a; return c3; }
void show(complex c) { if(c.y<0) cout<<c.x<<"-j"<<fabs(c.y)<<endl; else cout<<c.x<<"+j"<<fabs(c.y)<<endl; }
void main() { complex A(1,2); complex B(3,1); complex C,D,E,F; clrscr(); C=A+B; D=A-B; E=A*B; F=A/B; cout<<"Complex No:1 = "; show(A); cout<<"Complex No:2 = "; show(B); cout<<"Sum = "; show(C); cout<<"Difference = ";
show(D); cout<<"Product = "; show(E); cout<<"Quotient = "; show(F); getch(); }
OUTPUT: Complex No:1 = 1+j Complex No:2 = 3+j Sum = 4+j Difference = -2+j Product = 1+j Quotient = 0.5-j0.
cout<<"Enter the first distance(in feet):"; cin>>d; } friend void add(AB,AC); };
class AC { float d; public: AC() { cout<<"Enter the second distance(in inches):"; cin>>d; }
friend void add(AB a,AC b) { float total; b.d=b.d/12; total=a.d+b.d; cout<<"Total Distance:"<<total<<"feet"; } }; void main() { clrscr(); AB A; AC B; add(A,B); getch(); }
Enter the first distance(in feet): Enter the second distance(in inches): Total Distance:14.5feet
To implement + and ā operator overloading and to implement addition operation of octal object with integer using operator overloading.
REQUIREMENTS: Hardware : Pentium IV PC Software : Turbo C++
PROGRAM: /************************************************************************************************ Pr.No.4A Date: IMPLEMENTATION OF OPERATOR OVERLOADING Name : Reg.No. : Objective : To display the number of days between two valid dates and to display the date after a number of days from a valid date by overloading the operator '+' and '-'. ***********************************************************************************************/ #include<iostream.h> #include<conio.h> class date { int day,date,month,year; public:
if(month==2&&isleapyear()) return 29; else return m[month-1]; } void operator+() { ++day; if(day>thismonthmax()) { day=1; month++; } if(month>12) { month=1; year++; } }
void operator-() { int i,d1,d2,dd,m1,m2,md,ms=0,y1,y2,yd,ys,tdays; cout<<"Enter date 1:"; cin>>d1>>m1>>y1; cout<<"Enter date 2:"; cin>>d2>>m2>>y2; int m[12]={31,28,31,30,31,30,31,31,30,31,30,31}; if(y2<y1) { cout<<"Invalid date"; } else { yd=y2-y1;
if(m2<m1) { m1=m1+12; y1--; md=m2-m1; } else { md=m2-m1; } if(d2<d1) { d1=d1+m[m1-1]; m1--; dd=d2-d1; } else { dd=d2-d1; } for(i=m1;i<m2;i++) { ms=ms+m[i]; } if((y2%400==0)||(y2%100!=0)&&(y2%1==0)) { ys=366yd; } else ys=365yd; tdays=dd+ms+ys; cout<<"DIFFERENCE="<<tdays; } };