急啊! 求一道C++题的答案
填空题填写横线的空白使程序输出如下要求结果(3)要求输出结果****************#####################//proj2.cpp#includ...
填空题 填写横线的空白 使程序输出如下要求结果
(3)要求输出结果
*
***
*****
*******
#######
#######
#######
// proj2.cpp
#include <iostream>
using namespace std;
class CharShape {
public:
CharShape(char ch) : _ch(ch) {};
virtual void Show() = 0;
protected:
char _ch; // 组成图形的字符
};
class Triangle : public CharShape {
public:
Triangle(char ch, int r) : CharShape(ch), _rows(r) {}
void Show();
private:
int _rows; // 行数
};
class Rectangle: public CharShape {
public:
Rectangle(char ch, int r, int c):CharShape(ch),_rows(r), _cols(c) {}
void Show();
private:
int _rows, _cols; // 行数和列数
};
void Triangle::Show() // 输出字符组成的三角形
{
for (int i = 1; i <= _rows; i++) {
//********found********
for (int j = 1; j <= __________; j++)
cout << _ch;
cout << endl;
}
}
void Rectangle::Show() // 输出字符组成的矩形
{
//********found********
for (int i = 1; i <= __________; i++) {
//********found********
for (int j = 1; j <= __________; j++)
cout << _ch;
cout << endl;
}
}
//********found******** 为fun函数添加形参
void fun(__________) { cs.Show(); }
int main()
{
Triangle tri('*', 4);
Rectangle rect('#', 3, 8);
fun(tri);
fun(rect);
return 0;
} 展开
(3)要求输出结果
*
***
*****
*******
#######
#######
#######
// proj2.cpp
#include <iostream>
using namespace std;
class CharShape {
public:
CharShape(char ch) : _ch(ch) {};
virtual void Show() = 0;
protected:
char _ch; // 组成图形的字符
};
class Triangle : public CharShape {
public:
Triangle(char ch, int r) : CharShape(ch), _rows(r) {}
void Show();
private:
int _rows; // 行数
};
class Rectangle: public CharShape {
public:
Rectangle(char ch, int r, int c):CharShape(ch),_rows(r), _cols(c) {}
void Show();
private:
int _rows, _cols; // 行数和列数
};
void Triangle::Show() // 输出字符组成的三角形
{
for (int i = 1; i <= _rows; i++) {
//********found********
for (int j = 1; j <= __________; j++)
cout << _ch;
cout << endl;
}
}
void Rectangle::Show() // 输出字符组成的矩形
{
//********found********
for (int i = 1; i <= __________; i++) {
//********found********
for (int j = 1; j <= __________; j++)
cout << _ch;
cout << endl;
}
}
//********found******** 为fun函数添加形参
void fun(__________) { cs.Show(); }
int main()
{
Triangle tri('*', 4);
Rectangle rect('#', 3, 8);
fun(tri);
fun(rect);
return 0;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询