Read-only archive. Login and posting are unavailable.
View Full Version : Các cao nhân C++ giúp em với ạ
khonglamgimacungban
28-02-2020, 10:57
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
https://2.pik.vn/20205b833e4a-444b-45f0-b74d-e20e4d58784c.png
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 :sweat::sweat:
#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;
}
}
anhsayvimen
28-02-2020, 12:34
#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 :gach:
khonglamgimacungban
28-02-2020, 13:32
#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 :gach:
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 :waaaht::amazed::sweat::sosad:
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.
shinigami1997
29-02-2020, 16:57
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");
}
Hồi xưa cũng xoắn não với mấy trò in hình ra console
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
https://2.pik.vn/20205b833e4a-444b-45f0-b74d-e20e4d58784c.png
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 :sweat::sweat:
#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? :sexy:
vBulletin® v3.8.0, Copyright ©2000-2026, Jelsoft Enterprises Ltd.