Application of Residue Theorem to evaluate real integrations.pptx
A.P.S.E PRACTICAL FILE, NIT KURUKSHETRA
1. Program 3: Write a program to overload+ and * operators to add and multiplytwo complex
numbers.
#include<iostream.h>
#include<conio.h>
class comp
{
floatr,i;
public:
comp(){}
comp(floatd,floate)
{
r=d; i=e;
}
comp operator+(comp b)
{
comp temp;
temp.r=r+b.r;
temp.i=i+b.i;
returntemp;
}
comp operator*(comp b)
{
comp temp;
temp.r=r*b.r-i*b.i;
temp.i=i*b.r+b.i*r;
returntemp;
}
void show()
{
cout<<endl<<r<<" + "<<i<<"i";}
};
void main()
{
clrscr();
comp c1(5,2),c2(7,3),c3,c4;
c3=c1+c2;
c4=c1*c2;
c1.show();
c2.show();
c3.show();
c4.show();
getch();
}
2. Program 2: Write a program to show the use of friendfunctionin order to access the private data
of a class.
#include<iostream.h>
#include<conio.h>
#include<string.h>
class abc
{
char name[20];
intm;
public:
abc()
{
strcpy(name,"Akshay");
m=85;
}
friendvoid replace(abc&a1);
void show()
{
cout<<endl<<name<<""<<m;}
};
void replace(abc&a)
{
strcpy(a.name,"none");
a.m=0;
}
void main()
{
clrscr();
abc a;
a.show();
replace(a);
a.show();
getch();
}
3. Program 1: Write a program to implementbasicstructure of classesand memberfunction by
readingand printinga studentname and marks and also write a functionto assigngrade to the
student.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class studnt
{
floatmarks;char nam[50],grade[2];
public:
void getdata()
{
cout<<"Enter the name and marksof the studentn";
gets(nam);
cout<<endl;
cin>>marks;cout<<endl;
}
void calc()
{
if(marks>=85)
strcpy(grade,"A+");
else if(marks>=75)
strcpy(grade,"A");
else if(marks>=65)
strcpy(grade,"B");
else if(marks>=50)
strcpy(grade,"C");
else if(marks>=40)
strcpy(grade,"D");
else strcpy(grade,"F");
}
void show()
{
cout<<endl<<"Student:"<<nam<<"has grade "<<grade<<endl;
}
};
void main()
{
clrscr();
int n=1,i;
cout<<"nHowmany studentsdatayouwantto createn";cin>>n;
studnt*s;
s= newstudnt[n];
for(i=0;i<n;i++)
{
s[i].getdata();
s[i].calc();
}
for(i=0;i<n;i++)
s[i].show();
getch();
}
4.
5. Program 4: Write a program to show the use of “this” pointer.
#include<iostream.h>
#include<conio.h>
class student
{
char name[100];
floatpercent;
public:
voidgetdata()
{
cout<<"Enterdata"<<endl;
cout<<"Name:";
cin>>name;
cout<<"Percent:";
cin>>percent;
cout<<endl;
}
student& max(student&s1,student&s2)
{
if(percent>s1.percent&&percent>s2.percent)
return*this;
else if(s1.percent>percent&&s1.percent>s2.percent)
returns1;
else if(s2.percent>percent&&s2.percent>s1.percent)
returns2;
}
voiddisplay()
{
cout<<"Name:"<<name<<endl;
cout<<"Percent:"<<percent;
}
};
void main()
{
students,s1,s2,s3;
s1.getdata();
s2.getdata();
s3.getdata();
s=s3.max(s1,s2);
cout<<"Studentwithhighestpercentage"<<endl;
s.display();
getch();
}
6. Program 5: Write a program to implementmultiple andmultilevel inheritence.
A) Multilevel inheritance
#include <iostream>
#include<conio.h>
usingnamespace std;
class A
{
public:
voiddisplay()
{
cout<<"Base class content.";
}
};
class B : publicA
{ };
class C : public B
{ };
int main()
{
C obj;
obj.display();
return0;
getch();
}
af
7. B) Multiple inheritence
#include <iostream>
usingnamespace std;
class Mammal
{
public:
Mammal()
{
cout << "Mammalscan give directbirth."<< endl;
}
};
class WingedAnimal
{
public:
WingedAnimal()
{
cout << "Wingedanimal canflap."<< endl;
}};
class Bat: publicMammal, publicWingedAnimal
{
};
int main()
{
Bat b1;
return0;
}
8. Program 6: Write a program to implementhybridand heirarchical inheritence.
A) Hybrid inheritance
#include<iostream.h>
#include<conio.h>
class arithmetic
{
protected:
intnum1, num2;
public:
void getdata()
{
cout<<"For Addition:";
cout<<"nEnterthe firstnumber:";
cin>>num1;
cout<<"nEnterthe secondnumber:";
cin>>num2;
}
};
class plus:publicarithmetic
{
protected:
intsum;
public:
void add()
{
sum=num1+num2;
}
};
class minus
{
protected:
intn1,n2,diff;
public:
void sub()
{
cout<<"nForSubtraction:";
cout<<"nEnterthe firstnumber:";
cin>>n1;
cout<<"nEnterthe secondnumber:";
cin>>n2;
diff=n1-n2;
}
};
class result:publicplus,publicminus
{
public:
void display()
{
cout<<"nSumof "<<num1<<" and "<<num2<<"= "<<sum;
cout<<"nDifference of "<<n1<<" and "<<n2<<"= "<<diff;
}};
9. void main()
{
clrscr();
resultz;
z.getdata();
z.add();
z.sub();
z.display();
getch();
}
A) Heirarchical inheritance
#include <iostream.h>
#include<conio.h>
class Number
{
private:
intnum;
public:
voidgetNumber()
{
cout << "Enteran integernumber:";
cin >> num;
}
intreturnNumber()
{
returnnum;
}
};
class Square:publicNumber
{
public:
int getSquare()
{
intnum,sqr;
num=returnNumber();
sqr=num*num;
returnsqr;
}
};
class Cube:publicNumber