#include<iostream.h>
class person
{
private:
int a,i,j,k;
public:
void fn();
void sn();
person();
};
person::person()
{
cout<<"*****************************打印一个松树***************************"<<endl;
}
void person::sn()
{
cout<<"请输入数值:";
while(cin>>a)
{
if(a>4&&a<8)
fn();
else
cout<<"输入错误"<<endl;
cout<<"请输入:";
}
}
void person::fn()
{
for(i=0;i<a;i++)
{
for(j=10;j>=i;j--)
{
cout<<" ";
}
for(k=1;k<=2*i+1;k++)
{
if(k%2!=0)
cout<<"*";
else
cout<<" ";
}
cout<<endl;
}
for(i=0;i<a+2;i++)
{
for(j=9;j>=i;j--)
{
cout<<" ";
}
for(k=1;k<=2*i+3;k++)
{
if(k%2!=0)
cout<<"*";
else
cout<<" ";
}
cout<<endl;
}
for(i=0;i<a+3;i++)
{
for(j=8;j>=i;j--)
{
cout<<" ";
}
for(k=1;k<=2*i+5;k++)
{
if(k%2!=0)
cout<<"*";
else
cout<<" ";
}
cout<<endl;
}
for(i=0;i<a+3;i++)
{
for(j=10;j>=0;j--)
{
cout<<" ";
}
for(k=1;k<2;k++)
{
cout<<"*";
}
cout<<endl;
}
}
void main()
{
int a ;
person st;
st.sn();
}
----------------解决方案--------------------------------------------------------
go C++
----------------解决方案--------------------------------------------------------
我刚学C++在练手,本人还处于C初级阶段~只需要看FOR循环算法~
----------------解决方案--------------------------------------------------------