Search This Blog

Read Your Language

Showing posts with label C PLUS PLUS. Show all posts
Showing posts with label C PLUS PLUS. Show all posts

All int size of C++

               All int size of C++ 



Programming में  int  का एक साइज Defined होता है अगर आप उस साइज से ज्यादा  मेमोरी स्टोर कराते है तो आपका परिणाम इस प्रकार होगा | 

Program in C++


#include<iostream >

using namespace std;

main()

{

short signed int i;

short unsigned int j;

        unsigned long int k;

        long int z;

i=32768;  // a signed short integer

j=65536;    // an unsigned short integer

        z=2147483648;

        k=4294967296;

   

 cout << i <<  "\n"<< j <<"\n"<<z<<"\n"<< k;

  return 0;

}

OUTPUT: 

-32768
0
-214743648
0


Write the Factorial Program in C++.




Write the Factorial Program  in C++.



We knows that factorial no is the self divided or only 1. Factorial no  is find the C++ you have three variable.
1) Ist variable is fact=1 because factorial no has  last no is the 1.
2) 2nd variable is User defiend input  n numbers. 
3) 3rd variable is  i number has factorial increment of the numbers .


/*  Write the Factorial Program  in C++ */

#include<iostream>
using namespace std;
main()
{
int fact=1,i,n;
cout<<"Enter the factorial no is :"<<endl;
cin>>n;
for(i=1;i<=n;i++)
fact=fact*i;
cout<<"your  Enter factorial "<<n<<" is the :"<<fact;
}

OUTPUT:

Enter the factorial no is :
4
your  Enter factorial 4 is the : 24

Display the marks scored by a student in the final semester examination

Write a C++ program to display the marks scored by a student in the final semester examination. The student appears in exams of Math, Science, Hindi,English and Computer Application courses in the final semester. Each course isof 100 marks. Define proper class, constructor and method(s) in your program.Make necessary assumptions required.


#include<iostream>
using namespace std;
class student {
public:
int roll_no;
int  math ;
int  science;
int  hindi;
int  computer_science;
int  english;

student(int r,int m ,int s,int h,int c,int e)
{
roll_no=r;
math=m;
science=s;
hindi=h;
computer_science=c;
english=e;

}
       display()
  {
  cout<<"Roll_no is :"<<roll_no<<endl<<"math no is:"<<math<<endl<<"science no is:"<<science<<endl<<"hindi no is:"<<hindi<<endl<<"computer science no is:"<<computer_science<<endl<<"english no is :"<<english<<endl;
  int total_marks;
  total_marks=math+science+hindi+computer_science+english;
  cout<<"Roll_no"<<roll_no<<" has 500 in  the total marks:"<<total_marks<<endl;
  }

};

 main()
 {
  student st1(1,45,56,59,47,97);
  st1.display();

 }

OUTPUT:
Roll_no is : 1`
math no is : 45
science no is : 59
hindi no is : 59
computer_science no is : 47
english no is : 97
Roll_no 1 has 500 in the total marks: 304

Scope Resolution Operator

                Scope Resolution Operator

Scope resolution Operator is define the function outside a class. it show the inside of program is :: .


for example :

Display of the progrma of  using Scope  resolution opreator(::) in the C++.

#include<iostream>
using namespace std;
int data=5;  // global variable
main()
{
        int data=6; //local variable
        cout<<"without scope resolution opreator use in the data: "<<data<<endl;
cout<<"scope resolution opreator use in the  data: "<< ::data<<endl;

}
output:

without scope resolution opreator use in the data: 6
scope resolution opreator use in the  data : 5

Stream Classes in C++


                                 Stream Classes



What is the Stream Classes ?

The C++ I/O system contains a hierarchy of classes (known as stream classes) that are used for reading and writing by programs.

There are two types I/O  used in High level language of  the  C++  I/O in the :
1) Unformmated I/O
2) Formatted I/O

1) Unformmated I/O: Unformatted I/O uses functions :

  •    put()
  •    putline()
  •    get()
  •    getline()
  •    write()
  •    ignore()
  •    putback()
  •    peek()
  •    gcount()
  •   overloaded opreators >> (extraction ) are used in cin (cin means take a input of  the variable ) and <<(insertion)  are using the cout (cout means gives a output of the variable) in the program.
2) Formatted I/O: Formatted I/O uses functions :

  • width()
  • precision()
  • fiill()
  • setf()
  • unsetf()
  • Stream manipulators ( Defines the no the functions is called the manipulators  for example :      cout <<mani1<<mani2<<mani3<<mani4<<product;  show the all mani1 ,mani2,..,mani4  is manipulators )

Display the Student of Name , Roll_no & Marks in using of Constractor in C++.


Display the Student of Name , Roll_no & Marks in using of Constractor in C++.

#include<iostream>
using namespace std;
class student
{
     public:
      student(int roll_no,char name[50], float marks)
      {
  
   cout<<"student is roll no is :"<< roll_no<<endl;
    cout<<"student is name is :"<< name<<endl; 
    cout<<"student is marks:"<< marks<<endl;
  
}
  
};

main()
{
student std1(123,"rajan",450);
}


OUTPUT :
student is roll no is : 123
student is name is :rajan
student is marks : 450

Write a C++ program to create a Book class.


Write a C++ program to create a Book class. Define proper constructor for the Book class. Define methods to do the following (a) Display price of the book.(b) Display name(s) of the Author(s) of the book.(c) Display ISBN number of the book.


#include<iostream>
using namespace std;
 class book
 {
  private:
  int price, ISBN_NO;
  char name[50];
  public:
book(char name[50],int price,int ISBN_NO )
  {
      cout<<"Display name(s) of the Author(s) of the book:"<<name<<endl;
  cout<<"Display price of the book:"<<price<<endl;
  cout<<"Display ISBN number of the book :"<<ISBN_NO<<endl;
 
       }
 
      };
main()
{   
   book name("rahul",343,786);
    
}


OUTPUT:

Display name(s) of the Author(s) of the book: rahul
Display price of the book: 343
Display ISBN number of the book : 786




Size of data types in C++

           What is Size of data types in C++?

इसमें हम सीखने जा रहे है की आखिर C++ में  सब भी डाटा का  क्या size  होता है  ? 
यह हमारे लिए महत्वपूर्ण है क्यूँकि हम इससे  मेमोरी में ज्यादा स्टोर  करने वाले डाटा को कम स्टोर में परिवर्तित कर सकता है | खासतौर हम यह पता भी होना चाहिए | 

Program in C++ 


#include<iostream>
using namespace std;
int main()

cout<<"size of character :"<<sizeof (char)<<endl;
cout<<"size of unsigned char :"<<sizeof (unsigned char)<<endl;
cout<<"size of signed char :"<<sizeof (signed char)<<endl;
cout<<"size of inte :"<<sizeof (int)<<endl;
cout<<"size of unsigned int :"<<sizeof (unsigned int)<<endl;
cout<<"size of signed int :"<<sizeof (signed int)<<endl;
cout<<"size of short int :"<<sizeof (short int)<<endl;
cout<<"size of unsigned short int :"<<sizeof (unsigned short int )<<endl;
cout<<"size of long int :"<<sizeof (long int)<<endl;
cout<<"size of signed long int :"<<sizeof (signed long int)<<endl;
cout<<"size of unsigned long int :"<<sizeof (unsigned short int )<<endl;
cout<<"size of float :"<<sizeof (float )<<endl;
cout<<"size of double :"<<sizeof (double)<<endl;
cout<<"size of long double :"<<sizeof (long double)<<endl;
cout<<"size of wchar_t :"<<sizeof (wchar_t)<<endl;
}


According to the Dev C++ in 32 bit of Window , Size of the data types in the C++ is Output is :

OUTPUT:
 size of character : 1
size of unsigned char : 1
size of signed char :  1
size of integer : 4
size of unsigned int : 4
size of signed int : 4
size of short int : 2
size of unsigned short int : 2
size of long int : 4
size of signed long int : 2
size of unsigned long int : 8
size of float : 4
size of double  : 8
size of long double  : 12 
size of wchar_t : 2



Write a C++ program to find the sum of two complex numbers.

Write a C++ program to find the sum of two complex numbers. Define proper
class, constructor and method(s) in your program. Give comments to make your
code more understandable.
#include<iostream>
using namespace std;
class complex_no       // create a class  of complex number 
{
private:              /*create a  private member variable or function cannot be accessed from outside the class only friend functions can access private members.*/

    float real_no;       // create a flaot data type  real integer number 
    float imag_no;       // create a flaot data type  imagenary number 
public:           // create a  public  member variable or function can be any accessed from outside the class.

 complex_no() // call the function complex_no()
{
    
}
    complex_no(float r, float i)

    {

real_no= r;

imag_no= i;

    }
    complex_no sum(complex_no c)
    {

complex_no t;

t.real_no = real_no + c.real_no;

t.imag_no = imag_no+ c.imag_no;

return t;

    }
 void disp()
 {
cout<<real_no<<" + "<<imag_no<<endl;
 }

};
int main()
{
complex_no C1(3.5,6.1),C2(3.5,6.5),C3;
C3=C1.sum(C2);
cout<<"\n complex Number 1 = ";
C1.disp();
cout<<"\n complex Number 2 = ";
C2.disp();
cout<<"\n complex Number 3 = ";
C3.disp();
return 0;
}


Output: 
complex Number 1 = 3.5  +  6.1
complex Number 2 = 3.5  +  6.5
complex Number 3 =  7    + 12.6


How to write template in C++?

How to write  template in C++?

#include<iostream>
using namespace std;
template <class t1, class t2>
class template1
{
t1 x;
t2 y;
public :
template1(t1 a ,t2 b )
{
x=a;
y=b;
}
void display()
{
cout<<x<<" and "<<y<<endl;
}
};
main()
{
template1<float, int > test1(4.34,543);
template1<int ,char> test2 (800, 'h');
test1.display();
test2.display();
return 0;
}

OUTPUT:

4.34 and 543
800 and h 

Destructor program in C++


How to write a destructor program in C++?


#include<iostream>
using namespace std;

class worker
{
public:
worker()
{
cout<< "Thanks for using first destructor program in c++"<<endl;

}
 } ;
 main(){
  worker x,y,z;
 }

OUTPUT:

Thanks for using first destructor program in c++
Thanks for using first destructor program in c++
Thanks for using first destructor program in c++

Constructor program in C++




How to write a constructor program in C++ ?
 Constructer जो की ऑब्जेक्ट (object ) को initialization करने का  काम करता है | इसमें क्लास नाम का Same  फंक्शन बनता है जो की इसको indentify  करता है  | 

                                     Program in C++


#include <iostream>
#include<conio.h>
using namespace std;


class employee

{
    public:
    employee()
    {
        cout<<"thanks for using first constructor program in c++ "<<endl;
        
    }
};
main()
{
 employee x,y,z;
    getch();
}



OUTPUT:
thanks for using first constructor program in c++
thanks for using first constructor program in c++
thanks for using first constructor program in c++

Writes a C++ Program to find out the sum of n numbers.

Writes a C++ Program to find out the sum of n numbers.


#include <iostream>
using namespace std;

int main()
{
    int n,i,sum=0;

    cout << "Enter a positive integer: ";
    cin >> n;

    for ( i = 1; i <= n;i++) 
{
        sum=sum+i;
    }

    cout << "Sum=" << sum;
    return 0;

}


OUTPUT:
Enter a positive integers:
6
Sum=21

Contact Form

Name

Email *

Message *

Followers