oops file ishan
TRANSCRIPT
-
7/30/2019 Oops File Ishan
1/46
PRACTICAL 1 : Write a program to check whether a given number is even or odd.
#include#include
void main(){clrscr();int n;coutn;if(n%2==0)cout
-
7/30/2019 Oops File Ishan
2/46
PRACTICAL 2: Write a program to find the greatest of three numbers using conditional
operator.
#include
#includevoid main(){clrscr();int a,b,c;couta;coutb;coutc;
if(a>b){if(a>c)cout
-
7/30/2019 Oops File Ishan
3/46
PRACTICAL 3 : Write a program to find the sum of digits of a number.
#include
#includevoid main(){clrscr();int n,num,sum=0;coutn;num=n;while(num>0){sum+=num%10;
num/=10;}cout
-
7/30/2019 Oops File Ishan
4/46
PRACTICAL 4 : Write a program to generate Fibonacci series of first n numbers.
#include#includevoid main(){clrscr();int n;int f1,f2,f3;coutn;f1=1;f2=1;
cout
-
7/30/2019 Oops File Ishan
5/46
PRACTICAL 5: Write a program to print the multiplication table of a given number.
#include#includevoid main(){clrscr();int n,i;coutn;for(i=1;i
-
7/30/2019 Oops File Ishan
6/46
PRACTICAL 6 : Write a program to calculate the factorial of a number.
#include#includevoid main(){clrscr();int i,num,fact=1;coutnum;i=num;while (num>0){
fact=fact*num;--num;}cout
-
7/30/2019 Oops File Ishan
7/46
PRACTICAL 7 : Write a program to add, subtract, multiply & division o two numbers
using switch statement.
#include#includevoid main(){clrscr();int a,b;char opr;couta>>b;
coutopr;switch(opr){case'+':int c=a+b;cout
-
7/30/2019 Oops File Ishan
8/46
case'-':int d=a-b;cout
-
7/30/2019 Oops File Ishan
9/46
PRACTICAL 8 : Write a program to check whether a given number is prime or not.
100420480300
-
7/30/2019 Oops File Ishan
10/46
#include#includevoid main(){
clrscr();int num,i,c=0;coutnum;for(i=2;i
-
7/30/2019 Oops File Ishan
11/46
#include#includevoid main()
{clrscr();for(int i=1;i=0;j--)cout
-
7/30/2019 Oops File Ishan
12/46
#include#includevoid main(){
clrscr();int x,y;x=10;y=20;void swap(int,int);swap(x,y);cout
-
7/30/2019 Oops File Ishan
13/46
#include#includevoid main()
{clrscr();int x,y;x=10;y=20;void swap(int&, int&);swap(x,y);cout
-
7/30/2019 Oops File Ishan
14/46
#include#includevoid main(){clrscr();
int *p;int x;coutx;p=&x;*p=*p+10;cout
-
7/30/2019 Oops File Ishan
15/46
#include#includeinline double cube(double x){return(x*x*x);
}void main(){clrscr();double a;couta;cout
-
7/30/2019 Oops File Ishan
16/46
#include#includevoid main(){
clrscr();int sum(int=30,int=30);int a,b;couta;coutb;sum(a,b);sum(a);sum();getch();
}int sum(int x,int y){int s=x+y;cout
-
7/30/2019 Oops File Ishan
17/46
#include#includevoid main(){
clrscr();int fact(int);int f,n;coutn;f=fact(n);cout
-
7/30/2019 Oops File Ishan
18/46
#include#includevoid main(){
clrscr();int a[3][3],b[3][3],s[3][3];cout
-
7/30/2019 Oops File Ishan
19/46
{for(j=0;j
-
7/30/2019 Oops File Ishan
20/46
#include#includevoid main(){
clrscr();char a[80],b[80];void string_copy(char b[],char a[]);
cout
-
7/30/2019 Oops File Ishan
21/46
PRACTICAL 18: Write a program to demonstrate the working of structure within a
structure.
#include
#includestruct date{int day;char month_name[20];int year;};struct biodata{char name[80];date dob;
};void main(){clrscr();biodata student;cout
-
7/30/2019 Oops File Ishan
22/46
100420480300
-
7/30/2019 Oops File Ishan
23/46
PRACTICAL 19: Write a program to calculate the area of rectangle using the concept of
object class.
#include#includeclass area{public:int l,b,area;void getdata(){coutl;coutb;}void display(){area=l*b;cout
-
7/30/2019 Oops File Ishan
24/46
PRACTICAL 20 : Write a program to demonstrate data hiding, encapsulation and
abstraction.
#include#includevoid main(){clrscr();class date{public:int day;int month;int year;
};class date today;today.day=12;today.month=1;today.year=1992;cout
-
7/30/2019 Oops File Ishan
25/46
PRACTICAL 21 : Write a program to show the working of static data members and
static member functions.
#include#include
class alpha{private:static int x;public:alpha();static void display(){cout
-
7/30/2019 Oops File Ishan
26/46
100420480300
-
7/30/2019 Oops File Ishan
27/46
PRACTICAL 22 : Write a program to demonstrate the working of constructor.
#include#includeclass sample{int a,b;public:sample(){cout
-
7/30/2019 Oops File Ishan
28/46
PRACTICAL 23: Write a program to show the working of parameterized constructor.
#include#include
class student{int a,b;public:student(int a1,int b1){a=a1;b=b1;}int mul(){
return(a*b);}};void main(){clrscr();int i,j;couti;coutj;student c1(i,j);
cout
-
7/30/2019 Oops File Ishan
29/46
PRACTICAL 24: Write a program to demonstrate constructor overloading.
#include#includeclass complex{int x,y;public:complex(int a){
x=a;y=a;}complex(int a,int b){x=a;y=b;}void add(complex c1,complex c2){x=c1.x-c2.x;
y=c1.x-c2.y;}void show(){cout
-
7/30/2019 Oops File Ishan
30/46
clrscr();complex a(3,5);complex b(2);complex c(0);c.add(a,b);
a.show();b.show();cout
-
7/30/2019 Oops File Ishan
31/46
PRACTICAL 25: Write a program to demonstrate copy constructor.
#include#includeclass complex{int r,i;public:complex(int a,int b){r=a;
i=b;}complex(complex&c){r=c.r;i=c.i;}void show(){cout
-
7/30/2019 Oops File Ishan
32/46
complex c1(x,y);complex c2(c1);cout
-
7/30/2019 Oops File Ishan
33/46
PRACTICAL 26 : Write a program to demonstrate destructor.
include
100420480300
-
7/30/2019 Oops File Ishan
34/46
#includeclass sample{int a,b;public:
~sample(){cout
-
7/30/2019 Oops File Ishan
35/46
#includeclass b1{protected:int x;
public:void assignx(){x=20;}};class d1:public b1{protected:int y;public:void assigny()
{y=40;}};class d2:public d1{protected:int z;public:void assignz(){z=60;
}};class b2{protected:int k;public:void assignk(){k=80;}};class d3:public b2,public d2
{private:int total;public:void output(){total=x+y+z+k;cout
-
7/30/2019 Oops File Ishan
36/46
}};void main(){clrscr();d3 s;
s.assignx();s.assigny();s.assignz();s.assignk();s.output();getch();}
PRACTICAL 28: WRITE A PROGRAM which concatenates two strings by overloading
the binary operator +.
100420480300
-
7/30/2019 Oops File Ishan
37/46
#include#include#includeclass string
{char str[80];public:string(){strcpy(str," ");}string(char s[]){strcpy(str,s);}
void display(){cout
-
7/30/2019 Oops File Ishan
38/46
PRACTICAL 29: Write a program to show function overloading.
100420480300
-
7/30/2019 Oops File Ishan
39/46
#include#includevoid sum(int,int);void sum(int,int,int);
void sum(float,float);void main(){clrscr();int a,b,c;float p,q;couta>>b>>c;coutp>>q;sum(a,b,c);
sum(a,b);sum(a,c);sum(p,q);getch();}void sum(int x,int y){int z=x+y;cout
-
7/30/2019 Oops File Ishan
40/46
100420480300
-
7/30/2019 Oops File Ishan
41/46
PRACTICAL 30: Write a program to demonstrate virtual functions.
#include#includeclass b
{public:virtual void display(){cout
-
7/30/2019 Oops File Ishan
42/46
100420480300
-
7/30/2019 Oops File Ishan
43/46
PRACTICAL 31: Write a program to demonstrate friend function.
#include#includeclass sample{int x;int y;public:sample(int a,int b){x=a;y=b;
}friend int add(sample s1);};int add(sample s1){return(s1.x+s1.y);}void main(){clrscr();sample s2(20,30);
int sum;sum=add(s2);cout
-
7/30/2019 Oops File Ishan
44/46
PRACTICAL 32: Write a program to read multiple line string using get function.
#include#includevoid main(){clrscr();char str[80];cout
-
7/30/2019 Oops File Ishan
45/46
PRACTICAL 33: Write a program to demonstrate class template with constructor.
#include#includetemplateclass sample{private:T a,b;public:sample (Ta1,Tb1){a=a1;b=b1;}
T small(){if(a
-
7/30/2019 Oops File Ishan
46/46
PRACTICAL 34: Write a program to show function template with multiple parameters.
#include
#includetemplatevoid show(T1a,T2b){cout