You are on page 1of 12

PROGRAMMING V

PRACTICAL FILE

MANMEET SINGH
480/IC/11

INDEX
S. No.

1.
2.
3.
4.

5.

6.

EXPERIMENT

Write a C++ program for creating a class having


members of private and public and access them.
Write a program to implement inline function and
function overloading.
Study characteristics of constructor and destructor and
write a program to implement them.
Study inheritance, types of inheritance and modes of
inheritance. Write a program to create a class as a
member of private, protected and public.
Access these members through object and member
function.
Write a program in C++ to create a base and a derived
class of banking information system to perform the
following tasks:i. Personal Information of the customer.
ii. Display the balance
iii. Deposit, withdrawal and compute interest.
iv. Check for minimum balance and add penalty
where necessary and update the balance.
Write a program to make a text file and perform the
read, write and modify operations in it.

PAGE NO.

EXPERIMENT-1
#include<iostream>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
class student
{
int rollno;
char name[100];
public:
student()
{
rollno = 0;
strcpy(name,"");
}
void display()
{
cout<<endl<<"DISPLAYING"<<endl<<endl;
cout<<"Roll No : "<<rollno<<endl;
cout<<" Name : "<<name<<endl;
}
void setValue(int rln, char* str)
{
rollno = rln;
strcpy(name,str);
}
};
void main()
{
student stud[2];
int rno;
char name[100];
cout<<"Enter Details\n\n";
int i = 0;
for(int i=0;i<2;i++)
{
cout<<"\nEnter Roll No. : ";
cin>>rno;
cout<<"Enter Name : ";
gets(name);
stud[i].setValue(rno,name);
}

cout<<endl;
for(i=0;i<2;i++)
stud[i].display();
getch();
}

OUTPUT:
Enter Details

Enter Roll No. : 1


Enter Name : Anisha
Enter Roll No. : 2
Enter Name : Ani

DISPLAYING
Roll No : 1
Name : Anisha
DISPLAYING
Roll No : 2
Name : Ani

EXPERIMENT-2
#include<iostream>
#include<conio.h>
#include<math.h>
void inline func1()
{
cout<<"\n Inside Inline Function..."<<endl;
}
void area1(float b,float h)
{
cout<<"\n Inside 1st function...";
cout<<endl<<endl<<" Area of the Triangle is "<<0.5*b*h<<endl;
}
void area1(float a,float b,float c)
{
float s = (a+b+c)/2.0;
cout<<"\n Inside Overloaded function...";
cout<<endl<<endl<<" Area of the Triangle is "<<sqrt(s*(s-a)*(s-b)*(s-c))<<endl;
}
int main()
{
float b,h,a,b1,c;
cout<<"\n Calling Inline Function...";
func1();
cout<<"\n\n CALCULATING AREA...";
cout<<"\n Enter the length of Base ";
cin>>b;
cout<<" Enter the length of Height ";
cin>>h;
area1(b,h);
cout<<"\n\n CALCULATING AREA USING OVERLOADED FUNCTION...";
cout<<"\n Enter the length of the three sides ";
cin>>a>>b1>>c;
area1(a,b1,c);
return(0);
}

OUTPUT:
Calling Inline Function...
Inside Inline Function...

CALCULATING AREA...
Enter the length of Base 4
Enter the length of Height 6
Inside 1st function...
Area of the Triangle is 12

CALCULATING AREA USING OVERLOADED FUNCTION...


Enter the length of the three sides 4 4 4
Inside Overloaded function...
Area of the Triangle is 6.9282

EXPERIMENT-3
#include<iostream>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
class student
{
int rollno;
char name[100];
public:
student()
{
rollno = 0;
strcpy(name,"Default");
cout<<endl<<endl<<"Inside Student Constructor";
}
student(int rno,char *ptr)
{
rollno = rno;
strcpy(name,ptr);
cout<<endl<<endl<<"Inside Student Parameterised Constructor";
}
~student()
{
cout<<endl<<endl<<"INSIDE Student Destructor";
}
void display()
{
cout<<endl<<"DISPLAYING"<<endl<<endl;
cout<<"Roll No : "<<rollno<<endl;
cout<<" Name : "<<name<<endl;
}
};
void func()
{
int r;
char nm[100];
student obj1;
obj1.display();
cout<<"\n\nEnter the roll number: ";
cin>>r;
cout<<"\nEnter the Name: ";
gets(nm);

student obj2(r,nm);
obj2.display();
}
int main()
{
func();
getch();
return(0);
}

OUTPUT:
Inside Student Constructor
DISPLAYING
Roll No : 0
Name : Default

Enter the roll number: 1


Enter the Name: Anisha

Inside Student Parameterised Constructor


DISPLAYING
Roll No : 1
Name : Anisha

INSIDE Student Destructor


INSIDE Student Destructor

EXPERIMENT-5
#include<iostream>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<fstream>
class AccountInfo
{
protected:
char name[100];
char addr[100];
char date[30];
public:
AccountInfo()
{
strcpy(name,"");
strcpy(addr,"");
strcpy(date,"1 Jan 2000");
}
AccountInfo(char *nm,char *ad,char *dt)
{
strcpy(name,nm);
strcpy(addr,ad);
strcpy(date,dt);
}
void changeaddr(char *ad)
{
strcpy(addr,ad);
}
void showdet()
{
cout<<"\n\nACCOUNT DETAILS";
cout<<"\nName: "<<name;
cout<<"\nAddress: "<<addr;
cout<<"\nDate of Opening: "<<date;
}
};
class Bal : public AccountInfo
{
float bal; //min Rs 500
float penalty;
public:
Bal(char *nm,char *ad,char *dt)

{
bal = 0;
penalty = 0;
strcpy(name,nm);
strcpy(addr,ad);
strcpy(date,dt);
}
void balenq()
{
cout<<"Current Balance = Rs"<<bal - penalty;
}
void withdrawl(float withdr)
{
bal = bal - withdr - penalty;
if(bal<500)
penalty = 0.1 * (500 - bal);
}
void deposit(float deposit)
{
bal = bal + deposit - penalty;
if(bal<500)
penalty = 0.1 * (500 - bal);
}
void show()
{
cout<<"\n\nBalance Details";
cout<<"\nBalance = "<<bal;
cout<<"\nPenalty = "<<penalty;
cout<<"\nInterest = "<<0.2 * bal;
}
};
int main()
{
Bal obj("XYZ","ABC City Delhi India","1 Jan 2011");
float money;
int ch;
char yn;
char address[100];
cout<<"\nMenu ";
cout<<"\n1. Deposit";
cout<<"\n2. Withdraw";
cout<<"\n3. Address Change";
cout<<"\n4. Show Details";
do

{
cout<<"\nEnter your choice: ";
cin>>ch;
switch(ch)
{
case 1: cout<<"\nEnter the amount to be deposited: ";
cin>>money;
obj.deposit(money);
break;
case 2: cout<<"\nEnter the amount to be withdrawn: ";
cin>>money;
obj.withdrawl(money);
break;
case 3: cout<<"\nEnter the address: ";
flushall();
gets(address);
obj.changeaddr(address);
break;
case 4: obj.showdet();
obj.show();
}
cout<<"\nDo you wish to continue: ";
cin>>yn;
}while(yn=='y');
getch();
return(0);
}

OUTPUT:
Menu
1. Deposit
2. Withdraw
3. Address Change
4. Show Details
Enter your choice: 1
Enter the amount to be deposited: 1000
Do you wish to continue: y
Enter your choice: 4

ACCOUNT DETAILS

Name: XYZ
Address: ABC City Delhi India
Date of Opening: 1 Jan 2011
Balance Details
Balance = 1000
Penalty = 0
Interest = 200
Do you wish to continue: y
Enter your choice: 600
Do you wish to continue: y
Enter your choice: 4

ACCOUNT DETAILS
Name: XYZ
Address: ABC City Delhi India
Date of Opening: 1 Jan 2011
Balance Details
Balance = 1000
Penalty = 0
Interest = 200
Do you wish to continue: n

You might also like