Wednesday, August 19, 2015

this pointer : Part (A)

The ‘this’ pointer is passed as a hidden argument to all nonstatic member function calls and is available as a local variable within the body of all nonstatic functions. ‘this’ pointer is a constant pointer that holds the memory address of the current object. ‘this’ pointer is not available in static member functions as static member functions can be called without any object (with class name).
For a class X, the type of this pointer is ‘X* const’. Also, if a member function of X is declared as const, then the type of this pointer is ‘const X *const’
Following are the situations where ‘this’ pointer is used:
1) When local variable’s name is same as member’s name
#include<iostream>

/* local variable is same as a member's name */
class Test
{
private:
   int x;
public:
   void setX (int x)
   {
       // The 'this' pointer is used to retrieve the object's x
       // hidden by the local variable 'x'
       this->x = x;
   }
   void print() { cout << "x = " << x << endl; }
};
int main()
{
   Test obj;
   int x = 20;
   obj.setX(x);
   obj.print();
   return 0;
}

Thursday, August 13, 2015

Modeling in OOPS:OMT

Object Modeling Technique (Rumbaugh, 1991) was developed as an approach to software development. A fundamental assumption of OMT is that object-oriented thinking represents a more natural and intuitive way for people to reason about reality.
The purposes of modeling according to Rumbaugh are
  • testing physical entities before building them (simulation),
  • communication with customers,
  • visualization (alternative presentation of information), and
  • Reduction of complexity.
As a general modeling approach, OMT may be used to model all types of work. OMT proposes three main types of models:
  • Object model
The object model represents the static and most stable phenomena in the modeled domain. Main concepts are classes and associations, with attributes and operationsAggregation and generalization (with multiple inheritances) are predefined relationships.
  • Dynamic model
The dynamic model represents a state/transition view on the model. Main concepts are statestransitions between states, and events to trigger transitions. Actions can be modeled as occurring within states. Generalization and aggregation (concurrency) are predefined relationships.
  • Functional model
The functional model handles the process perspective of the model, corresponding roughly to data flow diagrams. Main concepts are processdata storedata flow, and actors.
The entire OMT software development process has four phases: Analysis, system design, object design, and implementation of the software. Most of the modeling is performed in the analysis phase. The recommended method incorporates the following activities :
1.     Develop a Problem Statement.
2.     Build an Object Model:
1.     Identify object classes.
2.     Develop a data dictionary for classes, attributes, and associations.
3.     Add associations between classes.
4.     Add attributes for objects and links.
5.     Organize and simplify object classes using inheritance.
6.     Test access paths using scenarios and iterate the above steps as necessary.
7.     Group classes into modules, based on close coupling and related function.
3.     Build a Dynamic Model:
1.     Prepare scenarios of typical interaction sequences.
2.     Identify events between objects and prepare an event trace for each scenario.
3.     Prepare an event flow diagram for the system.
4.     Develop a state diagram for each class that has important dynamic behavior.
5.     Check for consistency and completeness of events shared among the state diagrams.
4.     Build a Functional Model:
1.     Identify input and output values.
2.     Use data flow diagrams as needed to show functional dependencies.
3.     Describe what each function does.
4.     Identify constraints.
5.     Specify optimization criteria.
5.     Verify, iterate, and refine the three models:
1.     Add most important operations to the object model.
2.     Verify that classes, associations, attributes and operations are consistent and complete, check with problem statement.
3.     Iterate steps to complete the analysis.


Wednesday, August 12, 2015

To find the roots of a quadratic equation

/* PROGRAM TO COMPUTE THE ROOTS OF THE QUADRATIC EQUATION */
#include<iostream.h>
#include<conio.h>
#include<math.h>
int main()
{
float a,b,c;
clrscr();
cout<<"Enter Coefficients of the equation"<<endl;
cin>>a>>b>>c;
if(a==0)
{
cout<<"\n This is not a quadratic equation ";
return 0;
}
cout<<"\n The equation is ::"<<a<<"x^2+"<<b<<"x+"<<c<<"=0\n";
double d,x1,x2,d2;
d=(b*b)-(4*a*c);
if(d<0)
{
//cout<<"\n This equation has no real solution"<<endl;
d=((-1)*(d));
d2=sqrt(d);
x1=(-b)/(2*a);
x2=(d2)/(2*a);
cout<<"\n The roots are :: "<<x1<<"+"<<x2<<"i"<<" & "
<<x1<<"-"<<x2<<"i"<<endl;
cout<<"\n Where 'i' is Euler's Number"<<endl;
getch();
return 0;
}
d2=sqrt(d);
x1=(-b+d2)/(2*a);
x2=(-b-d2)/(2*a);
cout<<"\n The roots are :: "<<x1<<" & "<<x2<<endl;
getch();
return 0;
}


A Brief History of C++

The C++ programming language has a history going back to 1979, when Bjarne Stroustrup was doing work for his Ph.D. thesis. One of the languages Stroustrup had the opportunity to work with was a language called Simula, which as the name implies is a language primarily designed for simulations. The Simula 67 language - which was the variant that Stroustrup worked with - is regarded as the first language to support the object-oriented programming paradigm. Stroustrup found that this paradigm was very useful for software development, however the Simula language was far too slow for practical use.
Shortly thereafter, he began work on "C with Classes", which as the name implies was meant to be a superset of the C language. His goal was to add object-oriented programming into the C language, which was and still is a language well-respected for its portability without sacrificing speed or low-level functionality. His language included classes, basic inheritance, inlining, default function arguments, and strong type checking in addition to all the features of the C language.

The first C with Classes compiler was called Cfront, which was derived from a C compiler called CPre. It was a program designed to translate C with Classes code to ordinary C. A rather interesting point worth noting is that Cfront was written mostly in C with Classes, making it a self-hosting compiler (a compiler that can compile itself). Cfront would later be abandoned in 1993 after it became difficult to integrate new features into it, namely C++
exceptions. Nonetheless, Cfront made a huge impact on the implementations of future compilers and on the Unix operating system.

In 1983, the name of the language was changed from C with Classes to C++. The ++ operator in the C language is an operator for incrementing a variable, which gives some insight into how Stroustrup regarded the language. Many new features were added around this time, the most notable of which are
 virtual functions, function overloading, references with the & symbol, the const keyword, and single-line comments using two forward slashes (which is a feature taken from the language BCPL).
In 1985, Stroustrup's reference to the language entitled The C++ Programming Language was published. That same year, C++ was implemented as a comercial product. The language was not officially standardized yet, making the book a very important reference. The language was updated again in 1989 to include protected and static members, as well as inheritance from several classes.
In 1990, The Annotated C++ Reference Manual was released. The same year, Borland's Turbo C++ compiler would be released as a commercial product. Turbo C++ added a plethora of additional libraries which would have a considerable impact on C++'s development. Although Turbo C++'s last stable release was in 2006, the compiler is still widely used.

In 1998, the C++ standards committee published the first international standard for
 C++ ISO/IEC 14882:1998, which would be informally known as C++98. The Annotated C++ Reference Manual was said to be a large influence in the development of the standard. The Standard Template Library, which began its conceptual development in 1979, was also included. In 2003, the committee responded to multiple problems that were reported with their 1998 standard, and revised it accordingly. The changed language was dubbed C++03.
In 2005, the C++ standards committee released a technical report (dubbed TR1) detailing various features they were planning to add to the latest C++ standard. The new standard was informally dubbed C++0x as it was expected to be released sometime before the end of the first decade. Ironically, however, the new standard would not be released until mid-2011. Several technical reports were released up until then, and some compilers began adding experimental support for the new features.

In mid-2011, the new C++ standard (dubbed C++11) was finished. The Boost library project made a considerable impact on the new standard, and some of the new modules were derived directly from the corresponding Boost libraries. Some of the new features included regular expression support (details on regular expressions may be found here), a comprehensive randomization library, a new C++ time library, atomics support, a standard threading library (which up until 2011 both C and C++ were lacking), a new for loop syntax providing functionality similar to for each loops in certain other languages, the auto keyword, new container classes, better support for unions and array-initialization lists, and variable templates.