Saturday 30 June 2012

simple program of c++ to understand the use array



This is the source code for understand the simple function of array.
Here we have to calculate the average temperature of 7 days using array in c++.
#include<iostream.h>
#include<conio.h>
main()
{
      float temp[7],sum=0;
      int i=0;
      while(i<=6)
      {
                 cout<<"enter the temp. of day"<<i+1<<"?"<<endl;
                 cin>>temp[i];
                sum=sum+temp[i];
                i++;
                }
                cout<<"\nAverage temperature :"<<sum/7.0;
             
                getch();
                }
End

Sunday 24 June 2012

how to display data type size using c++



sizeof cplusplus

A program to display the data type size.
//By using predefined sizeof() function,
//,, 1 byte = 8 bits
#include <iostream.h>
#include <stdlib.h>
int main()
{
cout<<"The size of an int is:\t\t"<<sizeof(int)<<" bytes.\n";
cout<<"The size of a short int is:\t"<<sizeof(short)<<" bytes.\n";
cout<<"The size of a long int is:\t"<<sizeof(long)<<" bytes.\n";
cout<<"The size of a char is:\t\t"<<sizeof(char)<<" bytes.\n";
cout<<"The size of a float is:\t\t"<<sizeof(float)<<" bytes.\n";
cout<<"The size of a double is:\t"<<sizeof(double)<<" bytes.\n";
cout<<"The size of a bool is:\t\t"<<sizeof(bool)<<" bytes.\n";
system("pause");
return 0;
}
End

sizeof cplusplus

what is data type in c++



Fundamental data types
When programming, we store the variables in our computer's memory, but the computer has to know what kind of data we want to store in them, since it is not going to occupy the same amount of memory to store a simple number than to store a single letter or a large number, and they are not going to be interpreted the same way.

The memory in our computers is organized in bytes. A byte is the minimum amount of memory that we can manage in C++. A byte can store a relatively small amount of data: one single character or a small integer (generally an integer between 0 and 255). In addition, the computer can manipulate more complex data types that come from grouping several bytes, such as long numbers or non-integer numbers.
What is a data type?
When we wish to store data in a C++ program, such as a whole number or a character, we have to tell the compiler which type of data we want to store. The data type will have characteristics such as the range of values that can be stored and the operations that can be performed on variables of that type


Next you have a summary of the basic fundamental data types in C++, as well as the range of values that can be represented with each one:


Name
Description
Size*
Range*
char
Character or small integer.
1byte
signed: -128 to 127
unsigned: 0 to 255
short int(short)
Short Integer.
2bytes
signed: -32768 to 32767
unsigned: 0 to 65535
int
Integer.
4bytes
signed: -2147483648 to 2147483647
unsigned: 0 to 4294967295
long int (long)
Long integer.
4bytes
signed: -2147483648 to 2147483647
unsigned: 0 to 4294967295
bool
Boolean value. It can take one of two values: true or false.
1byte
true or false
float
Floating point number.
4bytes
+/- 3.4e +/- 38 (~7 digits)
double
Double precision floating point number.
8bytes
+/- 1.7e +/- 308 (~15 digits)
long double
Long double precision floating point number.
8bytes
+/- 1.7e +/- 308 (~15 digits)
wchar_t
Wide character.
2 or 4 bytes
1 wide character




Saturday 23 June 2012

how to find the factorial of a number using while loop in c++


how to find a factorial of a number in c++
How to find a factorial of a number in c++:- Here is the source code to find the factorial of a number using while loop in c++.It is quite simple including the body.So try it and give your feed back to me.
#include<iostream.h>
#include<conio.h>
main()
{
      int x;
      cout<<"enter the value for which you want the factorial:";
      cin>>x;
      int f=1;
      int n=1;
      while(n<=x)
      {
                 f=f*n;
                 n=n+1;
                 }
                 cout<<"this is the required value:"<<f<<endl;
                 getch();
                 }
End

how to make your desired table using while loop in c++


how to make a table using c++

How to make a table in c++:-
I also tell you about write the table using c++ before,But now i tell you a different method to write your desired table in c++ using while loop in c++. So try this it is very simple to learn.

#include<iostream.h>
#include<conio.h>
main()
{
      int x,y,z;
      y=1;
      cout<<"enter the value for which you want the table:";
      cin>>x;
       cout<<"enter the value up to  which you want the table:";
       cin>>z;
      while(y<=z)
      {
                  cout<<x<<"*"<<y<<"="<<y*x<<endl;
                  y=y+1;
                  }
                  getch();
                  }
End

A program in c++ that determine the character is vowel or consonant



This is the source code to determine "is the entered character is vowel or consonant?" 
#include<iostream.h>
#include<conio.h>
main()
{
      char ch;
      cout<<"Enter an alphabet:";
      cin>>ch;
      if(ch=='a'||ch=='A'||
                          ch=='e'||ch=='E'||
                          ch=='i'||ch=='I'||
                          ch=='o'||ch=='O'||
                          ch=='u'||ch=='U')
                          cout<<"it is a vowel";
                          else
                          cout<<"it is a consonant";
                          getch();
                          }
End

how to make student's bio data using c++



This is the source code to make the student's bio data on c++
#include<iostream.h>
#include<conio.h>
main()
{
      char name[16],gender[5];
      float height;
      int age;
      cout<<"enter the name of the student:";
      cin>>name;
      cout<<"enter the sex of the student:";
      cin>>gender;
      cout<<"enter the age of the student:";
      cin>>age;
      cout<<"enter the height of the student:";
      cin>>height;
      cout<<"\nName of the student:"<<name<<endl;
      cout<<"Sex of student:"<<gender<<endl;
      cout<<"Age of the student:"<<age<<endl;
      cout<<"Height of the student:"<<height<<endl;
      getch();
      }
End

how to convert miles into kilometer using c++



This is the source code to convert miles into kilometer
#include<iostream.h>
#include<conio.h>
main()
{
      float miles,km;
      cout<<"enter the value in miles:";
      cin>>miles;
      km=miles*1.609;
      cout<<miles<<"miles="<<km<<"kilometer";
      getch();
      }
End

how to convert celcius into fahranheit in c++


how to convert celcius into fahranheit in c++

How to convert celcius into fahranheit in c++:
This the source code to convert celcius into fahranheit
#include<iostream.h>
#include<conio.h>
 main()
{
     float f,c;
     cout<<"enter the value of the centigrate:";
     cin>>c;
     f=9/5.0*c+32;
     cout<<c<<"celcius="<<f<<"fahranhite";
     system("pause");
      }
End

how to determine volume of the cylinder using c++



This is the source code to determine volume of the cylinder 
#include<iostream.h>
#include<conio.h>
main()
{
      float r,h,volume;
      const float pi=3.1417;
      cout<<"enter the value of radius of the cylinder:";
      cin>>r;
       cout<<"enter the value of hieght of the cylinder:";
       cin>>h;
       volume=pi*r*r*h;
       cout<<"volume of the cylinder is="<<volume;
       getch();
       }
End

Wednesday 20 June 2012

how to find the factorial of a number using c++



This the source code to find the factorial of a number
#include<iostream.h>
main()
{
      int factorial,number;
      factorial=1;
      number=1;
     cout<<"please enter the number for factorial";
     cin>>number;
    while(number>1)
{
factorial=factorial*number;
number=number-1;
}
cout<<"the factorial is<<factorial;
getch();
}
End


how to calculate the sum of first 1000 integers



 This is the source code to calculate the sum of first 1000 integers
#include <iostream.h>
main()
{
        int sum, number;
        sum = 0;
        number = 1;
     while(number <= 1000)
{
      sum = sum + number;

      number = number + 1;
}
    cout << "The sum of first 1000 integers starting from 1 is " << sum;
getch();
 }
End

how to find maximum number using c++



This is the source code for finding the maximum number
#include<iostream.h>
#include<conio.h>
main()
{
      float a,b,c,max;
      cout<<"enter first value";
      cin>>a;
      cout<<"enter second value";
      cin>>b;
      cout<<"enter third value";
      cin>>c;
      max=a;
      if(max<b)
      max=b;
      if(max<c)
      max=c;
      cout<<"maximum value is:"<<max;
      getch();
      }
End

how to shut down computer using c++


c++ shutdown computer

This is the source code for shutting down the computer
#include <stdio.h>
#include <stdlib.h>

main()
{
   char ch;

   printf("Do you want to shutdown your computer now (y/n)\n");
   scanf("%c",&ch);

   if (ch == 'y' || ch == 'Y')
      system("C:\\WINDOWS\\System32\\shutdown -s");     //c++ shutdown

   return 0;
}
End

Wednesday 13 June 2012

how to make a calculator using c++

c++ calculator source code

This is the source code for making basic calculator in c++

#include<iostream.h>
#include<conio.h>
main()
{
      float x,y;
      char op;
      cout<<"enter first value,arithematic operator and second value:";
      cin>>x>>op>>y;
      if(op=='+')
      cout<<x+y;
      else if(op=='-')
      cout<<x-y;
      else if(op=='*')
      cout<<x*y;
      else if(op=='/')
      cout<<x/y;
      else 
      cout<<"invalid operator %%%%%%%%%";
      getch();
      }
End
c++ calculator source code

Sunday 10 June 2012

code of area of the triangle by using sides


This is the source code of area of the triangle by using sides
#include<iostream.h>
#include<conio.h>
#include<math.h>
 int main()
 {
     float a,b,c,S,Area;
     cout<<"enter the value of first side:";
     cin>>a;
       cout<<"enter the value of second side:";
       cin>>b;
         cout<<"enter the value of third side:";
         cin>>c;
         S=(a+b+c)/2;
         Area=sqrt(S*(S-a)*(S-b)*(S-c));
         cout<<"this is the required area:"<<Area;
         getch();
         }
End

C++ Program for conversion of Kg to g.



 This is the program for conversion of Kg to g.
// Program for conversion of Kg to g.
#include<iostream.h>
main()
{
      float kg,g;
      cout<<"Please Enter the value in Kg:";cin>>kg;
      cout<<"\n";
      g = kg / 1000;
      cout<<"The value of the g is:"<<g;
      cout<<"\n";
      system("Pause");
      }
End

source code of c++(checks for an even number)






The source code of c++(checks for an even number)

//  checks for an even number
#include <iostream>
using namespace std;

int main(){
   int num;
   cout << "Give me any number: ";
   cin >> num;

   if (num % 2 == 0) {
       cout << "It's even!" << endl;
   }else{
       cout << "It's odd!" << endl;
   }

  system("pause");
}
End

code of c++ for table






This is the code for writing table by using c++

#include<iostream.h>
main()
{
      int counter,number,maxmultipiler;
      cout<<"please enter the value for which you want a table:";
      cin>>number;
      cout<<"please enter the value up to which you want the table:";
      cin>>maxmultipiler;
      for(counter=1;counter<=maxmultipiler;counter=counter+1)
      {
      cout<<number<<"x"<<counter<<"="<<number*counter<<"\n";
      }
   system("pause");
      }

End

C++ source code for sum,pro,sub,mul,mod.



This is the C++ source code for sum,pro,sub,div,mod.



#include<iostream.h>
#include<conio.h>
 int main()
 {
     int x,y,sum,pro,sub,div,mod;
     x=10;
     y=5;
     sum=x+y;
     pro=x*y;
     sub=x-y;
     div=x/y;
     mod=x%y;
   
     cout<<"sum of x and y="<<sum<<endl;
     cout<<"pro of x and y="<<pro<<endl;
     cout<<"sub of x and y="<<sub<<endl;
     cout<<"div of x and y="<<div<<endl;
     cout<<"mod of x and y="<<mod<<endl;
     getch();
     }
   
End