Académique Documents
Professionnel Documents
Culture Documents
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class A
{ int a,b;
public:
void getdata(int a1,int b1)
{
a=a1;
b=b1;
}
void add(A ob1,A ob2)
{ a=ob1.a+ob2.a;
b=ob1.b+ob2.b;
cout<<"\nvalue of a after addition:"<<a;
cout<<"\nvalue of b after addition:"<<b;
}
};
void main()
{ clrscr();
A ob1,ob2,ob3;
ob1.getdata(7,8);
ob2.getdata(9,10);
ob3.add(ob1,ob2);
getch();
}
output:
value of a after addition:16
value of b after addition:18
//wap to construct a class named bank with details-name,type of account,accnt no.
,balance amt.member functions are-read,withdraw,deposite,display//
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class bank
{
char d_name[30];
char a_name[20];
int acc_no;
int a_bal,d_bal,w_bal;
public:
void read()
{
cout<<"\nEnter the name of depositor :";
gets(d_name);
cout<<"\nEnter the type of account :";
gets(a_name);
cout<<"\nEnter the account number :";
cin>>acc_no;
cout<<"\nEnter the balance amount : ";
cin>>a_bal;
}
void withdraw()
{
cout<<"\nEnter the amount to withdraw : ";
cin>>w_bal;
if (a_bal <= 2000)
cout<<"\nYou cannot withdraw as you reached minimum balance ";
else
a_bal = a_bal - w_bal;
}
void deposit()
{
cout<<"\n Enter the amount to deposit : ";
cin>>d_bal;
a_bal = a_bal + d_bal;
}
void display()
{
cout<<"\nThe depositor name is : "<<d_name;
cout<<"\nThe account type is : "<<a_name;
cout<<"\nThe account number is : "<<acc_no;
cout<<"\nThe account balance is : "<<a_bal;
}
};
void main()
{
bank b;
int select;
clrscr();
b.read();
cout<<"\nPress 1. for deposit or Press 2. for withdrawal : ";
cin>>select;
if (select == 1)
b.deposit();
else
if (select == 2)
b.withdraw();
else
cout<<"\nWrong value entered";
b.display();
getch();
}
output:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class book
{
char b_title[20];
char a_name[20];
int price;
int pages;
public:
void display();
void read()
{
cout<<"\nEnter name of book : " ;
gets(b_title);
cout<<"\nEnter name of Author : ";
gets(a_name);
cout<<"\nEnter price of the book : ";
cin>>price;
cout<<"\nEnter the number of pages in the book : ";
cin>>pages;
cout<<"\n**********************************";
}
};
void book :: display()
{
cout<<"\n\n The name of the book is : "<<b_title;
cout<<"\n\n The name of the author is : "<<a_name;
cout<<"\n\n The book price is : "<<price;
cout<<"\n\n The number of pages in the book is : "<<pages;
cout<<"\n\n----------------------------------------------";
}
void main()
{
book b1[3];
clrscr();
for (int i=0;i<3;i++)
{
b1[i].read();
}
for (int j=0;j<3;j++)
{
b1[j].display();
}
getch();
}
output:
**********************************
Enter name of book : computer system architecture
**********************************
Enter name of book : c++ fundamentals
**********************************
----------------------------------------------
----------------------------------------------
output:
Enter the excession no.:3
Enter the name of the book:c++
Enter the author's name:sumita arora
Enter the cost of the book:250
Enter the name of the publisher:dhanpat rai & co.
public:
item()
{
price =0;
code =0;
}
item(int a,int b)
{
price =a;
code= b;
}
item(item &obj3)
{
price = obj3.price;
code= obj3.code;
}
void display()
{
cout<<price<<"\n"<<code<<"\n";
}
};
void main()
{
clrscr();
item obj1(70,80),obj2(40,50);
obj1.display();
obj2.display();
obj2 = obj1;
obj2.display();
getch();
}
//wap to construct 2 classes named employee with details-(name,address,company) &
second class
named perk with details-da(25% of salary),hra(20% of salary).implement to find the net
salary//
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class employee
{
char e_name[30];
char address[40];
char company[20];
public:
void read()
{
cout<<"\nEnter the name of employee : ";
gets(e_name);
cout<<"\nEnter the address of employee : ";
gets(address);
cout<<"\nEnter the name of company : ";
gets(company);
}
void display()
{
cout<<"\n\nThe name of employee is : "<<e_name;
cout<<"\n\nThe address of the employee is : "<<address;
cout<<"\n\nThe name of the company is : "<<company;
}
};
class perk
{
float basic,da,hra,net_salary;
public:
void e_perk()
{
cout<<"\nEnter yhe basic salary : ";
cin>>basic;
da = 0.25 * basic;
cout<<"\n\nDa is : ";
cout<<da;
hra = 0.20 * basic;
cout<<"\n\nHra is : ";
cout<<hra;
}
void calc(employee obj1)
{
cout<<"\n\n----------------The details of the employee is ---------------- ";
obj1.display();
cout<<"\n\nThe Net Salary is : ";
net_salary = basic + da + hra;
cout<<net_salary;
}
};
void main()
{
employee obj1;
perk obj2;
clrscr();
obj1.read();
obj2.e_perk();
obj2.calc(obj1);
getch();
}
output:
Da is : 1500
Hra is : 1200
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class matrix
{
int a[2][2];
public:
void read();
void add(matrix,matrix);
};
void matrix::read()
{
cout<<"\nEnter the value of matrix :-----------------\n";
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
cin>>a[i][j];
}
}
}
void matrix::add(matrix a1,matrix b1)
{
int i,j;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
a[i][j] = a1.a[i][j] + b1.a[i][j];
}
}
cout<<"\nThe matrix after addition is :----------------\n";
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cout<<a[i][j]<<"\n";
}
}
}
void main()
{
clrscr();
matrix a,b,c;
a.read();
b.read();
c.add(a,b);
getch();
}
output:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class student
{
char st_name[20];
int r_no;
int m1,m2,m3,m4,m5;
public :
void read()
{
cout<<"\n\nenter your name : ";
gets(st_name);
cout<<"\nenter roll number : ";
cin>>r_no;
cout<<"\nenter marks of m1,m2,m3,m4,m5\n";
cin>>m1>>m2>>m3>>m4>>m5;
}
void display()
{
cout<<"\n\nThe name of student is : "<<st_name;
cout<<"\n\nthe roll number is : "<<r_no;
cout<<"\n\nthe marks are:
\n"<<m1<<"\n"<<m2<<"\n"<<m3<<"\n"<<m4<<"\n"<<m5;
}
void avg()
{
int avg;
avg = (m1+m2+m3+m4+m5)/5;
cout<<"\n\nThe average is : "<<avg;
}
};
void main()
{
student a;
clrscr();
a.read();
a.display();
a.avg();
getch();
}
output:
The average is : 77
//wap to input & show the details(marks in 2 subjects & total)of student using concept of
inheritance//
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class student
{
protected:
int roll_no;
public:
void getroll_no()
{
cout<<"\nEnter Your Roll Number :";
cin>>roll_no;
}
void put()
{
cout<<"\nYour roll_no";
}
};
class test:public student
{
protected:
int sub1,sub2;
public:
void showsub();
void getsub()
{
cout<<"\nEnter the marks in two subject : ";
cin>>sub1>>sub2;
}
};
void test::showsub()
{
cout<<"\nSubject 1 marks is : "<<sub1;
cout<<"\nSubject 2 marks is : "<<sub2;
}
class result:public test
{
int total;
public:
void showdetail();
void getdetail()
{
getroll_no();
getsub();
}
};
void result::showdetail()
{
total = sub1 + sub2;
cout<<"\nThe details of the student is : "<<total;
showsub();
cout<<"\nThe result is : "<<total;
}
void main()
{
clrscr();
result std;
std.getdetail();
std.showdetail();
getch();
}
output:
public:
void getroll_no()
{
cout<<"\nEnter Your Roll Number :";
cin>>roll_no;
}
void put()
{
cout<<"\nYour roll_no";
}
};
class test:public student
{
protected:
int sub1,sub2;
public:
void showsub();
void getsub()
{
cout<<"\nEnter the marks in two subject : ";
cin>>sub1>>sub2;
}
};
void test::showsub()
{
cout<<"\nSubject 1 marks is : "<<sub1;
cout<<"\nSubject 2 marks is : "<<sub2;
}
class result:public test
{
int total;
public:
void showdetail();
void getdetail()
{
getroll_no();
getsub();
}
};
void result::showdetail()
{
total = sub1 + sub2;
cout<<"\nThe details of the student is : "<<total;
showsub();
cout<<"\nThe result is : "<<total;
}
void main()
{
clrscr();
result std;
std.getdetail();
std.showdetail();
getch();
}
output:
//
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
int compute(int,int);
void compute(int,int,int);
void compute(char);
void main()
{
int l,b,h,a;
clrscr();
cout<<"\nEnter the length :";
cin>>l;
cout<<"\nEnter the Breadth :";
cin>>b;
cout<<"\nEnter the Height : ";
cin>>h;
a = compute(l,b);
cout<<"\nThe Area is : " <<a<<"\n";
compute('*');
compute(l,b,h);
compute('*');
getch();
}
void compute(char c)
{
for(int i=0;i<10;i++)
cout<<c;
}
int compute(int l1,int b1)
{
int area;
area = l1 * b1;
return(area);
}
void compute(int l1,int b1,int h1)
{
int vol;
vol =l1 * b1 * h1;
cout<<"\nThe volume is : "<<vol<<"\n";
}
output:
Enter the length :2
The Area is : 6
**********
The volume is : 24
**********