Showing posts with label cpp programs. Show all posts
Showing posts with label cpp programs. Show all posts

Cpp program addition of two complex number operator overloading | cpp programs | cpp class example

What is CPP?

Cpp programming  (pronounced see plus plus) is general-purpose programming language. Cpp programming is regarded as a "middle-level" language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell Labs as an enhancement to the C programming language and originally named C with Classes. It was renamed Cpp programming in 1983.
As one of the most popular programming languages ever created, C++  programming is widely used in the software industry. Some of its application domains include systems software, application software, device drivers, embedded software, high-performance server and client applications, and entertainment software such as video games.  


Here you will find cpp programs and cpp class example.This is just example you can modify this cpp class example.

cpp programs

cpp class example for how do addition of two complex number using CPP

/***************************
      author-Nikunj v Gandhi
      from-gujarat(surat)
      Web Developer(ZCE)
      email-nik_gandhi007@yahoo.com
      http://my-source-codes.blogspot.com/
      Description: cpp class example for addition of two complex 
      number using operator overloading
      ******************************************** */

       #include<iostream.h>
       #include<conio.h>
       #include<math.h>
       class complex
  {
    float real;
    float imag;
    public:
     complex()
      {
        real=imag=0.0;
      }
     complex(float real1 ,float imag1=0.0)
       {
  real=real1;
  imag=imag1;
        }
     void input()
      {
        cout<<"Enter real part?";
        cin>>real;
        cout<<"enter imaginary part of complex number?";
        cin>>imag;
      }
     void show()
        {
   cout<<real;
   if(imag<0)
      cout<<"-i";
   else
     cout<<"+i";
   cout<<fabs(imag);
       }
     complex add(complex c2);
    };
    complex complex::add(complex c2)
       {
        complex temp;
        temp.real=real+c2.real;
        temp.imag=imag+c2.imag;
        return(temp);
       }
    void main()
      {
        clrscr();
        complex c1(1.5,2.0);
        complex c2(2.2);
        int i=0;
        cout<<"What do you want?n";
        cout<<"Input data or you want to Used Initilized datan";
        cout<<"If you want to input data then enter 1 otherwise 0 ? ";
        cin>>i;
        if(i==1)
   {
     cout<<"Enter value for first object?n";
     c1.input();
     cout<<"Enter value for second object?n";
     c2.input();
   }
        cout<<"n";
        c1.show();
        cout<<"n";
        c2.show();
        cout<<"n";
        cout<<"---------------n";
        complex c3;
        c3=c1.add(c2);
        c3.show();
        getch();
    }

Buy Me a Beer-If you are like this post

 If you does not have paypal account create free account create account

Cpp Program concatenation of string and compare two string with the help of operator overloding

Cpp programming  (pronounced see plus plus) is general-purpose programming language. Cpp programming is regarded as a "middle-level" language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell Labs as an enhancement to the C programming language and originally named C with Classes. It was renamed Cpp programming in 1983.
As one of the most popular programming languages ever created, C++  programming is widely used in the software industry. Some of its application domains include systems software, application software, device drivers, embedded software, high-performance server and client applications, and entertainment software such as video games.  


cpp programs

 Here you will find cpp programs and cpp class example.This is just example you can modify this cpp class example.


cpp class example for how to do concatenation of string and compare two string with the help of operator overloding
/***************************
      author-Nikunj v Gandhi
      from-gujarat(surat)
      Web Developer(ZCE)
      email-nik_gandhi007@yahoo.com
      http://my-source-codes.blogspot.com/
      Description:CPP program- to concatenation of string and compare two string
      with the help of operator overloding in cpp operator == 
      for compare and + for concate

      ******************************************** */
      #include<conio.h>
     #include<iostream.h>
     #include<stdio.h>
     #include<string.h>
     const int size=50;
     class string
 {
   char str[size];
   public:
     string()
       {
  strcpy(str," ");
       }
     string(int n)
      {
       if(n==0)
    cout<<"nnBOTH THE STRING IS SAMEn";
       else
   cout<<"nnBOTH THE STRING IS NOT SAMEn";
      }
     string(char *mystr)
       {
  strcpy(str,mystr);
       }
     void input()
      {
       cout<<"Enter string?";
       gets(str);
      }
     string operator +(string s)
       {
  string temp=str;
  strcat(temp.str,s.str);
  return temp;
       }
     string operator ==(string s1)
       {
  int n;
  string temp1=str;
  n=strcmp(temp1.str,s1.str);
  return n;
       }
     void echo()
      {
       cout<<str;
      }
   };
   void main()
     {
       clrscr();
       string s1;
       cout<<"nstring 1n";
       s1.input();
       string s2;
       cout<<"nstring 2n";
       s2.input();
       string s3;
       s3=s1+s2;
       cout<<"AFTER CONCATE BOTH STRING IN 3rd STRING:";
       s3.echo();
       s1==s2;
       getch();
    }

Buy Me a Beer-If you are like this post

 If you does not have paypal account create free account create account

how to create inheritance using c++

What is CPP?

Cpp programming  (pronounced see plus plus) is general-purpose programming language. Cpp programming is regarded as a "middle-level" language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell Labs as an enhancement to the C programming language and originally named C with Classes. It was renamed Cpp programming in 1983.
As one of the most popular programming languages ever created, C++  programming is widely used in the software industry. Some of its application domains include systems software, application software, device drivers, embedded software, high-performance server and client applications, and entertainment software such as video games.  






Cpp practice work example,Cpp class example,CPP example,cpp class example,cpp programs


Here you will find cpp programs and cpp class example.This is just example you can modify this cpp class example.


cpp programs

cpp source codes for how to create inheritance using CPP

/******************************************
      author-Nikunj v Gandhi
      from-gujarat(surat)
      Web Developer(PHP ZCE)
      email-nik_gandhi007@yahoo.com
      http//my-source-codes.blogspot.com
      description:how to use inheritance using c++ language  
      *******************************************/
 
      #include<conio.h>
      #include<stdio.h>
      #include<nik.h>
      #include<iostream.h>
      class person
 {
   char name[50],gen[6];
   int age;
   public:
     person(){}
     void get_info();
     void put_info();
 };
      void person::get_info()
 {
   cout<<"Enter the name of person?";
   gets(name);
   cout<<"Enter the gender of person?";
   cin>>gen;
   cout<<"Enter the age of person?";
   cin>>age;
 }
     void person::put_info()
      {
 cout<<name<<"t";
 cout<<gen<<"t";
 cout<<age<<"t";
      }
      class employee:protected person
       {
  int empid;
  long sal;
  char des[20];
  public:
    employee(){}
    void get_info();
    void put_info();
 };
      void employee::get_info()
 {
   person::get_info();
   cout<<"Enter emp id?";
   cin>>empid;
   cout<<"Enter salary?";
   cin>>sal;
   cout<<"Enter designation?";
   gets(des);
 }
     void employee::put_info()
       {
  person::put_info();
  cout<<empid<<"t";
  cout<<sal<<"t";
  cout<<des<<"n";
       }
     class student:protected person
       {
  int studid;
  char class_name[10];
  public:
   void get_info();
   void put_info();
 };
     void student::get_info()
       {
  person::get_info();
  cout<<"Enter stud id?";
  cin>>studid;
  cout<<"enter student class name?";
  gets(class_name);
       }
     void student::put_info()
       {
  person::put_info();
  cout<<studid<<"t";
  cout<<class_name<<"n";
 }
     void main()
      {
 clrscr();
 nik();
 employee e;
 cout<<"nnENTER EMPLOYEE INFORMATIONnn";
 e.get_info();
 student p;
 cout<<"nnENTER STUDENT INFORMATIONnn";
 p.get_info();
 cout<<"n NAMEtGENDERtAGEtEMPIDtSALARYtDESIGNATIONn";
 e.put_info();
 cout<<"n NAMEtGENDERtAGEtSTUDIDtCLASS NAMEn";
 p.put_info();
      }

Buy Me a Beer-If you are like this post

 If you does not have paypal account create free account create account

c++ program count words from file | cpp programs

What is CPP?

Cpp programming  (pronounced see plus plus) is general-purpose programming language. Cpp programming is regarded as a "middle-level" language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell Labs as an enhancement to the C programming language and originally named C with Classes. It was renamed Cpp programming in 1983.
As one of the most popular programming languages ever created, C++  programming is widely used in the software industry. Some of its application domains include systems software, application software, device drivers, embedded software, high-performance server and client applications, and entertainment software such as video games.  


Here you will find cpp programs and cpp class example.This is just example you can modify this cpp class example.

cpp programs

Cpp practice work example

cpp source codes for count word from txt file

/* ********************************************************************
      This cpp program counts word from file.
     author-Nikunj v Gandhi
      from-gujarat(surat)
      Web Developer(PHP ZCE)
      email-nik_gandhi007@yahoo.com
      http//my-source-codes.blogspot.com
      ******************************************************************** */

 #include<fstream.h>
   #include<stdio.h>
   #include<string.h>
   #include<conio.h>
   class word
    {
       char *str;
       public:
 word()
   {
     str="nikunj v gandhi";
   }
 word(char *string)
   {
     strcpy(str,string);
   }
 void input()
   {
      cout<<"Enter string?";
      gets(str);
   }
      void exword();
   };
   void word::exword()
       {
     int len=strlen(str);
     str[len]=' ';
     ofstream out("z:/cpp/cppfile/countword.txt"); /* change path according to your computer path*/
     out<<str;
     out.close();
     ifstream in("z:/cpp/cppfile/countword.txt");  /* change path according to your computer path*/
     char ch;
     char substr[20];
     int i,j=0,p,m=0;
     int k;
     while(in)
       {
   in.get(ch);
   if(ch==32)
     {
       m++;
       if(m==1)
         {
    substr[j]='\0';
    p=0;
    while(substr[p]!=0)
      {
         cout<<substr[p];
         p++;
       }
     cout<<"\n";
     substr[0]='\0';
     j=0;
     m++;
   }
       }
       else if(ch!=32)
         {
   m=0;
   substr[j]=ch;
   j++;
       }
  }

     in.close();
  }
     void main()
      {
 clrscr();
 word w("nikunj v gandhi ");
 w.input();
 w.exword();
 getch();
      }

Buy Me a Beer-If you are like this post

 If you does not have paypal account create free account create account