All About C++

Get Pure Concepts of C++
Showing posts with label cplusplus. Show all posts
Showing posts with label cplusplus. Show all posts

Saturday, 2 July 2016

What is program development process|Defining & Analysis|Designing|Coding etc.

Program development process

To develop a computer program, a programmer has to go through the following stages.
·         Defining and Analyzing the problem
·         Designing the Algorithm
·         Coding or writing the program
·         Testing the program
·         Making final documentation
Let see the above stages in detail

Friday, 1 July 2016

What is Flowchart|Flowchart symbols|Limitations|Guidelines |Examples

Definition of Flowchart
Flowchart is the combination of two words which are ‘Flow’ and ‘Chart’. A charts consists of different symbols which display the information about any program and Flow indicates the direction of processing that information which takes place in a program.
Flowchart is the graphical representation of an algorithm. It indicates a way of visually presenting the flow of data, operations which are performed on that data and sequence of these operations. Flowchart is similar as layout plan of a building. As a designer of buildings draws a layout plan of the building before constructing it similarly a programmer designs the flowchart of a program before writing that program. It is designed according to defined rules and principles.
Symbols of Flowchart
Following are the symbols which are used to design a Flowchart:

Algorithm|Algorithm Properties|Advantages|Analysis

Algorithm

An algorithm is a step by step procedure to solve a problem. Steps of an algorithm are often called instructions. Process of solving any problem becomes easier with the use of Algorithm. It is better for programmer to write algorithm before writing actual computer program. Algorithms are used for calculations and data processing.

Informal definition:

An ordered sequence of instructions that is guaranteed to solve a specific problem is called algorithm.

Properties of Algorithm

Some basic properties of an algorithm are following:

Wednesday, 29 June 2016

What is program and computer programs and their advantages and disadvantages?


Big Program

Program

A program is a set of instruction that tells a computer what to do. Program is a detail process which commands to computer that how to process data to get information. Person who make program is called programmer. Programmer uses programming languages to make or write any program.








Computer Program

Computer Program in the form of a human-readable, computer programming language is called source code. Source code can be converted into an executable image by a compiled or executed immediately with the aid of an interpreter.
OR

Tuesday, 28 June 2016

What is problem solving and problem solving techniques

Problem Solving:
Problem Solving

                                           Problem solving is a process to identify a problem and finding the best solution for that problem.

Problem solving is a skill that can be developed by following a well organized approach.  In daily life, we face different types of problems and try to solve them with easy method.Different tools, strategies and techniques are used to solve a problem. Computers are used as a tool to solve complex problems by using computer programs.




Problem solving techniques are following:

Sunday, 26 June 2016

What is constructor in c++,default and argument constructor

Constructer without any argument (default constructor).
       Let name of class is “list” and “size” and “fill” are two data members(variables) and "arr" is array  in a class then constructor without argument will be                                                           
list :: list()
 {             size=10;
arr=new int [size];
             fill=-1;
 }
Here we give values to size=10, and fill=-1, this is a default constructer,
Constructer with one parameter.
Let name of class is “list” and “size” and “fill” are two data members (variables) and "arr" is array in a class then constructor with one argument will be
list :: list(int num)
 {            size=num;

Sunday, 5 June 2016

How to make copy constructor in C++,with code example

In copy constructor, we copy a constructor to another object. When we have to make a constructor with same values of attributes which another constructor have, then we use copy constructor technique.
I give an example code in C++ to understand copy constructor concept.

#include<iostream>
using namespace std;
class distancee
{ private:
int feet;

How to concatenate two or more strings of different objects in C++ with example code

In concatenation, we concatenate two or more strings together. Concatenation syntax in C++ is:
strcat(str1,str2);
Here:
str1 and str2 are two strings which are concatenated and the result is stored in left side’s string which is in above case is str1,so here result will be stored in str1.
Example Code:
In this example code strings which belong to two different objects are concatenated.

#include<iostream>
using namespace std;
#include<string>

Saturday, 4 June 2016

How to pass objects as parameters in the function with code example

We can pass objects as parameter in the functions.to use objects as parameter, we just pass the object’s name as in the case of array.
Let a1 and a2 are two objects and “add” is a function name then we will pass these objects as parameters as
add(a1,a2);
When we make function to pass objects as parameter then the data types of function attribute must be the name of that class in which we are making that function.
I explain this concepts using a complete code example
This code add, subtract and multiply two objects values

#include<iostream>
#include<math.h>
using namespace std;
class complex
{
private:
            float real;
            float imaginary;
public:
            complex():real(0),imaginary(0)
            {}
complex(float re,float im):real(re),imaginary(im)
{}
void add(complex a,complex b)
{float z;
            float x,y,k;
            z=a.real+b.real;
            x=-(a.imaginary);
            y=-(b.imaginary);
            k=sqrt(x)+sqrt(y);
            cout<<endl<<"addition is  "<<z<<"+"<<k<<"i"<<endl;
}
void subtruct(complex s,complex w)
{float z;
            float x,y,k;
            z=s.real-w.real;
            x=-(s.imaginary);
            y=-(w.imaginary);
            k=sqrt(x)-sqrt(y);
            cout<<endl<<"subtrucrtion is  this"<<endl<<z;
if(k>=0)
{cout<<"+"<<k<<"i"<<endl;}
else
{cout<<"-"<<k<<"i"<<endl;}}
void product(complex f1,complex f2)
{float z;
            float x,y,k,o,t,r1,r2;
            z=f1.real*f2.real;
            x=-(f1.imaginary);
                        y=-(f2.imaginary);
                        k=(f1.real)*(sqrt(y));
                        o=(f2.real)*(f1.imaginary);
                        t=x*y;
                        r1=z+t;
                        r2=k+o;
                        cout<<endl<<"production is this   "<<r1;
                        if(r2>=0)
                        {
                                    cout<<"+"<<r2<<endl;}
                        else
                        {cout<<"-"<<r2<<endl;}}
void getdata()
{
cout<<"enter real and imaginary  ";
            cin>>real>>imaginary;}
};
void main()
{
             complex i(12.2,-25.3);
            complex e1,e2,e3,e4;
            e1.getdata();
            e2.add(i,e1);
            e3.subtruct(i,e1);
            e4.product(i,e1);
             system("pause");}

Here:
void add(complex a,complex b);
void subtruct(complex s,complex w);
void product(complex f1,complex f2);

These are the function declaration method to use objects as parameters and here complex is the name of class in which these functions are made.

And
            e2.add(i,e1);
            e3.subtruct(i,e1);
            e4.product(i,e1);
Here functions are called in which objects are passed as parameters;
Here i, e1, e2 and e3 are objects names.








Friday, 3 June 2016

Operator overloading in C++ with code example

Operator overloading
Operator overloading is a technique in C++ where we overload an operator. Here operators are <,>,>=, <= or  =.
The true concept about operator overloading is that using operator overloading scheme we manipulate or interact two objects  . For example we add the attributes of two different objects etc.
I give an example to understand the overloading concept
In this example, two different distances belong to two different objects and they are added through operator overloading
#include<iostream>
using namespace std;
class distancee
{ private:
int feet;
float inches;
public:
       distancee( ):feet(0),inches(0.0)
            { }
      distancee(int ft,float in) : feet(ft),inches(in)
      {  }
     
      void getdist()
      {
            cout<<"enter feet";
            cin>>feet;
            cout<<"enter inches";
            cin>>inches;
      }
      void showdist() const
      { cout<<feet<<inches<<endl; }
      void operator +=(distancee);
};
void distancee::operator += (distancee d2)
{
      feet += d2.feet;
      inches +=d2.inches;
      if(inches >= 12.0)
      {
            inches -= 12.0;
            feet++;
      }
};
int main()
{
      distancee dist1;
      dist1.getdist();
      cout<<"dist1";
      dist1.showdist();
      distancee dist2(11,6.35);
      cout<<"dist2";
      dist2.showdist();
      dist1+=dist2;
      cout<<"after addition";
      cout<<"dist1";
      dist1.showdist();
      cout<<endl;
      return 0;
}

In this code here we manipulate two different objects attributes together

feet += d2.feet;
       inches +=d2.inches;
       if(inches >= 12.0)
       {
              inches -= 12.0;
              feet++;}
Here:
feet and d2.feet indicates two different objects values


Tuesday, 1 March 2016

What is function overloading is C++ with code example

Function overloading is C++

In function overloading two or more different functions share exactly the same name. That is because in C++  a function is identified by its signature which comprises both the function's name and the list of arguments it takes. Hence the following code is perfectly fine.

#include <iostream>

What is concatenation between strings in C++ with code example

Concatenation between strings in C++

Concatenation combines two or more strings together. Here is a code to understand its concept:

#include <iostream>
#include <string>

Monday, 29 February 2016

What is namespace std in C++ with example code

What is namespace std in C++

Std is a namespace which is built-in in library files of C++. Std deals with the cin and cout.that is std tells to compiler that what is cin and cout.

A simple example of std to understand its concept

#include <iostream>

What is OOP(Object Oriented Programing) in computer Language

What is OOP?
                                  
                            Object oriented programming(OOP)  is a fairly new way to approach the task of programming. It supersedes the so called procedural or structured programming languages like Algol, Pascal or C, that have been around since the 1960s. In short, it is the latest version of C. The essence of structured programming is to

Wednesday, 10 February 2016

What is singly link list in data structure

Singly link list

In Singly link list every previous node has address of its next node.address of first node is in head and address part of last node is NULL.

Structure of a singly link list is

Struct node
{int data;

what is link list in data structure C++

link list in data structure:
                                           
                                  Link list is a way to store data following a specific method.in link list we link elements with each other.
Every element is saved in a specific node and every node contains two parts,one is data part and other is

how to add,remove and display data from singly link list in data structure

An example of singly link list with the function of insertion, deletion and display
#include<iostream>
#include<conio.h>
using namespace std;
struct node
{
            int data;
            node *next;

how To show data in singly link list in data structure with the example of source code

To display the data from singly link list
Here is a function to display data from single link list
void show()
                        {
            link *temp;
            temp= first;

how To delete data from singly link list in data structure with the example of source code

To delete a node from start, end or mid from singly link list

Below is a source code to delete data from single link list

void delnode()           //deleting
{  node *temp1,*temp2,*temp3;
   
    char d;

how To add data in singly link list in data structure with the example of source code

To add data in singly link list

Using following technique we can easily add data in single link list

#include<iostream>
#include<conio.h>
using namespace std;
struct link
{
    int data;