Welcome

Hi! This blog is for beginners of c++ and java .You can check and pick codes for your programming assignments. This will also help you to understand the concepts of these programming languages. Its all about programming.

Calculator Using Pointers & Parameter pass by Refrence.

Friday, July 1, 2011

#include<iostream.h>

void add(float* , float*);        // function declaration
void sub(float* , float*);        // function declaration
void mul(float* , float*);        // function declaration
void div(float* , float*);        // function declaration

int main(){
    char option;
    float a;
    float b;     
   
    cout << "Choose from the following options: " << endl;
    cout << "+ : Plus" << endl;
    cout << "- : Minus" << endl;
    cout << "* : Multiply" << endl;
    cout << "/ : Divide" << endl;
    cin >> option;
   
    cout << "Enter first number: ";  cin >> a;
    cout << "Enter second number: "; cin >> b;
   
    switch (option){
      case '+':
         add(&a, &b);
         break;
     
      case '-':
         sub(&a, &b);
         break;
     
      case '*':
         mul(&a, &b);
         break;
     
      case '/':
         div(&a, &b);
         break;
     
      default:
         cout << "Wrong option. Run again.";
    } // end switch
   
return 0;
} // end main()

// ========= () ================
void add(float* x, float* y){
   cout << *x << " + " << *y << " = " << ((*x) + (*y));
return;


// ========= () ================
void sub(float* x , float* y) {
   cout << *x << " - " << *y << " = " << ((*x) - (*y));
return;   
}

// ========= () ================
void mul(float* x, float* y){
   cout << *x << " * " << *y << " = " << ((*x) * (*y));
return;


// ========= () ================
void div(float* x, float* y){
   cout << *x << " / " << *y << " = " << ((*x) / (*y));
return;