C pgms
1. Factorial value of a number using recursive function
#include
#include
long fact(int n)
{
if(n==0)
return 1;
return (n*fact(n-1));
}
void main()
{
int num;
cout>num;
cout
#include
#include
void main()
{
clrscr();
char str[100];
int i,totChar;
totChar=0;
cout
#include
int swap(int &,int &);
void main()
{
int a,b;
clrscr();
cout>a>>b;
coutOUTPUT
Swapping Two numbers
10
5
Before swapping
A = 10
B=5
After Swapping
A=5
B = 10
4. Salary slip using class and Object
#include
#include
class Employee
{
clrscr();
int eid;
char ename[100];
float basic_salary, hra, da, i_tax, net_salary;
public:
void accept_details()
{
cout>eid;
cout>ename;
cout>basic_salary;
hra = 800;
da = 0.25 * basic_salary;
i_tax = 0.15 * basic_salary;
net_salary = basic_salary + da + hra – i_tax;
}
void display_details()
{
cout
#include
class fibonacci
{
private:
unsigned long int f0,f1,fib;
public:
fibonacci()
{
f0=0;
f1=1;
fib=f0+f1;
}
fibonacci (fibonacci &ptr)
{
f0=ptr.f0;
f1=ptr.f1;
fib=ptr.fib;
}
void increment()
{
f0=f1;
f1=fib;
fib=f0+f1;
}
void display()
{
cout
#include
#include
#include
class area
{
float ar;
public:
area(float r)
{
ar=3.14*r*r;
}
area(float l, float b)
{
ar=l*b;
}
area(float a, float b, float c)
{
float s;
s=(a+b+c)/2;
ar=s*(s-a)*(s-b)*(s-c);
ar=pow(ar,0.5);
}
void display()
{
cout>ch;
switch(ch)
{
case 1 :
{
cout>x;
area a1(x);
a1.display();
break;
}
case 2 :
{
cout>x>>y;
area a2(x,y);
a2.display();
break;
}
case 3 :
{
cout>x>>y>>z;
area a3(x,y,z);
a3.display();
break;
}
case 4 :
exit(0);
default :
cout
#include
#include
class AddString
{
public:
char s1[25], s2[25];
AddString(char str1[], char str2[])
{
strcpy(this->s1, str1);
strcpy(this->s2, str2);
}
void operator+()
{
cout >str1;
cout>str2;
AddString a1(str1, str2);
+a1;
getch();
}
OUTPUT
Enter the first string : Good
Enter the second string : Morning
Concatenated String : GoodMoring
8. Electricity Bill Calculation using Derived class
#include
#include
class electricity
{
protected:
float unit;
float cost;
public:
void bill()
{
cout>unit;
if(unit300)
{
cost=0.60*unit;
cout250.00)
{
diff=cost-250;
surcharge=diff*0.15;
cout
#include
int a,b;
class add
{
public:
void getdata();
friend void display();
};
void add::getdata()
{
cout>a>>b;
}
void display()
{
cout
#include
#include
void main()
{
ofstream fout(“student”);
char str[20];
int i,n;
clrscr();
cout>n;
for(i=0;i>str;
cout