您的位置:首页 > 其它

第11周项目1函数版星号图(2&review)

2014-11-06 14:35 260 查看
问题及代码:

<pre class="cpp" name="code">/* 
*Copyright (c)2014,烟台大学计算机与控制工程学院 
*All rights reserved. 
*文件名称:star.cpp 
*作    者:单昕昕 
*完成日期:2014年11月6日 
*版 本 号:v1.0 
* 
*问题描述:根据main函数中对printchs函数的调用,以及printchs的功能要求,编写printchs函数。
*程序输出:星号图
*/  
#include <iostream>
using namespace std;
void printchs(int m,char ch)  //定义能输出一行若干个指定字符的函数。
{
  for(int j=1;j<=m;++j)
        cout<<ch;
}

int main()
{
    int n=6,i; //n代表要输出的行数。
    for(i=1; i<=n; ++i)
    {
        printchs(n-i,' '); //调用函数,括号里为自定义输出的*数量。
        printchs(2*i-1,'*');
        cout<<endl;
    }
    return 0;
}



运行结果:





问题及代码:



/* 
*Copyright (c)2014,烟台大学计算机与控制工程学院 
*All rights reserved. 
*文件名称:star.cpp 
*作    者:单昕昕 
*完成日期:2014年11月6日 
*版 本 号:v1.0 
* 
*问题描述:调用函数输出星号图,体会与理解函数的工作过程,并为其后编制自定义函数实现特定功能。
*程序输出:星号图
*/  
#include <iostream>
using namespace std;
void printchs(int m,char ch)  //定义能输出一行若干个指定字符的函数。
{
  for(int j=1;j<=m;++j)
        cout<<ch;
}

int main()
{
    int n=10,i; //n代表要输出的行数。
    for(i=1; i<=n; ++i)
    {
        printchs(n-i,'*'); //调用函数,括号里为自定义输出的*数量。
        printchs(2*i-1,' ');
        cout<<endl;
    }
    return 0;
}




运行结果:





知识点总结:

对printchs函数的调用,以及printchs的功能要求,编写printchs函数。



学习心得:

想想上上个周写那个星号图的代码好纠结好惆怅。。果然知识就是力量,现在学了这玩意儿,还用怕啥星号图?!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: