msc cpp
msc cpp
Hello world
#include<iostream.h>
#include<conio.h>
void main()
cout<<"Hello world";
getch();
}
Output
the sum is 30
#include<iostream.h>
#include<conio.h>
void main()
int a;
int b;
cin>>a;
cin>>b;
getch();
}
Output
#include <iostream.h>
#include<conio.h>
void main()
int a;
int b;
cin>>a;
cin>>b;
if (a>b)
else if (a<b)
else
getch();
}
Output
10*20=200
#include<iostream.h>
#include<conio.h>
void main()
char op;
int a,b;
cin>>op;
cin>>a>>b;
switch(op)
break;
break;
break;
break;
break;
getch();
}
Output
enter a number 5
the table of 5 is
10
15
20
25
30
35
40
45
50
#include<iostream.h>
#include<conio.h>
void main()
int a;
int i=1;
cin>>a;
while (i<=10)
cout<<a*i<<endl;
i=i+1;
getch();
}
Output
enter a number 5
the table of 5 is
10
15
20
25
30
35
40
45
50
#include<iostream.h>
#include<conio.h>
void main()
int a;
int i=1;
cin>>a;
do
cout<<a*i<<endl;
i=i+1;
} while (i<=10);
getch();
}
Output
enter a number 4
4*1=4
4*2=8
4*3=12
4*4=16
4*5=20
4*6=24
4*7=28
4*8=32
4*9=36
4*10=40
#include<iostream.h>
#include<conio.h>
void main()
int a;
cin>>a;
getch();
}
Output
#include<iostream.h>
#include<conio.h>
void main()
int a, rev=0,rem;
cin>>a;
while (a !=0)
rem = a%10;
a/=10;
getch();
}
Output
Factorial of 5= 120
#include <iostream.h>
#include<conio.h>
void main()
int n;
long factorial = 1;
cin >> n;
if (n < 0)
Else
factorial *= i;
cout << "Factorial of " << n << " = " << factorial;
getch();
}
Output
hello world
#include<iostream.h>
#include<conio.h>
void hello()
cout<<"hello world";
void main()
hello();
getch();
}
Output
0X00410
0X00410
0X02010
#include<iostream.h>
#include<conio.h>
void main()
int a=1;
int* b;
b=&a;
getch();
}
Output
10
#include <iostream.h>
#include<conio.h>
void increment(int i)
i++;
void main()
int a = 10;
increment(a);
getch();
}
Output
11
#include <iostream.h>
#include<conio.h>
a++;
void main()
int a = 10;
increment(&a);
getch();
}
Output
enter a number 5
factorial of 5 is 120
#include<iostream.h>
#include<conio.h>
void main()
int a;
cin>>a;
int factorial(int a)
if(a>1)
return a*factorial(a-1);
Else
return 1;
}
Output
10
12
#include <iostream.h>
#include<conio.h>
void main()
int n;
cin >> n;
getch();
}
Output
#include <iostream.h>
#include<conio.h>
return (x > y) ? x : y;
void main()
cout << "The maximum value is: " << m << endl;
getch();
}
Output
#include <iostream.h>
#include<conio.h>
return (x > y) ? x : y;
return (x > y) ? x : y;
void main()
cout << "The maximum integer value is: " << max(a, b) << endl;
cout << "The maximum double value is: " << max(c, d) << endl;
getch();
}
Output
#include <iostream.h>
#include<conio.h>
class Rectangle
public:
int length;
int width;
Rectangle(int l, int w)
length = l;
width = w;
int area()
};
void main()
cout << "The area of the rectangle is: " <<rect.area() << endl;
getch();
}
Output
#include <iostream.h>
#include<conio.h>
class Rectangle
private:
int length;
int width;
public:
Rectangle()
length =1 0;
width = 10;
Rectangle(int i)
length = i;
width = 5;
Rectangle(int l, int w)
length = l;
width = w;
}
int area()
};
void main()
Rectangle rect1;
cout << "The area of rect1 is: " << rect1.area() << endl;
Rectangle rect2(10);
cout << "The area of rect2 is: " << rect2.area() << endl;
cout << "The area of rect3 is: " << rect3.area() << endl;
getch();
}
Output
20. Write a program to show use of static data member and function
#include <iostream.h>
#include<conio.h>
class Counter
private:
public:
Counter()
count++;
return count;
};
int Counter::count = 0;
void main()
getch();
}
Output
#include <iostream.h>
#include<conio.h>
class Rectangle
private:
int length;
int width;
public:
Rectangle(int l, int w)
length = l;
width = w;
};
void main()
cout << "The area of the rectangle is: " << area(rect) << endl;
getch();
}
Output
#include <iostream.h>
#include<conio.h>
class Shape
protected:
int width;
int height;
public:
Shape(int w, int h)
width = w;
height = h;
};
public:
int getArea()
};
void main()
{
Rectangle rect(10, 20);
cout << "The area of the rectangle is: " <<rect.getArea() << endl;
getch();
}
Output
#include <iostream.h>
#include<conio.h>
class Shape
protected:
int width;
int height;
public:
Shape(int w, int h)
width = w;
height = h;
};
class Colour
protected:
string color;
public:
Colour(string c)
color = c;
};
{
public:
int getArea()
string getColor()
return colour;
};
void main()
cout << "The area of the rectangle is: " <<rect.getArea() << endl;
cout << "The colour of the rectangle is: " <<rect.getColor() << endl;
getch();
}
Output
Derived Function
#include <iostream.h>
#include<conio.h>
class Base
public:
void print()
};
public:
void print()
};
void main()
Derived derived1;
derived1.print();
getch();
}
Output
Count: 6
#include <iostream.h>
#include<conio.h>
class Count
private:
int value;
public:
Count() : value(5) {}
void operator ++ ()
++value;
void display()
};
void main()
Count count1;
++count1;
count1.display();
getch();
}
Output
Base Function
#include <iostream.h>
#include<conio.h>
class Base
public:
};
public:
void print()
};
void main()
Derived derived1;
base1->print();
getch();
}
Output
7.0
#include <iostream.h>
#include<conio.h>
template <typename T> T myMax(T x, T y)
{
return (x > y) ? x : y;
}
void main()
{
cout << myMax<int>(3, 7);
cout << myMax<double>(3.0, 7.0);
getch();
}
Output
34
65
39
11
39
#include<iostream.h>
#include<conio.h>
void main()
int a[50],n,i,item;
clrscr();
cin>>n;
for(i=0;i<n;i++)
cin>>a[i];
cin>>item;
for(i=0;i<n;i++)
if(a[i]==item)
break;
}
if(i==n)
else
getch();
}
Output
enter n
12
34
65
78
90
enter item
12
#include<iostream.h>
#include<conio.h>
void main()
int n,i,j,a[50],mid,end,item,big;
clrscr();
cout<<"enter n";
cin>>n;
for(i=0;i<n;i++)
cin>>a[i];
cout<<"enter item";
cin>>item;
big=0;
end=n-1;
mid=(big+end)/2;
while(item!=a[mid]&&big<=end)
if(item>a[mid])
big=mid+1;
else
end=mid-1;
mid=(big+end)/2;
if(big>end)
else
getch();
}
Output
enter the n 5
63
33
66
18
99
sorted list is
18
33
63
66
99
#include<iostream.h>
#include<conio.h>
void main()
int n,i,p,a[35],t;
clrscr();
cin>>n;
for(i=0;i<n;i++)
cin>>a[i];
for(p=1;p<n;p++)
for(i=0;i<n-p;i++)
{
if(a[i]>a[i+1])
t=a[i];
a[i]=a[i+1];
a[i+1]=t;
for(i=0;i<n;i++)
cout<<a[i];
getch();
}
Output
enter no of list
11
09
44
12
Sorted array
09
12
11
44
#include<iostream.h>
#include<conio.h>
void main ()
void mergesort(int[],int,int);
int n,i,a[20];
clrscr();
cout<<"enter no of list";
cin>>n;
for(i=0;i<n;i++)
cin>>a[i];
mergesort(a,0,n-1);
cout<<"sorted array=";
for(i=0;i<n;i++)
cout<<a[i];
getch();
int mid;
void merge(int[],int,int,int);
if(low<high)
mid=(high+low)/2;
mergesort(a,low,mid);
mergesort(a,mid+1,high);
merge(a,low,mid,high);
int b[20],i,j,m,k;
i=low;
j=mid+1;
k=low;
while(i<=mid&&j<=high)
if(a[i]>a[j])
b[k]=a[j];
k++;
j++;
}
else
b[k]=a[i];
k++;
i++;
while(i<=mid)
b[k]=a[i];
k++;
i++;
while(j<=high)
b[k]=a[j];
k++;
j++;
for(i=low;i<=high;i++)
a[i]=b[i];
}
Output
90
19
44
62
Sorted list
19
44
62
90
#include<iostream.h>
#include<conio.h>
void main()
void quicksort(int[],int,int);
int i,n,a[10];
clrscr();
cin>>n;
for(i=0;i<n;i++)
cin>>a[i];
quicksort(a,0,n);
cout<<a[i];
getch();
int position(int[],int,int);
int j;
if(low<high)
j=position(a,low,high);
quicksort(a,low,j-1);
quicksort(a,j+1,high);
int i,j,pivot,k;
pivot=a[low];
i=low;
j=high;
do
do
i=i+1;
}while(a[i]<pivot);
do
{
j=j-1;
}while(a[j]>pivot);
if(i<j)
k=a[i];
a[i]=a[j];
a[j]=k;
}while(i<j);
a[low]=a[j];
a[j]=pivot;
return j;
}
Output
enter no of list
11
09
44
12
Sorted array
09
12
11
44
#include<iostream.h>
#include<conio.h>
void main()
int a[20],j,i,n,k;
clrscr();
cout<<"enter no of list";
cin>>n;
for(i=0;i<n;i++)
cin>>a[i]);
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
if(a[i]>a[j])
k=a[i];
a[i]=a[j];
a[j]=k;
for(i=0;i<n;i++)
cout<<a[i];
getch();
}
Output
no of element
enter element
11
09
44
12
Sorted list is
09
12
11
44
#include<iostream.h>
#include<conio.h>
void main()
void radixsort(int[],int);
int i,j,k,n,a[20];
clrscr();
cout<<"no. of elements";
cin>>n;
for(i=0;i<n;i++)
cout<<"enter element";
cin>>a[i];
radixsort(a,n);
cout<<a[i];
getch();
int i,j,exp,b[20],m;
int bucket[10];
m=a[0];
for(i=1;i<n;i++)
if(a[i]>m)
m=a[i];
exp=1;
while(m/exp>0)
for(i=0;i<10;i++)
bucket[i]=0;
for(i=0;i<n;i++)
bucket[a[i]/exp%10]++;
for(i=1;i<10;i++)
{
bucket[i]+=bucket[i-1];
for(i=n-1;i>=0;i--)
b[--bucket[a[i]/exp%10]]=a[i];
for(i=0;i<n;i++)
a[i]=b[i];
exp=exp*10;
Return 0;
}
output
enter no of list
enter a number
11
09
44
12
Sorted list =
09
12
11
44
#include<iostream.h>
#include<conio.h>
void main()
int a[20],j,i,n,k,m;
clrscr();
cout<<"enter no of list";
cin>>n;
for(i=0;i<n;i++)
cout<<"enter a no";
cin>>a[i];
for(i=1;i<n;i++)
for(j=0;j<i;j++)
{
if(a[i]<a[j])
k=a[i];
m=i;
while(m!=j)
a[m]=a[m-1];
m--;
a[j]=k;
cout<<"sorted list=";
for(i=0;i<n;i++)
cout<<a[i];
getch();