Beruflich Dokumente
Kultur Dokumente
Template<class T>
Class sort
{
T a[10];
Public:
Void insert()
{
For(i=0;i<10;i++)
{
Cout<<”enter value”;
Cin>>a[i];
}
Void sort
{
T temp;
For(i=0;i<=n-1;i++)
{
For(j=1;j<=n-I;j++)
{
If (a[j]>a[j+1])
{
Temp=a[j]
A[j]=a[j+1]
A[j+1]=temp
}
}
}
}
Main()
{
Sort<int>s1;
S1.insert();
S1.sort();
Sort<float>s2;
S2.sort();
}
Program – 2
Class ele-bill
{
Char name[10];
Int unit;
Float bill;
Public:
Void getdetail()
{
Cout<<”enter person details”;
Cin>>name>>unit;
If(unit<=100)
{
Bill=unit*60;
If(bill<50)
{
Bill=50;
}
}
Else if (unit>101 && unit<=300)
{
Bill=unit*80;
}
Else
{
Bill=unit*90;
If(bill>300)
{
Bill=bill+bill*0.15;
}
Void putdata()
{
Cout<<name<<bill;
}
};
Main()
{
Ele-bill p1,p2;
P1.getdata();
P1.getdata();
}
Program – 3
#include<math.h>
Power(double M,int n=2)
{
Return= power(m,n);
}
Main()
{
Cout<<”enter value of m,n”;
Cin>>m>>n;
Power(m,n);
}
Program – 4
#include<iostream.h>
#include<conio.h>
class staff
{
public:
int code;
char *name;
void gets()
{
cout <<"ENTER THE NAME AND CODE OF
STAFF:";
cin >> code >> name;
}
};
class teacher : public staff
{
public:
char *sub,*pub;
void gett()
{
cout <<"ENTER THE DETAILS OF TEACHER:";
cin >>sub >>pub;
}
void displayt()
{
cout << "THE DETAILS OF A TEACHER IS:";
cout << sub <<endl <<pub;
}
};
class typist : public staff
{
public:
int speed;
void gett1()
{
cout << "ENTER SPEED:";
cin >>speed;
}
};
class regular : public typist
{
public:
int mw;
void getr()
{
cout << "ENTER THE MONTHLY
WAGES:";
cin >> mw;
}
void displayr()
{
cout << "THE MONTHLY WAGES IS:";
cout << mw <<endl;
}
};
class casual : public typist
{ public:
int dw;
void getc()
{
cout << "ENTER THE DAILY WAGES:";
cin >> dw;
}
void displayc()
{
cout << "THE DAILY WAGES IS:";
cout << dw <<endl;
}
};
class other:public staff
{
public:
int grade;
void geto()
{
cout << "ENTER THE GRADE:";
cin >> grade;
}
void displayo()
{
cout << "THE GRADE IS:";
cout << grade <<endl;
}
};
void main()
{
clrscr();
int n;
cout << "ENTER CODE:";
cout <<"1.TEACHER\n" <<"2.TYPIST\n"
<<"3.OTHERS\n";
teacher t;
t.gets();
if(t.code == 1)
{
t.gett();
t.displayt();
}
else if(t.code == 2)
{
typist t1;
t1.gett1();
cout << "1.regular and 2.casual:\n";
if(t1.speed == 1)
{
regular r;
r.getr();
r.displayr();
}
if(t1.speed == 2)
{
casual c;
c.getc();
c.displayc();
}
}
else if(t.code == 3)
{
other o;
o.geto();
o.displayo();
}
else
{
cout << "INVALID CHOICE:";
}
getch();
}
Program – 5
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class account
{
public:
char cust_name[10];
int accno;
int typeofac;
void getaccount()
{
cout<<"Enter customer name";
cin>>cust_name;
cout<<endl<<"Enter account number";
cin>>accno;
void displayaccount()
{
cout<<cust_name<<endl<<accno<<endl;
if (typeofac ==1)
cout<<"Savings";
else
cout<<"Current";
}
};
void basicbalance()
{
cout<<endl<<"Enter the balance";
cin>>balance;
int i;
do
{
cout<<endl;
cout<<endl<<"1. Deposit amt";
cout<<endl<<"2. Withdraw amt";
cout<<endl<<"3. Calculate interest";
cout<<endl<<"4. Show balance";
cout<<endl<<"5. Exit";
cin>>i;
switch(i)
{
case 1:
depositamt();
break;
case 2:
withdrawal();
break;
case 3:
calculateinterest();
break;
case 4:
showbalance();
break;
case 5:
exit(0);
}
}while(i!=5);
}
void depositamt()
{
cout<<endl<<"Enter the amount to be
deposited";
cin>>depo_amt;
void showbalance()
{
cout<<"The balanace is "<<balance;
}
void calculateinterest()
{
interest = balance * 0.10;
cout<<endl<<"The interest is "<<interest;
void withdrawal()
{
cout<<endl<<"Enter the withdrawal
amount";
cin>>with_amt;
};
void basicbalance()
{
cout<<endl<<"Enter the balance";
cin>>balance;
int i;
do
{
cout<<endl;
cout<<endl<<"1. Deposit amt";
cout<<endl<<"2. Withdraw amt";
cout<<endl<<"3. Show balance";
cout<<endl<<"4. Exit";
cin>>i;
switch(i)
{
case 1:
depositamt();
break;
case 2:
withdrawal();
break;
case 3:
showbalance();
break;
case 4:
exit(0);
}
}while(i!=4);
void depositamt()
{
cout<<endl<<"Enter the cheque no";
cin>>chequeno;
cout<<endl<<"Enter the bank name";
cin>>bankname;
cout<<endl<<"Enter the amount to be
deposited";
cin>>depo_amt;
void showbalance()
{
cout<<"The balanace is "<<balance;
}
void withdrawal()
{
cout<<endl<<"Enter the withdrawal
amount";
cin>>with_amt;
};
void main()
{
clrscr();
savings s;
s.getaccount();
cout<<endl<<"Enter the type of account";
cout<<"1. Savings";
cout<<"2. Current";
cin>>s.typeofac;
s.displayaccount();
if (s.typeofac == 1)
s.basicbalance();
else
{
current c;
c.basicbalance();
}
getch();
}
Program – 6
Write a program to input string from user & print the following
types of triangle depend on input.
e.x if user input “program” then
Pr
Pro
Prog
Progr
Progra
Program
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[10];
int i,j,n;
clrscr();
cout<<endl<<"Enter string :=> ";
cin>>a;
n=strlen(a);
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
cout<<a[j];
}
cout<<endl;
}
getch();
}