Programming Resources
For Fun and Learning
Charles Cusack
Computer Science
Hope College
main

Python
C++
JAVA
PHP
SQL

Assignments


VerificationAlgs


P2Verify.cpp

/*-------------------------------------*/
/*cse310 hw6 prob2 verification program*/
/*Author: Guanshan Yu                  */
/*Requirement: Prob2.dat Prob2.out     */
/*-------------------------------------*/

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

int main(){
	
	//open Prob2.dat and Prob2.out
	
	FILE *dat_file = fopen("Prob2.dat","r");
	FILE *out_file = fopen("Prob2.out","r");
	char dat[256], out[256];
	int dat_num, out_num;
	fscanf(dat_file,"%s",dat);
	fscanf(out_file,"%s",out);
	dat_num = atoi(dat);
	out_num = atoi(out);
	int size = dat_num;
	int min = out_num;
	int x[size + 1], y[size + 1];

	//-------------------------------create map-------------------------------
	//initialize the map with 0
	int map[1001][1001];
	for(int i=0; i<1001; i++){
		for(int j=0; j<1001; j++){
			map[i][j] = 0;
		}
	}
	
	//read x and y coordinates
	//and make the sets
	for(int i=1; i<=size; i++){
		
		//------x---------------
		fscanf(dat_file,"%s",dat);
		dat_num = atoi(dat);
		x[i] = dat_num;
		//------y---------------
		fscanf(dat_file,"%s",dat);
		dat_num = atoi(dat);
		y[i] = dat_num;
		//make a map
		map[x[i]][y[i]] = 1;	//map all the points	
	}
	//--------------------------------------------------------------------------
	//----------------------------eliminate points------------------------------
	for(int i=1; i<=min; i++){
		fscanf(out_file,"%s",out);
		out_num = atoi(out);
		for(int j=1; j<=size; j++){
			if((x[out_num]-x[j])*(x[out_num]-x[j])+(y[out_num]-y[j])*(y[out_num]-y[j]) <= 10000){
				map[x[j]][y[j]] = 0;
			}
		}
	}
	
	//--------------------------check if sets cover all the points--------------
	
	int counter = 0;	//counter for number of points that's not been covered
	for(int i=0; i<=1000; i++){
		for(int j=0; j<=1000; j++){
			if(map[i][j] == 1){
				counter++;
			}
		}
	}
	//---------------------test result output------------------------------------
	cout<<"test result:"<<endl;
	cout<<"you have "<<min<<" sets;"<<endl;
	if(counter > 0){
		cout<<"your sets failed to cover all the points."<<endl;
		cout<<"there are "<<counter<<" points left uncovered."<<endl;
		cout<<"bad for you... you failed this course!"<<endl;
	}else{
		cout<<"your sets successfully covered all the points."<<endl;
		cout<<"good for you!"<<endl;
	}
		
	//-------------------------end-----------------------------------------------
	return 0;
}