13,825
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
using namespace std;
//定义一个类;
class A
{
public:
A(int Width,int Height)//Width(宽),Height(高);
{
W=Width;
H=Height;
b=0;
}
void hua(int cc=1)//三角;
{
if(cc==1)
c=-1;
else c=cc-2;
while(H>0)
{
c+=2;
b=(W-c)/2;
for(int s=0;s<=b;s++)
cout<<"-";
for(int s=0;s<c;s++)
cout<<"*";
for(int s=0;s<=b;s++)
cout<<"-";
cout<<endl;
H--;
}
}
void go(int cc)//长条
{
b=(W-cc)/2;
c=cc;
while(H>0)
{
for(int s=0;s<=b;s++)
cout<<"-";
for(int s=0;s<c;s++)
cout<<"*";
for(int s=0;s<=b;s++)
cout<<"-";
H--;
cout<<endl;
}
}
private:
int W;
int H;
int b,c;
};
int main(int argc, char* argv[])
{
A a(29,10);//第一个
a.hua();
A b(29,10);//第二个
b.hua(7);
A c(29,10);//第三个
c.go(3);
Sleep(10000);//等待10秒
return 0;
}
#include<iostream>
using namespace std;
int length,width;
void display(int wid,int len,char firstchar,char secondchar,int stage){
int count;
if(stage==1) count=1;
else count=wid/3;
while(len!=0){
for(int i=1;i<=(wid-count)/2;i++) cout<<firstchar;
for(int i=(wid-count)/2+1;i<=(wid-count)/2+count;i++) cout<<secondchar;
for(int i=(wid-count)/2+count+1; i<=wid;i++)cout<<firstchar;
cout<<endl;
count+=2;
len--;
}
}
int main(){
char fchar,schar;
cout<<"请输入行数:"<<endl;
cin>>length;
cout<<"请输入列数:"<<endl;
cin>>width;
cout<<"请输入显示的两种字符:"<<endl;
cin>>fchar>>schar;
display(width,length/3,fchar,schar,1);
display(width,length/3,fchar,schar,2);
for(int i=1;i<=length-length/3*2;i++){
for(int j=1;j<=width/3;j++) cout<<fchar;
for(int j=1;j<=width/3;j++) cout<<schar;
for(int j=2; j<=width-width/3*2;j++)cout<<fchar;
cout<<endl;
}
return 0;
}
#include <iostream>
using namespace std;
void PrintChar(char ch, int count)
{
for (int i=0; i<count; i++)
cout << ch;
}
void Display(char firstChar, char secondChar, int lines, int width, int secondCharMin, int secondCharMax)
{
for (int i=0; i<lines; i++)
{
PrintChar(firstChar, (width - secondCharMin) / 2);
PrintChar(secondChar, secondCharMin);
PrintChar(firstChar, (width - secondCharMin) / 2);
cout << endl;
if (secondCharMin < secondCharMax)
secondCharMin += 2;
}
}
int main()
{
const char ch1 = '-';
const char ch2 = '*';
const int lines = 27;
Display(ch1, ch2, 8, lines, 1, 15);
Display(ch1, ch2, 9, lines, 7, 23);
Display(ch1, ch2, 6, lines, 3, 3);
return 0;
}