北美微论坛

App下载
扫码下载 App
联系我们
1框架
查看: 691|回复: 6
打印 上一主题 下一主题

[学校校园] 求chegg这题答案。。编程的code。。

[复制链接]

系主任

Rank: 12Rank: 12Rank: 12

最佳新人常驻居民

跳转到指定楼层
楼主
发表于 2014-10-8 17:45:52 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
1金钱
本帖最后由 月見藥 于 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

674dbe20gw1ejxxjinuukj20dw0dw757.jpg (37.55 KB, 下载次数: 0)

674dbe20gw1ejxxjinuukj20dw0dw757.jpg

最佳答案

查看完整内容

void printStringInBox(string s){ int l; l=s.length(); for(int i=1;i
收藏收藏 分享分享 赞赞赞!赞赞赞! 踩踩踩!踩踩踩! 新浪微博微博分享
猫头鹰眼睛一瞪 发现事情 没有辣么简单
回复

使用道具 举报

副系主任

【小米家】 诚信买卖

Rank: 11Rank: 11Rank: 11Rank: 11

最佳新人常驻居民

沙发
发表于 2014-10-8 17:45:53 | 只看该作者
void printStringInBox(string s){
int l;
l=s.length();
for(int i=1;i<=l+4;i++)
cout<<"*";
cout<<endl;
cout<<"* "<<s<<" *"<<endl;
for(int i=1;i<=l+4;i++)
cout<<"*";
}
❤ 诚信买卖 ❤
❤ 微信 Michelle_5146 ❤
回复

使用道具 举报

高级院士

Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15

热心居民最佳新人常驻居民精华达人

板凳
发表于 2014-10-8 17:48:00 | 只看该作者
提高点悬赏我就教你。。。我不会为一金币折腰的。。
回复

使用道具 举报

系主任

Rank: 12Rank: 12Rank: 12

最佳新人常驻居民

地板
 楼主| 发表于 2014-10-8 17:50:49 | 只看该作者
Elise1213 发表于 2014-10-8 16:48
提高点悬赏我就教你。。。我不会为一金币折腰的。。

哈哈好的
猫头鹰眼睛一瞪 发现事情 没有辣么简单
回复

使用道具 举报

系主任

❀爱生活,爱购物❀

Rank: 12Rank: 12Rank: 12

最佳新人常驻居民

5#
发表于 2014-10-8 17:52:13 | 只看该作者
不为1金币折腰……= =
奇葩太多怎么说都说不完
回复

使用道具 举报

教授

Rank: 10Rank: 10Rank: 10

最佳新人常驻居民

6#
发表于 2014-10-8 17:52:45 | 只看该作者
哈哈哈哈哈哈哈
回复

使用道具 举报

高级院士

Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15

热心居民最佳新人常驻居民精华达人

7#
发表于 2014-10-8 17:58:55 | 只看该作者

哈哈哈哈哈 你已经有答案啦~~
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

返回顶部