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;