Certificate
Name:
Class & Section:
Rohan Gupta
XII A
School:
Session:
2015-2016
____________________
___________________
Examiner`s Signature
Teacher`s Signature
Acknowledgement
I am extremely grateful and remain indebted to my teacher & guide Mrs. Narayani Singh for
being a source of inspiration and for her constant support in the design, implementation and
evaluation of the project. I am thankful to her constant criticism and invaluable suggestion,
which benefitted us a lot while developing the project. She has been a constant source of
inspiration and motivation for hard work & has been very co-operative throughout this project
work.
I also express my gratitude to my principal, Ms. Bharti Gosain for providing us the
infrastructure to carry out the project and to all the staff members who were directly &
indirectly instrument in enabling us to stay committed for the project. At last I would like to
thank my parents who helped me in various ways with their unconditional support and
affection during the years and always being there for me. They inspired my every step ahead to
put in my best.
Contents
Introduction
The C++ programming language was developed at AT&T Bell laboratories in the early 1980s by
Bjarne Stroustrup. He found C lacking for simulations and decided to extend the language by
adding features form his favorite language, Simula 67. Simula 67 was one of the earliest object
oriented language. Bjarne Stroustroup called it C with classes or New C during
development. The name C++ (pronounced C plus plus) was coined by Rick Mascitti where
++is the C increment operator. Ever since its birth, C++ evolved to cope with problems
encountered by users, and through discussions at AT&T. However, the maturation of the C++
language is attested by two recent events:
(i)The formation of an ANSI (American National Standard Institute)
And (ii) the publication of The Annotated C+ Reference
Function Overloading
Program 1: To illustrate the working of Function Overloading. Calculating
interest amount.
#include<iostream.h>
#include<stdlib.h>
void amount(float princ, int time, float rate)
{
cout<<"\nPrincipal Amount:"<<princ;
cout<<"\tTime:"<<time<<"year";
cout<<"\tRate:"<<rate;
cout<<"\nInterest Amount:"<<(princ*time*rate)<<"\n";
}
void amount(float princ, int time)
{
cout<<"\nPrincipal Amount:"<<princ;
cout<<"\tTime:"<<time<<"years";
cout<<"\tRate: 0.08";
cout<<"\nInternet Amount:"<<(princ*time*0.08)<<"\n";
}
void amount(float princ, float rate)
{
cout<<"\nPrincipal Amount:"<<princ;
cout<<"\tTime : 2 year";
cout<<"\tRate:"<<rate;
cout<<"\nInterest Amount:"<<(princ*2*rate)<<"\n";
6
}
void amount(int time, float rate)
{
cout<<"\nPrincipal Amount: 2000";
cout<<"\tTime:"<<time<<"years";
cout<<"\tRate:"<<rate;
cout<<"\nInterest Amount:"<<(2000*time*rate)<<"\n";
}
void amount(float princ)
{
cout<<"\nPrincipal Amount:"<<princ;
cout<<"\tTime: 2 years";
cout<<"\tRate: 0.08";
cout<<"\nInterest Amount:"<<(princ*2*0.08)<<"\n";
}
int main()
{
system("cls");
cout<<"Case 1";
amount(2000.0F);
cout<<"Case 2";
amount(2500.0F,3);
cout<<"Case 3";
amount(2300.0F,3,0.11F);
cout<<"Case 4";
amount(2,0.12F);
cout<<"Case 5";
7
amount(6,0.07F);
return 0;
}
OUTPUT:
9
}
float ITEM::largest(void)
{
float large=it_price[0];
for(int i=1;i<5;i++)
{
if(large<it_price[i])
large=it_price[i];
}
return large;
}
float ITEM::sum(void)
{
float sum=0;
for(int i=0;i<5;i++)
{
sum+=it_price[i];
}
return sum;
}
void ITEM::display_item(void)
{
cout<<"\nCode Price\n";
for(int i=0;i<5;i++)
{
cout<<"\n"<<itemcode[i];
cout<<"\n"<<it_price[i];
10
}
cout<<"\n";
}
int main()
{
ITEM order;
order.initialize();
float total, biggest;
int ch=0;
system("cls");
do
{
cout<<"\n\tMAIN MENU\n";
cout<<"\n1. Display Largest Price";
cout<<"\n2. Display Sum Of Prices";
cout<<"\n3. Display Item List";
cout<<"\nEnter your choice(1-3):";
cin>>ch;
switch(ch)
{
case 1: biggest=order.largest();
cout<<"The Largest Price is"<<biggest<<"\n";
break;
case 2:total=order.sum();
cout<<"The Sum Of Prices is"<<total<<"\n";
break;
case 3: order.display_item();
11
break;
}
}
while(ch>=1&&ch<=3);
return 0;
}
OUTPUT:
12
"<<inches<<" Inches
"<<"\n";
}
Distance sum(Distance d2);
};
Distance Distance::sum(Distance d2)
{
Distance d3;
d3.feet=feet+d2.feet+(inches+d3.inches)/12;
d3.inches=(inches+d2.inches)%12;
return (d3);
}
int main()
{
Distance Length1, Length2,total;
Length1.getdata(17,8);
Length2.getdata(14,5);
total=Length1.sum(Length2);
13
cout<<"Length 1: ";
Length1.printit();
cout<<"Length 2: ";
Length2.printit();
cout<<"Total Length: ";
total.printit();
return 0;
}
OUTPUT:
14
}
class Student { int rollno;
float marks;
public:
Student()
{cout<<"Constructing Student\n";
15
rollno=0;
marks=0.0;
}
void getval(void)
{
cout<<"Enter Roll Number And Marks: ";
cin>>rollno>>marks;
cout<<"\n";
}
void print(void)
{
cout<<"Roll Number: "<<rollno;
cout<<"\nMarks: "<<marks<<"\n";
}
};
class Admission{
Subject sub;
Student stud;
float fees;
public:
Admission()
{
cout<<"Constructing Admission\n";
fees=0.0;
16
}
void print(void)
{
stud.print();
sub.printsub();
cout<<"Fees: "<<fees<<"\n";
}
};
int main()
{
system("cls");
Admission adm;
cout<<"\nBack in Main()\n";
return 0;
}
OUTPUT:
17
};
18
cout<<"\tTotal Amount: Rs"<<total_amt<<"\n";
int main()
{
system("cls");
Deposit D1, D2(2000,2,0.0f), D3(4000,1), D4(3000,0.12f);
D1.calc_amt(); D2.calc_amt(); D3.calc_amt(); D4.calc_amt();
cout<<"Object 1\n"; D1.display();
cout<<"Object 2\n"; D2.display();
cout<<"Object 3\n"; D3.display();
cout<<"Object 4\n"; D4.display();
return 0;
OUTPUT:
19
OUTPUT :
20
21
cout<<line<<"\n";
cout<<line<<"\n";
filin1.close();
filin2.close();
return 0;
}
OUTPUT:
22
23
cout<<savac.name;
cout<<" has the balance amount of Rs."<<savac.balance<<"\n";
fin.close();
return 0;
}
OUTPUT:
24
25
int main()
{
ofstream fo("stu.dat", ios::app|ios::binary);
char ans='y';
while(ans=='y')
{
s1.getdata();
fo.write((char *) &s1,sizeof(s1));
cout<<"Record added to file \n";
cout<<"Want to enter more record?(y/n)..";
cin>>ans;
}
fo.close();
return 0;
}
OUTPUT:
26
Progra