void aliquotClassifier(unsigned long long n){
	unsigned long long arr[16];
	int i,j;
	
	arr[0] = n;
	
	for(i=1;i<16;i++){
		arr[i] = bruteForceProperDivisorSum(arr[i-1]);
		
		if(arr[i]==0||arr[i]==n||(arr[i]==arr[i-1] && arr[i]!=n)){
			printSeries(arr,i+1,(arr[i]==0)?"Terminating":(arr[i]==n && i==1)?"Perfect":(arr[i]==n && i==2)?"Amicable":(arr[i]==arr[i-1] && arr[i]!=n)?"Aspiring":"Sociable");
			return;
		}
		
		for(j=1;j<i;j++){
			if(arr[j]==arr[i]){
				printSeries(arr,i+1,"Cyclic");
				return;
			}
		}
	}
	
	printSeries(arr,i+1,"Non-Terminating");
}
Ejemplo n.º 2
0
/* 
The test cases are run separately because if their veritcal alignment
is wrong students will loose marks simply because we do not see the 
subsequent output in the right places.  It is also good to do it this way 
when testing extremes  - it avoids that students loose all their marks  
if their program segfault on an extreme.
 */
int main()	
{ 
	/** need only one test matrix because we need not look at how it 
	    deals with cases where the values themselves are extreme 
	    because it is not relvant. The printer just echo so it would
	    deal consistantly with values. One case that has negative, 
	    positve and zero value respectivey are thus sufficient.*/
	
	double array[5] = {5,-1,0,3,9};
	
	cin >> aSize;
	cout << "AAAAAA";
	printSeries(array, aSize);
	cout << "HHHHHH\n";
	return 0;
}
Ejemplo n.º 3
0
int main()	{
	float angle, rads;
	cout << "Enter an angle in degrees: ";
	cin >> angle;

	cout << "1. Calculate sin(" << angle << ")" << endl; 
	cout << "2. Calculate cos(" << angle << ")" << endl; 
	cout << "3. Calculate tan(" << angle << ")" << endl; 
	cout << "Enter your choice: ";
	int choice;
	cin >> choice;

	if (!(choice == 1 || choice == 2 || choice == 3)){
		cout << "Invalid choice" << endl;
		return 0;
	}

	rads = toRadians(angle);
	int terms;
	cout << "Enter the number of terms to use in series: ";
	cin >> terms;
	if (terms < 0) {
		cout << "Cannot have a negative number of terms" << endl;
		return 0;
	}
	
	double seriesArray[MAX_TERMS];
	
	switch (choice){
		case 1: 
			sinSeries(rads, seriesArray, terms);
			cout << "sin(" << angle << ") = ";
			printSeries(seriesArray, terms);
			cout << " = " << sumOfSeries(seriesArray, terms) << endl;
			break;
		case 2: 
			cosSeries(rads, seriesArray, terms);
			cout << "cos(" << angle << ") = ";
			printSeries(seriesArray, terms);
			cout << " = " << sumOfSeries(seriesArray, terms) << endl;
			break;
		case 3:
			double seriesArray2[MAX_TERMS];
			tanSeries(rads, seriesArray, seriesArray2, terms);			
			cout << "tan(" << angle << ") = " << endl;
			printSeries(seriesArray, terms);
			cout << endl;
			for (size_t i = 0; i < terms; i++){
				cout << "------------";
			}
			cout << endl;
			printSeries(seriesArray2, terms);
			cout << "\n= " << sumOfSeries(seriesArray, terms) / sumOfSeries(seriesArray2, terms) << endl;
	}
	
	switch(choice)
	{
		case 1:
			cout << "When using the cmath sin function: " << endl;
			cout << "sin(" << angle << ") = " << sin(rads) << endl;
			break;
		case 2:
			cout << "When using the cmath cos function: " << endl;
			cout << "cos(" << angle << ") = " << cos(rads) << endl;
			break;
		case 3:
			cout << "When using the cmath tan function: " << endl;
			cout << "tan(" << angle << ") = " << tan(rads) << endl;
	}
		
	return 0;
}