C++ is an object-oriented programming language developed by Bjarne Stroustrup in the early 1980s as an extension of C, incorporating features from Simula67. It includes major additions like classes, inheritance, and function overloading, and was standardized by the ANSI/ISO committee in 1997. The document also provides various example programs demonstrating C++ syntax and features.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0 ratings0% found this document useful (0 votes)
2 views
C++.CPP (programing language)
C++ is an object-oriented programming language developed by Bjarne Stroustrup in the early 1980s as an extension of C, incorporating features from Simula67. It includes major additions like classes, inheritance, and function overloading, and was standardized by the ANSI/ISO committee in 1997. The document also provides various example programs demonstrating C++ syntax and features.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 32
what is c++ ?
c++ is an object-oriented programming language. it was developed by bjarne
stroustrupat at& t bell laboratories in murray hill, new jersey, usa in the early
1980’s. strrousptrup, an admirer of simula67 and a strong supporter of c,
wanted to combine the best of the language and create a more powerful
language that could support object-oriented programming featured and still
retain the power and elegance of c. the result was c++ . therefore, c++ is
an extension of c with major addition of the class construct feature of f
simula67. since the class was a major addition to the original ¢ language,
stroustrup initially called the new language ‘c with classes’. however, later
in 1983, the name was changes to c++. the idea of c++ comes from the c
increment operator ++, thereby suggesting that c++ is an augmented
(incremented) version of c.
during the early 1990°s the language underwent a number of improvement
and changes. in november 1997, the ansi\iso standards committee
standardized these changes and added several new features to the languages
specifications.
c++ is a superset of c. most of what we already know about ¢ applies to c++
also. therefore almost all ¢ programs are also c++ programs. however, there
a few minor differences that will prevent a c program to run under c++
compiler. we shall see these differences later as and when they are
encountered.
the most important facilities that c++ adds on tro c are classes, inheritance,
function-overloading.
Page 1Cncteger_ coments )
() Write a program to demonstrate Simple message in c++. )
#include
#include
void main()
{
cout
#include
void main()
if
int varl;
int var2;
var1=20;
var2=varl+10;
clrser();
cout
#include
void main()
{
een
int feemp; cltscr¢)*
cout>ftemp;
int ctemp=(ftemp-32)*5/9;
cout
#finclude
void main()
{
float rad;
const float pi=3.14159;
cout> rad;
float area=pi*rad*rad;
cout
#include
#include
void main()
{
double number, answer; i
coute>number;
answer= sqrt(number);
cout
#tinclude
void main()
15; +4))
cout
#tinclude
void main()
{
unsigned int numb;
unsigned long fact=1;
cout> numb;
for (int j-numb; j>0; j--)
fact=fact*j;
cout
#include
void main(){
long dividend, divisor;
char ch;
do
{
cout> divisor;
cout>ch;
}
while(ch!='n’);
getch();
Z
, cin>> dividend;
9) Write the program to demonstrate multiple statement in the if body.
#include
#include
void main()
{
int x;
cout>x;
iffx>100)
fi
cout
#include
void main()
{
char dir=’a’;
int x=10, y=10;
while(dir!="\r’)
i
cout
Htinclude
#includecstring.h>
class worker
{
private:
‘int wno;
char wname[30];
int wtime;
int rate;
int pay;
void total()
{
pay=(wtime* rate);
}
public:
worker()
{
wno=1;
strcpy(wname,”abc”);
wtime=3;
rate=G0
} 5
void getdata()
{
cout>wno;
cout>wname;
cout>wtime;
cout>rate;totall);
}
void showdata()
{i
cout
#include
class para
{
int length;
int breadth;
int area;
public:
para(int |, int b)
{
length=!
breadtharea=length*breadth;
}
void show()
{ ~)
cout
#include
void main()
{
void ss();
clrser();
ss()j
getch();
t
void ss()
{
int a, b, sum;
cout>a>>b;
sum=atb;
cout
#include
void main()
{
void jp();
clrser();
ipl);
getch();
}
void jp()
(eee
int a,b,c,d,e, big;
cout>a>>b>>c>>d>>e;
big=a;
if(b>big)
big=b;
if(c>big)
big=c;
if(d>big)
big=d;
if(e>big) ~
big=e;
cout
#include
void main()
{inti, n;
cout>n;
for(i; ic=n; i++)
cout
#include
class sample
{
int x, y;
public:
sample(int a, int b)
4
x=a;
}
sample(sample &p)
af
X=p.x;
Y=P-Y;,
}
void show()
{
cout function to read data as input
roll no, name, age
show () -> function to display
roll no, name, age
# include
# include
class students
{
private :
int rolino;
char name [10]; 2,
int age;
public:
void read ()
t
cout>rollno;
cout >name;
cout> age;
}
void show ()
{
cout function to enter the detail of book
show ()-> function to display the detail of a book
@ Declare a class student with the following specification
# include
# include
class book
{
pfivate
int bookno;
char bookname[10];
char author [10];
float price;public:
void get ()
{
cout
cin>>bookno; a
er the book name;
t>bookname;
cout>author;
cout>price;
}
void show ( )
{
cout function to enter
display()-> function to display
salary 0# include
# include
class employee
{
private :
int eno;
char ename[10];
float salary;
public:
void enter()
{
cout>eno ;
cout >ename;
cout>salary;
}
void display( )
{
cout function to enter P!
calculation
show data()-> display all the details.
#include
#include
class si
{
private:
float p;
int t;
float r;
float interest;
void calculation()
{
interest=(p*t*r)/100;
}
public:
void get()
{
Cout>p;
cout>t;
cout>r;
calculation();
enter the rate of interest ».
Void show()cout
#include
class pointer
{
int a,b,c,*%,*¥;
public:
void read()
{
cout>a>>b;
x=8a;
y=&b;
cet x+y;
}
void show()
{
cout
#include
class si
{
private:
float p;
int t;
float r;
float interest;
float total;
void calculate()
{
interest=(p*t*r)/100,
total=p+ interest;
}
public:
void get()
{
cout>p;
lue ofp”;cout>r;
calculate();
}
void show()
{
cout function to enter the detail
show()-> function to displayHinclude
# include
class student
{
private :
int rollno;
char name [30];
char clas [12];
int phy, chem, math;
float percentage;
void calculation()
{
percentage=( phy + chem+ math)/3;
}
publi
void get()
4 scjacercyt .
cout>rolino;
cout>name;
cout>clas;
cout>phy>>chem>>math;
calculation();
}
void show()
{
cout function to enter the number and invoice the
calculate()
show ()-> function to display.
#include
# include
class math
if
private :
int m1;
int m2;
int m3;
int m4;
int m5;
float average;
void calculate()
{
average=( m1+m2+m3+m4+m5)/5;
}
public:
void get()
{
cout>m1;(4, Declare the
private member-worker no of int type, wo:
work time of int type, rate, pay of int tyne,
pay.
coutc>m2; 7
cout>m3;
cout>m4;
cout>m5;
+R
calculatg();
}
void show()
{
cout function to enter data
show data()-> function to display
#include
# include
class worker
{
private :
int workerno;
char wname [30];
int wtime;
int rate;
int pay;
void total()
{
pay=(wtime*rate);
}
public:
void get()
{
cout>workerno;
cout>wname;
cout>rate;
cout>wtime;
total();
}
void show()
{
cout
| # include
class rectangle
{
private:
int |;
int b;
float area;
float parameter;
void calculate()
{
area=(I*b)5
parameter=I*(I+b);
}
public:
void get()
{cout>I;
cout>b;
calculate();
}
void show()
{
cout
# include
class rectangle
{
private :
int |;
int b;float area;
float parameter; ;
void calculate()
t
area=(I*b) 5
parameter=2*(I+b);
}
public:
void get()
{
cout>I;
cout>b;
calculate();
}
void show()
{
cout
#include
class triangle
{
private :
int |;
int b;
float area;
void calculate()
{
area=0.5*I*b;
}
public:
void get()
{
cout>1;
cout>b;
calculate();
}
void show()
{
cout display aly
the details
#include
#include
class si
{
private :
int principle,si;
float rate;
float time;
int interest;
void calculate()
{
interest=( principle*rate*time)/100;
Z
public:
si()
{
principle= 1000;
time=2;
}
void getdata()
{
cout>principle;
cout>rate;
cout>time;
calculate();
}
void showdata() 7
{
cout function to enter principal
4 i show data ()-> display all the details
#include
#include
class si
a Peat ‘i{
private :
float principle;
float rate;
int interest,time;
void calculate()
{
interest=( principle*rate*time)/100;
:
public:
si()
{
principle= 1000;
rate= 5;
time=2;
}
void getdata()
{
cout>principle;
cout>rate;
cout>time;
calculate(); /
}
void showdata ()
{
cout readdata
show-> display all
#include
#include
#include
class sample
{
private:
int itemno;
char itemname[30)];
float itemprice;
public:
sample()
f
itemno=1;
strepy(itemname, “shirt”);
itemprice=500;
page 3!}
void read()
{ 4
cout>itemno;
cout>itemname;
cout>itemprice;
}
void show()
{
cout