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<<”welcome to the world of c +#”;
getch();
}
2) Write a program to demonstrate integer variables.
#include
#include
void main()
if
int varl;
int var2;
var1=20;
var2=varl+10;
clrser();
cout<<"var1+10 is”;
cout<
#include
void main()
{
een
int feemp; cltscr¢)*
cout<<"enter the ‘einbcrature in fahrenheit”;cin>>ftemp;
int ctemp=(ftemp-32)*5/9;
cout<<”equavalent in celsius is: ”<
#finclude
void main()
{
float rad;
const float pi=3.14159;
cout<<”enter the radius of the circle: ”;
cin>> rad;
float area=pi*rad*rad;
cout<
#include
#include
void main()
{
double number, answer; i
coute<’enter a number.) SCF C 2
ree
cin>>number;
answer= sqrt(number);
cout<<”square root is ”<
#tinclude
void main()
15; +4))
cout<
#tinclude
void main()
{
unsigned int numb;
unsigned long fact=1;
cout<<”\n enter a number:
cin>> numb;
for (int j-numb; j>0; j--)
fact=fact*j;
cout<<"factorial is ”<
#include
void main(){
long dividend, divisor;
char ch;
do
{
cout<<"enter dividen
cout<<"enter divisor: ”; cin>> divisor;
cout<<"remainder is ”<>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<<”enter a number: ”;
cin>>x;
iffx>100)
fi
cout<<”the number ”<
#include
void main()
{
char dir=’a’;
int x=10, y=10;
while(dir!="\r’)
i
cout<<”\n your location is ”<
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<<”enter the wno ”;
cin>>wno;
cout<<”enter the wname ”;
cin>>wname;
cout<<”enter the wtime ”;
cin>>wtime;
cout<4enter the rate”;
cin>>rate;totall);
}
void showdata()
{i
cout<<”\n wno is "<
#include
class para
{
int length;
int breadth;
int area;
public:
para(int |, int b)
{
length=!
breadtharea=length*breadth;
}
void show()
{ ~)
cout<<"the area is”<
#include
void main()
{
void ss();
clrser();
ss()j
getch();
t
void ss()
{
int a, b, sum;
cout<<”enter the value to a, b”;
cin>>a>>b;
sum=atb;
cout<<”the sum of two no is ”<
#include
void main()
{
void jp();
clrser();
ipl);
getch();
}
void jp()
(eee
int a,b,c,d,e, big;
cout<<”enter the value of a,b,c,d,e ”;
cin>>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<<”the bigger no is’<
#include
void main()
{inti, n;
cout<<”enter the value of n”;
cin>>n;
for(i; ic=n; i++)
cout<<™’the series is ”<
#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<<"x is”< 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<<” enter the rolino”;
cin>>rollno;
cout <<”enter name”;cin>>name;
cout<<” enter age ”;
cin>> age;
}
void show ()
{
cout<<”\n roll number is” < 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<<” enter the bookno fa
cout <<”ent
cin>>bookname;
cout<<”enter the author”;
cin>>author;
cout<<” enter the price aa
cin>>price;
}
void show ( )
{
cout<<”\n book no is” < 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<<” enter the employee no”;
cin>>eno ;
cout<<”enter the employee name ”;
cin> >ename;
cout<<” enter salary”;
cin>>salary;
}
void display( )
{
cout<<”employee no is ”< 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<<"enter the principle”;
cin>>p;
cout<<”enter the time ”
cin>>t;
cout<<"¢
cin>>r;
calculation();
enter the rate of interest ».
Void show()cout<<"\n principle is” <
#include
class pointer
{
int a,b,c,*%,*¥;
public:
void read()
{
cout<<"enter the values to a,b”;
cin>>a>>b;
x=8a;
y=&b;
cet x+y;
}
void show()
{
cout<<”the sum of two number is "<
#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<<"enter the val
cin>>p;
lue ofp”;cout<<"enter the value of t”;
cin;
cout<<’enter the value of r”;
cin>>r;
calculate();
}
void show()
{
cout<<” principle is” <
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<<"enter the rolino ”;
cin>>rolino;
cout<<”enter the name”;
cin>>name;
cout<<”enter the class ”;
cin>>clas;
cout<<”enter the marks of
cin>>phy>>chem>>math;
calculation();
}
void show()
{
cout<<”roll no is “ 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<<”enter the value of m1”;
cin>>m1;(4, Declare the
private member-worker no of int type, wo:
work time of int type, rate, pay of int tyne,
pay.
coutc<”enter the value of m2";
cin>>m2; 7
cout<<"enter the value of m3";
cin>>m3;
cout<<"enter the value of m4”;
cin>>m4;
cout<<”enter the value of m5”;
cin>>m5;
+R
calculatg();
}
void show()
{
cout<<”\n m1 is” < 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<<"enter the worker no”;
cin>>workerno;
cout<<"enter the worker name”;
cin>>wname;
cout<<”enter the rate”;
cin>>rate;
cout<<”enter work time”;
cin>>wtime;
total();
}
void show()
{
cout <<”\n worker no is” <
| # 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<<” enter the value of I”;
cin>>I;
cout<<” enter the value of b”;
cin>>b;
calculate();
}
void show()
{
cout <<"the length is” <
# 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<<” enter the value of I’;
cin>>I;
cout<<” enter the value of b”;
cin>>b;
calculate();
}
void show()
{
cout <<”\n | is”<
#include
class triangle
{
private :
int |;
int b;
float area;
void calculate()
{
area=0.5*I*b;
}
public:
void get()
{
cout<<” enter the value of |”;
cin>>1;
cout<<” enter the value of b”;
cin>>b;
calculate();
}
void show()
{
cout <<”\n lis”< 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<<”enter principle”;cin>>principle;
cout<<”enter rate”;
cin>>rate;
cout<<”enter time”;
cin>>time;
calculate();
}
void showdata() 7
{
cout <<”\n principle”< 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<<”enter principle”;
cin>>principle;
cout<<"enter rate”;
cin>>rate;
cout<<"enter time”;
cin>>time;
calculate(); /
}
void showdata ()
{
cout <<”\n principle”< 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<<”enter item no”;
cin>>itemno;
cout<<”enter item name”;
cin>>itemname;
cout<<"enter item price”;
cin>>itemprice;
}
void show()
{
cout<<”\n item no”<