9.21.2012

[C++ Hướng đối tượng] Code mẩu bài tập về nhà #3 :19.09

Ý tưởng: dùng mãng hai chiều. Chi tiết hơn -> hãy tham gia buổi học nhóm ngày mai: Ca 2 , P205, CS1, Q7.


#include<iostream.h>
#include<conio.h>
#include<time.h>
#define r 22
void time_start()
{
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
cout<<timeinfo ->tm_hour<<": ";
cout<<timeinfo ->tm_min<<": ";
cout<<timeinfo ->tm_sec;
}

int main()
{
char a[r][44],s1=30,s2=31,s3=0222;
for(int i=0;i<r;i++)
for(int j=0;j<44;j++)
a[i][j]=' ';
int n,mid,p=0,count;
R:system("cls");
cout<<"\t\t\t Home work #3 C++ 19.Sep.12\n";
cout<<"\t\tby Viet Trung - 05CDCT1 http://izone4u.blogspot.com/\n";
cout<<"\t IDE,CLR is powered by C-Free 5.0. All rights reserved\n";
cout<<"\t\t\t Welcome to Msys-Console\n";
cout<<"\t\t\t\t Clock ";time_start();
cout<<"\n--------------------------------------------------------------------------------\n";
cout<<"Nhap so dong [3-22]: ";
cin>>n;
if(n<2||n>22)
{
cout<<"\nFailed, Press any key to re-type !";
getch();
goto R;
}
mid=((n-1)*2+1)/2;
while(p<n)
{
//p++;//Xoa dong giua
for(int t=p;t<n;t++)
a[t][mid-p]='*';
for(int t=p;t<n;t++)
a[t][mid+p]='*';
p++;
};
for(int f=0;f<n;f++)
               count+=((n-1)*2+1)-(2*f);
system("cls");
cout<<”So sao da dung: “<<count<<endl;
cout<<"\nStyle 1 - "<<s1<<endl<<endl;
for(int i=0;i<n;i++)
for(int j=0;j<= mid*2;j++)
{
cout<<a[i][j];
if(j==mid*2) cout<<endl;
}
cout<<"\nStyle 2 - "<<s2<<endl<<endl;
for(int i=n-1;i>=0;i--)
for(int j=0;j<= mid*2;j++)
{
cout<<a[i][j];
if(j==mid*2) cout<<endl;
}
p=0;
while(p<n-1)
{
for(int t=p+1;t<n-1;t++)
a[t][mid-p]=' ';
for(int t=p+1;t<n-1;t++)
a[t][mid+p]=' ';
p++;
};
cout<<"\nStyle 3 - "<<s3<<endl<<endl;
for(int i=n-1;i>=0;i--)
for(int j=0;j<= mid*2;j++)
{
cout<<a[i][j];
if(j==mid*2) cout<<endl;
}
cout<<endl;
return 0;
}

1 Nhận xét:

Tại lúc 21:25:00 GMT+7 25 tháng 9, 2012 , Anonymous Nặc danh nói...

ui....còn dính cái adf...thiệt là rắc rối...nhưng đã đỡ hơn trước.^__^.Cái tên để chữ màu vàng được á. I Like It. tui thích màu vàng ^^

Sao k dùng lớp,cái này làm theo lớp được k. Cái này là lập trình theo cấu trúc bình thường ^__^.

 

Đăng nhận xét

Đăng ký Đăng Nhận xét [Atom]

<< Trang chủ