Part I: Streamlining the Means and Mechanics of OOP In this part, you learn the basic concepts of objectoriented programming and how they apply to the C++ programming language.
Part II: Working with the Pre-Processor The C++ pre-processor is a powerful tool for customizing your application, making your code more readable, and creating portable applications. In this section, you get some handy ways to wring the most out of the pre-processor; some handy techniques explain how to create portable code, and the voice of experience reveals why you should avoid the assert macro.
Part III: Types The C++ language is rich in data types and userdefinable types. In this section, we explore using the built-in types of the language, as well as creating your own types that can be used just like the built-in ones. You find techniques in this section that explain structures and how you can use them. You also zero in on enumerations and creating default arguments for methods.
Part IV: Classes The core of the C++ programming language is the class. In this section, you get a look at how to create complete classes that work in any environment — as well as how to perform data validation and manipulation, create properties for your class, and inherit from other people’s classes.
Part V: Arrays and Templates Container classes are a core element of the Standard Template Library (STL), an important part of the C++ programming environment. In this section, you get the goods on working with the various container classes, as well as creating your own containers. Here’s where to find out how to iterate over a collection of objects, and how to allocate and De-allocate blocks of objects.
Part VI: Input and Output It would be a rare program indeed that did not have some form of input and output. After all, why would a user bother to run a program that could not be controlled in some way, or at least yield some sort of useful information? In this section, we learn all about various forms of input and output, from delimited file input to XML file output, and everything in between.
Part VII: Using the Built-in Functionality One hallmark of the C++ programming language is its extensibility and reusability. Why reinvent the wheel every time you write an application? C++ makes it easy to avoid this pitfall by providing a ton of built-in functionality. In this section, you get to use that built-in functionality — in particular, the C++ library and STL — to implement a complete internationalization class. You also get pointers on avoiding memory leaks, using hash tables, and overriding allocators for a container class.
Part VIII: Utilities
The single best way to learn C++ techniques is to look at the way that other people implement various
things. This section contains simple utilities that can sharpen your coding techniques, and it provides
valuable code that you can drop directly into your applications. You will find techniques here for
encoding and decoding data, converting data into a format that the World Wide Web can understand,
and opening a file using multiple search paths. Part IX: Debugging C++ Applications
One of the most important things to understand about programs is that they break. Things go wrong,
code behaves in unexpected ways, and users do things you (and sometimes they) didn’t intend.
C++ code to sort objects of a class
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<iomanip.h>
class stud
{
public:
int sno,s1,s2,s3,total;
void read();
void calc();
void print();
}s[50],t;
void stud::read()
{
cout<<endl<<"enter sno:";
cin>>sno;
cout<<"enter s1:";
cin>>s1;
cout<<"enter s2:";
cin>>s2;
cout<<"enter s3:";
cin>>s3;
}
void stud::print()
{
cout<<endl<<sno<<" "<<s1<<" "<<s2<<" "<<s3<<" "<<total;
}
void stud::calc()
{
total=s1+s2+s3;
}
void main()
{
int n;
clrscr();
cout<<"enter record no:";
cin>>n;
for(int i=0;i<n;i++)
s[i].read();
for(i=0;i<n;i++)
s[i].calc();
for(i=0;i<n;i++)
for(int j=0;j<n;j++)
{
if(s[i].total<s[j].total)
{
t=s[i];
s[i]=s[j];
s[j]=t;
}
}
for(i=0;i<n;i++)
s[i].print();
getch();
}
Create overloaded function reverse() to find reverse of a string and integer number
/*Create overloaded function reverse() to find reverse of a string
and integer number*/
#include<conio.h>
#include<iostream.h>
#include<string.h>
class test
{
public:
int a;
char b[50];
char c[50];
void reverse(int a);
void reverse(char b[]);
}t;
void test::reverse(int a)
{
int sum;
for(int i=1;a!=0;i++)
{
sum=a%10;
a=a/10;
cout<<sum;
}
}
void test::reverse(char b[])
{
strcpy(c,strrev(b));
cout<<endl<<c;
}
void main()
{
clrscr();
t.reverse(1000);
t.reverse("niraj");
getch();
}
/*Write a Class vector including data member as integer array of length five and member functions as: [a]. Parameterized constructor initialize data member [b]. Overloaded the + operator to add two vector and returning the result as vector. [c]. Overloaded the - operator to subtract two vector and returning the result as vector. [d]. Overloaded the * operator to perform scalar multiplication and returning the result as vector. [e]. A method to display the value of the vector. */
#include<iostream.h>
#include<string.h>
#include<conio.h>
class loc
{
public:
int a[5],sum[5];
loc(){}
loc(int b,int c,int d,int e,int f)
{
a[0]=b;
a[1]=c;
a[2]=d;
a[3]=e;
a[4]=f;
}
void show()
{
for(int i=0;i<5;i++)
cout<<sum[i]<<"\n";
}
loc operator+(loc &s);
loc operator-(loc &s);
loc operator*(loc &s);
};
loc loc::operator+(loc &s)
{
for(int i=0;i<5;i++)
{
s.sum[i]=a[i]+s.a[i];
}
return s;
}
loc loc::operator-(loc &s)
{
for(int i=0;i<5;i++)
{
s.sum[i]=a[i]-s.a[i];
}
return s;
}
loc loc::operator*(loc &s)
{
for(int i=0;i<5;i++)
{
s.sum[i]=a[i]*s.a[i];
}
return s;
}
void main()
{
clrscr();
loc ob1(10,20,30,40,50),ob2(10,20,30,40,50);
cout<<"\nthe overloaded operator +\n";
ob1=ob1+ob2;
ob1.show();
cout<<"\nthe overloaded operator -\n";
ob1=ob2-ob1;
ob1.show();
cout<<"\nthe overloded operator *\n";
ob1=ob2*ob1;
ob1.show();
getch();
}