Read-only archive. Login and posting are unavailable.
Reply
 
Thread Tools
  #1  
Old 28-02-2020, 10:57
Member
Join Date: 05-2013
Posts: 54
Các cao nhân C++ giúp em với ạ

Chào các bác, đề bài là vẽ 1 quả tên lửa từ hình tam giác cân , hình chữ nhật và hình thang cân


Các bác cho em hỏi code bên dưới em viết có gì sai ạ, em chạy với sửa 2 tiếng rồi chưa xong


#include
using namespace std;
void drawTriangle(int numRows, char fill, int offset);
void drawTrapezoid( int numRows, char Fill, int offset);
void drawRectangle(int offset, int width, int height, char fill);
void drawRow(int offset, int numChars, char fill);
int main()
{
int numRows,offset;
char Fill;
cout<<"Please enter the number of rows, char fill, and offset:"<>numRows>>Fill>>offset;
for (int i=1;i<=numRows;i++)
{
for (int j=1;j<=numRows - i;j++)
{cout<<' ';}
for (int j=1;j<=2*i-1;j++)
{cout<> offset >> width >> height>>fill;
drawRectangle(offset, width, height, fill);
}
void drawRectangle(int offset, int width, int height, char fill) {
for (int i = 0; i < height; i++)
drawRow(offset, width, fill);
}
void drawRow(int offset, int numChars, char fill) {
for (int i = 0; i < offset; i++)
cout << ' ';
for (int i = 0; i < numChars; i++)
cout << fill;
cout << endl;
}
void drawTrapezoid( int numRows, char Fill, int offset)
{
int numRows,offset;
char Fill;
cout<<"Please enter the number of rows, char fill, and offset:"<>numRows>>Fill>>offset;
for (int i=1;i<=numRows;i++)
{
for (int j=1;j<=numRows - i;j++)
{cout<<' ';}
for (int j=1;j<=2*i+3;j++)
{cout<<Fill;}
cout<<endl;
}
}
__________________
[COLOR="Black"]Re: ​“Tại sao tham nhũng lại bị tâm thần nhiều thế!”
[/COLOR]
[QUOTE=Etoile Filante;99099598]Có lần năm cấp 3, ngày hội hướng nghiệp tao có hỏi bà cô : em muốn làm lãnh đạo đảng được không cô? Bà hỏi lại : em có bị khùng không?
Giờ tao mới hiểu ý bả đó là tiêu chuẩn đầu vào.[/QUOTE]
Reply With Quote
  #2  
Old 28-02-2020, 12:34
anhsayvimen's Avatar
Senior Member
Join Date: 02-2012
Posts: 145
Re: Các cao nhân C++ giúp em với ạ

Code:
#include 

using namespace std;

void DrawRectangle(unsigned int height, unsigned int width)
{
	for (int i = 0; i < height; ++i)
	{
		cout << "  ";
		for (int j = 0; j < width; ++j)
		{
			cout << "* ";
		}
		cout << endl;
	}
}

void DrawTrapezoid(unsigned int width, unsigned int height)
{
	for (int row = 0; row < height; ++row) 
	{
		for (int col = height - row; col > 0; --col) 
		{
			cout << " ";
		}
		for (int col = 0; col < (width + 2 * row); ++col)
		{
			cout << "*";
		}
		cout << endl;
	}
}

void DrawTritangle(unsigned int height)
{
	int width = 1;
	for (int i = 1, k = 0; i <= height; ++i, k = 0)
	{
		for (width = 1; width <= height - i; ++width)
		{
			cout << "  ";
		}

		while (k != 2 * i - 1)
		{
			cout << "* ";
			++k;
		}
		cout << endl;
	}
}

int main()
{
	DrawTritangle(4);
	DrawRectangle(10,5);
	DrawTrapezoid(3,5);
	return 0;
}
Mình sửa cho bạn nhé, bạn bị thiếu kiến thức về khai báo biến rồi nha
Reply With Quote
  #3  
Old 28-02-2020, 13:32
Member
Join Date: 05-2013
Posts: 54
Re: Các cao nhân C++ giúp em với ạ

Quote:
Originally Posted by anhsayvimen View Post
Code:
#include 

using namespace std;

void DrawRectangle(unsigned int height, unsigned int width)
{
	for (int i = 0; i < height; ++i)
	{
		cout << "  ";
		for (int j = 0; j < width; ++j)
		{
			cout << "* ";
		}
		cout << endl;
	}
}

void DrawTrapezoid(unsigned int width, unsigned int height)
{
	for (int row = 0; row < height; ++row) 
	{
		for (int col = height - row; col > 0; --col) 
		{
			cout << " ";
		}
		for (int col = 0; col < (width + 2 * row); ++col)
		{
			cout << "*";
		}
		cout << endl;
	}
}

void DrawTritangle(unsigned int height)
{
	int width = 1;
	for (int i = 1, k = 0; i <= height; ++i, k = 0)
	{
		for (width = 1; width <= height - i; ++width)
		{
			cout << "  ";
		}

		while (k != 2 * i - 1)
		{
			cout << "* ";
			++k;
		}
		cout << endl;
	}
}

int main()
{
	DrawTritangle(4);
	DrawRectangle(10,5);
	DrawTrapezoid(3,5);
	return 0;
}
Mình sửa cho bạn nhé, bạn bị thiếu kiến thức về khai báo biến rồi nha
Cảm ơn bác nhiều . Em thề với bác code bác viết khác hoàn toàn với code ông giáo sư em dạy
__________________
[COLOR="Black"]Re: ​“Tại sao tham nhũng lại bị tâm thần nhiều thế!”
[/COLOR]
[QUOTE=Etoile Filante;99099598]Có lần năm cấp 3, ngày hội hướng nghiệp tao có hỏi bà cô : em muốn làm lãnh đạo đảng được không cô? Bà hỏi lại : em có bị khùng không?
Giờ tao mới hiểu ý bả đó là tiêu chuẩn đầu vào.[/QUOTE]
Reply With Quote
  #4  
Old 28-02-2020, 14:24
minhbon's Avatar
Đã tốn tiền
Join Date: 09-2014
Posts: 999
Re: Các cao nhân C++ giúp em với ạ

Thường nó sẽ báo lỗi gì, dòng nào. Bạn nên học cách đọc thông báo lỗi thì sẽ tự mình fix được các ca về sau.
__________________
[COLOR="White"]Quyền lực của nhà nước là quyền tạo ra tội phạm. Họ sẽ đưa ra nhiều điều luật đến mức chúng mày đéo thể sống mà không phạm tội.[/COLOR]
Reply With Quote
  #5  
Old 29-02-2020, 16:57
shinigami1997's Avatar
Member
Join Date: 01-2017
Posts: 91
Re: Các cao nhân C++ giúp em với ạ

Cái này chắc được

#include
using namespace std;
void hinhtamgiac(int y)
{
for (int i = 0; i < y; i++)
{
for (int j = 0; j = y - i-1)
cout << "*";
else
cout << " ";
}
cout << endl;

}
}
void hinhchunhat(int x, int y,int lechvao)
{
for (int i = 0; i < y; i++)
{
for (int j = 0; j < x + lechvao; j++)
{
if (j < lechvao)
cout << " ";
else
cout << "@";
}
cout << endl;
}
}
void hinhthangcan(int daynho, int daylon)
{
for (int i = 0; i < (daylon-daynho)/2 +1; i++)
{
for (int j = 0; j < (daynho + (daylon - daynho) / 2)+i; j++)
{
if (j < (daylon - daynho) / 2 - i)
cout << " ";
else
cout << "$";
}
cout << endl;
}
}
int main()
{
hinhtamgiac(7);
hinhchunhat(9, 20, 2);
hinhthangcan(5, 13);
system("pause");
}
Reply With Quote
  #6  
Old 29-02-2020, 20:22
Fzen's Avatar
Đã tốn tiền
Join Date: 03-2015
Posts: 758
Re: Các cao nhân C++ giúp em với ạ

Hồi xưa cũng xoắn não với mấy trò in hình ra console
__________________
[CODE]https://forums.voz.vn/profile.php?do=addlist&userlist=ignore&u=ID[/CODE]
Reply With Quote
  #7  
Old 01-03-2020, 16:21
Junior Member
Join Date: 04-2017
Posts: 23
Re: Các cao nhân C++ giúp em với ạ

Quote:
Originally Posted by khonglamgimacungban View Post
Chào các bác, đề bài là vẽ 1 quả tên lửa từ hình tam giác cân , hình chữ nhật và hình thang cân


Các bác cho em hỏi code bên dưới em viết có gì sai ạ, em chạy với sửa 2 tiếng rồi chưa xong


#include
using namespace std;
void drawTriangle(int numRows, char fill, int offset);
void drawTrapezoid( int numRows, char Fill, int offset);
void drawRectangle(int offset, int width, int height, char fill);
void drawRow(int offset, int numChars, char fill);
int main()
{
int numRows,offset;
char Fill;
cout<<"Please enter the number of rows, char fill, and offset:"<>numRows>>Fill>>offset;
for (int i=1;i<=numRows;i++)
{
for (int j=1;j<=numRows - i;j++)
{cout<<' ';}
for (int j=1;j<=2*i-1;j++)
{cout<> offset >> width >> height>>fill;
drawRectangle(offset, width, height, fill);
}
void drawRectangle(int offset, int width, int height, char fill) {
for (int i = 0; i < height; i++)
drawRow(offset, width, fill);
}
void drawRow(int offset, int numChars, char fill) {
for (int i = 0; i < offset; i++)
cout << ' ';
for (int i = 0; i < numChars; i++)
cout << fill;
cout << endl;
}
void drawTrapezoid( int numRows, char Fill, int offset)
{
int numRows,offset;
char Fill;
cout<<"Please enter the number of rows, char fill, and offset:"<>numRows>>Fill>>offset;
for (int i=1;i<=numRows;i++)
{
for (int j=1;j<=numRows - i;j++)
{cout<<' ';}
for (int j=1;j<=2*i+3;j++)
{cout<<Fill;}
cout<<endl;
}
}
Cơ bản là bác chủ thread hỏi code bác ấy có gì sai ở đâu mà chưa thấy bác nào chỉ ra )
Em ko rành lắm nhưng mà có thể đi từng bước.
Ví dụ: em thấy bác define 4 cái hàm nhưng không hề gọi trong hàm main, thì define để làm gì đâu?
Reply With Quote
Reply

« Previous Thread | Next Thread »

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT +7. The time now is 11:02.