View Code of Problem 15

#include<iostream>
#include<math.h>
using namespace std;
struct Point{
	double x;
	double y;
};
int main(){
	int n;
	int d=1;
	while(cin>>n && n!=0){
		Point ar[10];
		double s=0;
		while(n--){
			int m;
			cin>>m;
			for(int i=0;i<m;i++){
				cin>>ar[i].x>>ar[i].y;
			}
			double x1=ar[1].x-ar[0].x;
			double y1=ar[1].y-ar[0].y;
			double a=sqrt(pow(x1,2)+pow(y1,2));
			switch(m){
				case 3:
                              s += 1.73205 / 4 * a * a;
                              break;
                      case 4:
                              s += a * a;
                              break;
                      case 5:
                              s += 1.72048 * a * a;
                              break;
                      case 6:
                              s += 1.73205 / 4 * a*a * 6;
                              break;
                      case 7:
                              s += 3.63391 * a * a;
                              break;
                      case 8:
                              s += 4.82843 * a*a;
                              break;
                      default:
                              break;
              }
			}
			printf("Case #%d: %.4lf\n",d++,s);
		}
	}

Double click to view unformatted code.


Back to problem 15