Banner Ad

    A    L    W    A    Y    S           D    E    S    I    R    E           T    O           L    E    A    R    N           S    O    M    E    T    H    I    N    G           U    S    E    F    U    L   

Sunday, May 8, 2011

IPE Lab 12A rectangle

//rectangle.h

#include <iostream>
using namespace std;

class rec
{
private:
double width;
double length;

public:
rec(double width, double length);
double calcArea();
};

//rectangle.cpp
#include "rec.h"

rec::rec(double pwidth, double plength)
{
      width=pwidth;
      length = plength;
}

double rec::calcArea()
{
      return width*length;
}
 
//area.cpp
#include "rec.h"
#include <iostream>
using namespace std;
int main()
{
      double a1, a2, tot;

      rec rec1(3,4);
      rec rec2(5,6);
      a1 = rec1.calcArea();
      a2 = rec2.calcArea();

      tot = a1+a2;

      cout << "Total Area is " << tot << endl;
}
 


0 comments:

Related Posts Plugin for WordPress, Blogger...

your comments