Monday 25 March 2013

C++ Sum of two numbers using pointers

#include<iostream.h>
void main(){
int n,m,*no,*mo;
no=&n;
mo=&m;
cout<<"Enter the two numbers";
cin>>*no>>*mo;
//*no=2;
//*mo=3;
cout<<"sum of two numbers via pointer is as under = "<<n+m;}



C++ program tell you the cube of the number entered by the user

#include<iostream.h>
 int main()
{int cube(int);
int a;
cout<<"Enter a number to find : ";
cin>>a;
cout<<"Cube of a number is as under : "<<cube(a);
return 0;}

int cube(int m)
{
int mx=m;
mx=mx*mx*mx;
return mx;
}



C++ simple pointer program tell you the address of the pointer


#include<iostream.h>
void main(){
int x,y;
x=245; y=246;
cout<<"value of variable = "<<x<<endl;
cout<<"Value of Address x = "<<&x<<endl;
cout<<"Value of Address y = "<<&y;

}


C++ adding first five location of two arrays

#include<iostream.h>
#include<conio.h>
void main(){ clrscr();
int a[5],b[5];  cout<<"Enter first 5 numbers = ";
for(int i=0;i<5;i++){
cin>>a[i]; }  cout<<"Enter Second 5 numbers = ";
for(int j=0;j<5;j++){
cin>>b[j]; } int s[5];
for(int x=0;x<5;x++){
s[x]=a[x]+b[x];
cout<<a[x]<<" + "<<b[x]<<" = "<<s[x]<<endl;
} getch();
}



Sunday 24 March 2013

c++ Enter the Integer between 1 to 7 and get the required day


#include<iostream.h>
#include<conio.h>
void main()
{
int integer;
gotoxy(15,5);
cout<<"enter any integer between 1 to 7 to finday the day:"; cin>>integer;
switch(integer){
case 1: cout<<"Monday";  break;
case 2: cout<<"Tuesday"; break;
case 3: cout<<"Wednesday"; break;
case 4: cout<<"Thursday"; break;
case 5: cout<<"Friday"; break;
case 6: cout<<"Saturday"; break;
case 7: cout<<"Sunday"; break;
defaut:
cout<<"Wrong options"; } getch();
}

C++ Empty Square Program

 

#include <iostream.h>

int main()
{
    int row=6 , col;
    while (row >= 1)
    {
        col=11;
        while (col >= 1)
        {
            if (row==6 || row==1)
            {
                cout << "=";
            }
            if (row>=2 && row<=5)
            {
                if (col==1 || col==11)
                {
                    cout << "*";
                }
                else
                {
                    cout <<" ";
                }
            }
            col--;
        }
        row--;
        cout << endl;
    }
    return 0;
}

C++ Even & Odd Number Teller Program

 

 

#include<iostream.h>
void main()
{ int num;
cout<<"Enter the number to check weather its even or not = "; cin>>num;
if(num%2==0){cout<<"number is even";}
else if(num%3==0){cout<<"number is odd";}
else {cout<<"Try Again";}
}

C++ Factorial Simple Program


#include<iostream>
#include<conio.h>

using namespace std;

void main()
{
int fact;
int result= 1;

cout<<"Enter Number to find Factorial = "; cin>>fact;

int i=fact;  //i = 5
for(int i=fact;i>1;i--)
{
fact = fact * (i-1);
cout<<fact<<",";
}
_getch();

}



C++ Rectangle Program


#include <iostream.h>

int main()
{
    int row=1 , col;
    while (row <= 5)
    {
        col=12;
        while (col >= 1)
        {
            cout << "* ";
            col--;
        }
        cout << endl;
        row++;
    }
    return 0;
}

C++ How to find the power of any number Easy Approach by two methods


#include<iostream.h>
int main()
{
  int b,e;

  cout<<"enter a base value:";
  cin>>b;
  cout<<"enter a exponent Value:";
  cin>>e;


  long int r=b;
  while (e>1)
  {
      e=e-1;
      r=b*r;
  }
  cout<<r;
  return 0;
}



Another program with different method in visual studio


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

void main()
{
    int b;
    int p;
    int temp;
    cout<<"Enter the value of base = "; cin>>b;
    cout<<"Enter the value of power = "; cin>>p;

    temp = b;
    while(p>1)
    {
        b = b* temp;
        p--;

    }

    cout<<"the power of the value is as under = "<<b;
    _getch();

}







C++ Half Diamond Program Using NEsted Loops



#include <iostream.h>

int main()
{
    int row=1 , col ;

    while(row <= 6)
    {
        col = row;
        while (col >= 1)
        {
            cout << "*";
            col--;
        }
        cout << endl;
        row++;
    }
    row=6;
    while (row >= 1)
    {
        col = row;
        while (col >=1)
        {
            cout << "*";
            col--;
        }
        cout << endl;
        row--;
    }
    return 0;
}

Saturday 23 March 2013

C++ GPA & CGPA Calculator Program

You can see this program  in C# also at on another blog
http://csharpisbest.blogspot.com/2013/06/c-cgpa-caclulator-form-application.html 

Program of gpa calculator is also done in functions go to this link to view that code

  1. #include<iostream.h>
  2. #include<conio.h>
  3. //www.programmingisbest.blogspot.com
  4. void main()
  5. {
  6. float x[5]; float cpa;
  7. char name[15],fname[15];  int i=1; int cr[5]; float result[5];
  8. cout<<"please enter your name: ";
  9. cin>>name;
  10. cout<<"please enter your father name:";
  11. cin>>fname;
  12. cout<<"please enter your previous cgpa = ";
  13. cin>>cpa;
  14. while(i<6)
  15. {//www.programmingisbest.blogspot.com
  16. cout<<"enter the marks of the subject"<<i<<" = ";
  17. cin>>x[i];
  18. cout<<"enter the credit hour of that subject = ";
  19. cin>>cr[i];
  20. result[i]=cr[i]*x[i];
  21. i++;
  22. }

  23. int gm;float sum; float gpa;
  24. gm=cr[1]+cr[2]+cr[3]+cr[4]+cr[5];
  25. sum = result[1]+result[2]+result[3]+result[4]+result[5];
  26. gpa=sum/gm;
  27. cout<<"\n\n\n\n";
  28. cout<<"xxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"; cout<<"xxxR.E.S.U.L.Txxx\n";   cout<<"xxxxxxxxxxxxxxxxxxxxxxxxxxxx\n";
  29. cout<<"Your gpa is as under = "<<gpa<<endl; float kk; kk=(gpa*cpa)/2; cout<<"your cgpa is as under = "<<kk<<endl;
  30. if(kk>2 && kk<4)
  31. {
  32. cout<<"You are Qualified";
  33.  }
  34.  else if(kk<2 && kk>1.5)
  35.   {
  36.   cout<<"You are Probiation";
  37.     }
  38.     else if(kk<1.5)
  39.     {
  40.     cout<<"You are at chance";
  41.     }
  42.     else {
  43.     cout<<"try again";
  44.      }
  45. getch();
  46. }

C++ program tell you the size of String which You have entered



#include<iostream.h>
#include<conio.h>
#include<cstring.h>


void main()
{
    char arr[20];
    int a,count;

    count=0;

    cin.getline(arr,20,'\n');

    for(a=0;a<20;a++)
    {
        if(arr[a]!='\0')
        {
            count++;

        }
        else if(arr[a]=='\0')
        {
            break;
        }
    }

    cout<<"\n\nThe size is = "<<count;

    getch();
}

using C++ structure call the paramters to make Calculator program



#include<iostream.h>

struct dis
{
 int num; int num2;
};

void main()
{
dis x,y;
 cout<<"enter the first number & second number = ";
  cin>>x.num>>y.num2;
 cout<<"\nadd = "<<x.num+y.num2;
 cout<<"\nsub = "<<x.num-y.num2;
 cout<<"\nMultiply = "<<x.num*y.num2;
 float g; g=x.num/y.num2;
 cout<<"\nDivide = "<<g;
}

Using Functions make Calculator by return their results C++


#include<iostream.h>
int add(int x,int y){return x+y;}
int sub(int x,int y){return x-y;}
int mult(int x,int y){return x*y;}
 int div(int x,int y){return x/y;}
int main()
{
int a,b;
cout<<"enter any two numbers:";
cin>>a>>b;
cout<<"sum = "<<add(a,b);
 cout<<"\nsub = "<<sub(a,b);
 cout<<"\nmultiply = "<<mult(a,b);
  cout<<"\ndivide = "<<div(a,b);
  }