注册 登录
编程论坛 C++教室

新人求组,已查过度娘实在没找到解决方法或者未理解怎么运用。求解答!

xmforget911 发布于 2015-07-24 16:01, 636 次点击
C++PP 上的编程练习题

使用3个用户自定义函数(包括main()),并生成下面的输出:
Three blind mice
Three blind mice
See how they run
See how they run
其中一个函数要调用两次,该函数生成前两行,另一个函数也要调用两次,并生成其余的输出;

请问这函数循环调用该怎么写?为何这么写?

谢谢各位大神解答。
6 回复
#2
hjx11202015-07-24 16:05
这个帖子,本掌柜前段时间有写过
https://bbs.bccn.net/thread-455418-1-1.html
#3
xmforget9112015-07-24 16:06
回复 2楼 hjx1120
谢谢。 太感谢掌柜的笔记了。。
#4
xmforget9112015-07-24 16:10
回复 2楼 hjx1120
掌柜
请问:

int main()
{
    mice();
    mice();
    run();
    run();
    return 0;
}
这么写是定义函数原型么?
#5
hjx11202015-07-24 16:15
回复 4楼 xmforget911

#include <iostream>
void mice(void);   //自定义函数原型
void run(void);    //自定义函数原型
using namespace std;
int main()
{
    mice();   //自定义函数调用
    mice();   //自定义函数调用
    run();    //自定义函数调用
    run();    //自定义函数调用
    return 0;
}

void mice(void)      //自定义函数结构
{
    cout << "Three blind mice" << endl;
}

void run(void)       //自定义函数结构
{
    cout << "See how they run" << endl;
}
#6
xmforget9112015-07-24 16:16
回复 4楼 xmforget911
谢谢 ,明朗了。
#7
flkj20152015-07-24 20:25
回复 楼主 xmforget911
#include<iostream>

int main()
{
    extern void mice();
    extern void see();
    mice();
    mice();
    see();
    see();
    return 0;
}

void mice(){std::cout<<"Three blind mice"<<std::endl;}
void see(){std::cout<<"See how they run"<<std::endl;}
1