本帖最后由 月見藥 于 2014-11-6 10:27 编辑
I have finished my project, are you guys willing to do a check for me
/*uniqname:sakuraraallenqzy; uniqname of partner: allenqzy*/ #ifndef _ASCIIART_H #define _ASCIIART_H
#include "asciiart.h" #include <iostream> #include <cmath> #include <string> using namespace std;
void printRectangle(int rows, int cols) { for (int i = 1; i <= rows; i++) { for (int j = 1; j <= cols; j++) { cout << '*'; } cout << endl; } } void printRectangle(int rows, int cols, int offset) { for (int i = 1; i <= rows; i++) { int j = 1; int k = 1; while (k <= offset) { cout << " "; k++; } while (j <= cols) { cout << '*'; j++; } cout << endl; } } void printStringInBox(string str1) { int i = str1.length(); for (int j = 0; j < i + 4; j++) { cout << '*'; } cout << endl << "* " << str1 << " *" << endl; for (int j = 0; j < i + 4; j++) { cout << '*'; } cout << endl; } void printRight(int n) { for (int i = 1;i <= n; i++) { for (int j = 1; j <= i; j++) { cout << '*'; } cout << endl; } } void printRightWithSpaces(int n) { for (int i = 1; i <= n; i++) { cout << '*'; for (int j = 1; j < i - 1; j++) { cout << ' *'; } cout << endl; } }
void printIsosceles(int n) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n - i; j++) cout << ' '; for (int k = 1; k <= 2 * i - 1; k++) cout << '*'; for (int m = 1; m <= n - i; m++) { cout << ' '; } cout << endl; } } void printIsoscelesPointingDown(int n) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= -1 + i; j++) cout << ' '; for (int k = 1; k <= 2*n - 2*i + 1; k++) cout << '*'; for (int m = 1; m <= -1 + i; m++){ cout << ' '; } cout << endl; } } void printDiamond(int n) { printIsoscelesPointingDown(n); printIsoscelesPointingDown(n - 1); cout << endl; } void printArrow(int n) { for (int i = 1; i <= n; i++) { for (int a = 1; a <= 2 * n + 2; a++) cout << ' '; for (int b = 1; b = 2 * i + 1; b++) { cout << '*'; } cout << endl; } for (int j = 1; j <= 4 * n + 3; j++) { cout << '*'; } for (int k = 1; k <= n; k++) { for (int c = 1; c <= 2 * n + 2; c++) cout << ' '; for (int d = 1; d <= 2 * n + 1 - 2 * k; d++) { cout << '*'; cout << endl; } } } bool isPrime(int val) { for (int i = 2; i < val; i++) if (val== 0 ) { return false; } return true; } void printPrimes(int start, int end) { int i = start; if (start > end) { swap(start, end); } while (isPrime(i) == false) { i = i + 1; } if (isPrime(i) == true) { cout << i; for (int j = start; j <= end; j++) { if (isPrime(j) == true) { cout << ", " << j; } } } } void printMersennePrimes(int start, int end) {
int i = 2; if (start > end) { swap(start, end); } while (pow(2,i) + 1 <= end) { int k = pow(2, i) + 1; if (isPrime(i) == true) { if (isPrime(k) == true) { cout << k << endl; i = i + 1; } i = i + 1; } i = i + 1; } }
int sumProperDivisors(int n) { int sum = 0; for (int i = 1; i <= n - 1;i++) if (n % i == 0) { sum = sum + i; } return sum; } bool isPerfect(int n) { if (n == sumProperDivisors(n)) { return true; } else { return false; } } bool isAbundant(int n) { if (n < sumProperDivisors(n)) { return true; } else { return false; } } bool isAmicable(int first, int second) { if (first == sumProperDivisors(second) && second == sumProperDivisors(first)) { return true; } else { return false; } } #endif
----------------------------------------------------- Test: /*uniqname:sakurara; uniqname of partner: allenqzy*/ #ifndef _ASCIIART_H #define _ASCIIART_H #include "asciiart.h" #include <cmath> #include <iostream> #include <string> using namespace std;
int main() {
printRectangle(3, 2); cout << endl; printRectangle(2, 3); cout << endl; printRectangle(3, 5, 2); cout << endl; printRectangle(5, 3, 2); cout << endl; printStringInBox("I love you!"); cout << endl; printStringInBox("\n"); cout << endl; printRight(4); cout << endl; printRightWithSpaces(3); cout << endl; printIsosceles(5); cout << endl; printIsoscelesPointingDown(3); cout << endl; printDiamond(4); cout << endl; printArrow(4); cout << endl; cout << isPrime(9); cout << endl; printPrimes(5, 10); cout << endl; printPrimes(19, 2); cout << endl; printMersennePrimes(1, 50); cout << endl; printMersennePrimes(30, 1); cout << endl; cout << sumProperDivisors(6); cout << endl; cout << isPerfect(20); cout << endl; cout << isAbundant(30); cout << endl; cout << isAmicable(25, 30); cout << endl; cout << isAmicable(40, 18);
// ... return 0; } #endif |