C++ by Dev
C++ by Dev
Name: Devbrat kr. singh Roll No. :- 1863058 Reg No: 184630086 / 2018
Output:
1
Practical of C++
Name: Devbrat kr. singh Roll No. :- 1863058 Reg No: 184630086 / 2018
Output:
2
Practical of C++
Name: Devbrat kr. singh Roll No. :- 1863058 Reg No: 184630086 / 2018
//Program of armstrong
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,s=0,b=0,r;
cout<<"\n Enter number:";
cin>>n;
while(n>0)
{
r=n%10;
b=b*10+r;
n=n/10;
s=(s+(r*r*r));
if(s==n)
{
cout<<"\n Number is an armstrong";
}
else
{
cout<<"\n Number is not an armstrong";
}
cout<<"\n Sum="<<s;
}
getch();
}
Output:
3
Practical of C++
Name: Devbrat kr. singh Roll No. :- 1863058 Reg No: 184630086 / 2018
#include<iostream.h>
#include<math.h>
#include<conio.h>
void main()
{
clrscr();
float a,b,c,x,y;
cout<<"\n Value of A=";
cin>>a;
cout<<"\n Value of B=";
cin>>b;
cout<<"\n Value of C=";
cin>>c;
x= (-b-sqrt(b*b-4*a*c))/2*a;
cout<<"\n Value of first root is="<<x;
getch();
y= (-b+sqrt(b*b-4*a*c))/2*a;
cout<<"\n Value of second root is="<<y;
getch();
}
Output
4
Practical of C++
Name: Devbrat kr. singh Roll No. :- 1863058 Reg No: 184630086 / 2018
}
lcm=(a*b)/hcf;
cout<<"\n Lcm="<<lcm;
cout<<"\n Hcf="<<hcf;
getch();
}
Output:
5
Practical of C++
Name: Devbrat kr. singh Roll No. :- 1863058 Reg No: 184630086 / 2018
Output
6
Practical of C++
Name: Devbrat kr. singh Roll No. :- 1863058 Reg No: 184630086 / 2018
Output
7
Practical of C++
Name: Devbrat kr. singh Roll No. :- 1863058 Reg No: 184630086 / 2018
8
Practical of C++
Name: Devbrat kr. singh Roll No. :- 1863058 Reg No: 184630086 / 2018
9
Practical of C++
Name: Devbrat kr. singh Roll No. :- 1863058 Reg No: 184630086 / 2018
void main()
{
clrscr();
Report r;
r.input();
r.output();
getch();
}
Output:
10
Practical of C++
Name: Devbrat kr. singh Roll No. :- 1863058 Reg No: 184630086 / 2018
11
Practical of C++
Name: Devbrat kr. singh Roll No. :- 1863058 Reg No: 184630086 / 2018
};
class MDerive:public Derive1,public Base1
{
int e;
public:
void input()
{
Derive1::input();
Base1::input();
cout<<"\n Enter the value for e:";
cin>>e;
}
void output()
{
Derive1::output();
Base1::output();
cout<<"\n E="<<e;
}
};
void main()
{
clrscr();
MDerive t;
t.input();
t.output();
}
Output:
12
Practical of C++
Name: Devbrat kr. singh Roll No. :- 1863058 Reg No: 184630086 / 2018
Output
13
Practical of C++
Name: Devbrat kr. singh Roll No. :- 1863058 Reg No: 184630086 / 2018
#include<iostream.h>
#include<conio.h>
class number
{
public:
int x;
int y;
number(){}
number(int j,int k)
{
x=j;
y=k;
}
number operator++()
{
++x;
++y;
}
number operator+(number D)
{
number T;
T.x=x+D.x;
T.y=y+D.y;
return T;
}
void show()
{
cout<<"\n X="<<x;
cout<<"\n Y="<<y;
}
};
void main()
{
clrscr();
number A(2,3),B(4,5),C,G(10,20);
A.show();
B.show();
C=A+B;
C.show();
cout<<"\n Before increment of G";
G.show();
++G;
cout<<"\n Ater increment of G";
G.show();
getch();
}
14
Practical of C++
Name: Devbrat kr. singh Roll No. :- 1863058 Reg No: 184630086 / 2018
Output:
15
Practical of C++
Name: Devbrat kr. singh Roll No. :- 1863058 Reg No: 184630086 / 2018
16
Practical of C++
Name: Devbrat kr. singh Roll No. :- 1863058 Reg No: 184630086 / 2018
17
Practical of C++
Name: Devbrat kr. singh Roll No. :- 1863058 Reg No: 184630086 / 2018
#include<iostream.h>
#include<conio.h>
class student
{
protected:
char name[20];
int rollno;
};
class Fees:public student
{
float f;
public:
void input()
{
cout<<"\n Enter Name:";
cin.getline(name,20);
cout<<"\n Enter roll number:";
cin>>rollno;
cout<<"\n Enter fees:";
cin>>f;
}
void output()
{
cout<<"\n Name="<<name;
cout<<"\n Roll number="<<rollno;
cout<<"\n Fees="<<f;
}
};
void main()
{
clrscr();
Fees f;
f.input();
f.output();
getch();
}
Output
18
Practical of C++
Name: Devbrat kr. singh Roll No. :- 1863058 Reg No: 184630086 / 2018
19
Practical of C++
Name: Devbrat kr. singh Roll No. :- 1863058 Reg No: 184630086 / 2018
20
Practical of C++
Name: Devbrat kr. singh Roll No. :- 1863058 Reg No: 184630086 / 2018
Output:
21