c++-小白求教C++怎样用函数输出图形

问题描述

小白求教C++怎样用函数输出图形

原题是这样的

二、设计以下三个函数:dispRectangle()、dispRightAngledTriangle()、dispIsoscelesTriangle(),分别用来显示由指定字符和指定行数构成的矩形、直角三角形和等腰三角形。并在主函数给出如图1所示的菜单(就是很简单的那种输入一二三的菜单,我就不写了,大神们肯定都懂),输入选项,调用相应的图形显示函数。

#include
using namespace std;
void dispRectangle(int,int,char);
void dispRightAngledTriangle(int,char);
void dispIsoscelesTriangle(int,char);
int main()
{
int a,b,c,d,e,f,g,k;
do{
cout<<"1.输出矩形"<
cout
cout
int xuhao;
cin>>xuhao;
switch(xuhao)
{
case 1:
cout<<"你选择了矩形"<
cout
cin>>a>>b>>c;
cout<
break;
case 2:
cout
cout
cin>>d,e;
cout<
break;
case 3:
cout
cout
cin>>f>>g;
cout<
break;
default:
cout
}
cout
cin>>k;
}
while(k==1);
return 0;
}
void dispRectangle(int a,int b,char c)
{
for(int i=0;i<a;i++)
for(int j=0;j<b;j++)
cout<<b<<endl;
}
void dispRightAngledTriangle(int d,char e)
{
for(int i=0;i<d;i++)
{
for(int j=0;j<=i;j++)
cout<<e<<endl;
}
}
void dispIsoscelesTriangle(int f,char g)
{
for(int i=0;i<f;i++)
{
for(int j=0;j<=f-i-1;j++)
cout<<" "<<endl;
for(int w=0;w<2*i+1;w++)
cout<<g<<endl;
}
}

我不知道这样对不对,他显示
cpp(21) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'void' (or there is no acceptable conversion)
cpp(27) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'void' (or there is no acceptable conversion)
cpp(33) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'void' (or there is no acceptable conversion)
执行 cl.exe 时出错.

大神们,拜托帮我改一下,非常谢谢。

解决方案

sprintf() 格式化输出函数(图形)

解决方案二:

建议楼主重新发一遍代码,代码放在代码便签内,报错所在的那几行有点奇怪啊cout cout cin>>f>>g; ??
是复制的问题么?

//放在这里
时间: 2024-09-17 03:49:33

c++-小白求教C++怎样用函数输出图形的相关文章

c++-C++小白求教怎样用函数输出图形,拜托拜托,在线等

问题描述 C++小白求教怎样用函数输出图形,拜托拜托,在线等 原题是这样的 二.设计以下三个函数:dispRectangle().dispRightAngledTriangle().dispIsoscelesTriangle(),分别用来显示由指定字符和指定行数构成的矩形.直角三角形和等腰三角形.并在主函数给出如图1所示的菜单(就是很简单的那种输入一二三的菜单,我就不写了,大神们肯定都懂),输入选项,调用相应的图形显示函数. #include using namespace std; void

c++-C++编程小白求教,逆序输出字符串

问题描述 C++编程小白求教,逆序输出字符串 #include #include #include #include //逆序输出字符串 using namespace std; void print(const char a[],int size){ int i; for(i=size;i>0;i--) cout<<a[i-1]; cout<<endl; } void main(){ int i=0; char a[50]; while(getchar()!='n'){ a

linux 下shell脚本调用 (小白求教)

问题描述 linux 下shell脚本调用 (小白求教) Shell脚本怎么实现调用一个可执行文件并在脚本中执行该文件中的命令? (可执行文件打开后是命令行模式) 解决方案 啥意思?脚本里调用脚本?直接以廖本名调用啊 解决方案二: 这个是不是类似,在shell命令行窗口中打开另外一个命令行? 解决方案三: 用fork,system等,可以获取它的管道输出等 解决方案四: 文件中的命令? 没明白什么意思? 解决方案五: 可以尝试使用source函数................. 解决方案六:

小白求教java基础问题

问题描述 小白求教java基础问题 System.out.println(from.getCell(8).equals("手机直充预付款") + " " + from.getCell(8)); 为何输出的是"false 手机直充预付款 " 为什么是false啊? 解决方案 getCell(8)的值是不是有空格啊,看你最后的输出,最后是带空格的 解决方案二: 不是不是首尾有空格. 解决方案三: 你去检查看看你的 from.getCell(8)获取的

c语言-小白求教C语言头文件和源文件的关系

问题描述 小白求教C语言头文件和源文件的关系 书上说头文件一般只有声明,比如void func(void); 函数的定义则是在源文件中,那也就是说我新建的项目要使用以前项目中写过的一些函数(有相关头文件含有它们的声明),光靠把相关头文件#include进来是没用的喽? 可是为什么像stdio.h这样的可以不用包含它的源文件呢? 解决方案 stdio.h的实现在stdlib里,封装起来了,不能通过文本格式打开,防止被修改! 很多函数只提供给你头文件(相当于接口,只给用户使用),而没有具体实现的源代

小白求教,关于oracle字符串插入问题

问题描述 小白求教,关于oracle字符串插入问题 oracle将一个字符插入到一个字符串中指定位置,该用什么函数,如果要删除某字符串中的某个指定位置的字符用什么函数,求教,在线等 解决方案 update group_test set name = substr(name,0,4)||'x'||substr(name,4+1,length(name)) where rownum = 1 解决方案二: length() 和 instr() 这两个应该可以的 解决方案三: 如果位置是固定的,使用su

c++ SYN 网络编程遇到问题 小白求教

问题描述 c++ SYN 网络编程遇到问题 小白求教 以下是代码,运行无错误,但是用wireshark 抓不到发出的SYN包,求高手解释原因.. #include <stdlib.h> #include <stdio.h> #include <winsock2.h> //加入WinSock的头文件 #include <WS2TCPIP.h> //设置IP_HDRINCL选中需要 #include <time.h> #include <ios

select-想知道SQL group by的一个问题。小白求教。。

问题描述 想知道SQL group by的一个问题.小白求教.. 比如现有表Ad_inf _id name describe 1 test1 d1 2 test2 d2 3 test2 d2 4 test2 d3 5 test3 d2 6 test4 d4 执行select * from Ad_inf group by name,describe 得到的是什么样的? 解决方案 select * from Ad_inf group by name,describe 如果你是使用oracle查询,这

画图-如何用MFC中OnDraw函数输出的文字是反向的?

问题描述 如何用MFC中OnDraw函数输出的文字是反向的? 如题,要用绘图程序画图,在OnDraw函数中,如何输出反向的文字? 解决方案 自己先把文字反向reverse了,再OnDraw来TextOut 解决方案二: 只能是先把你要输出的字符改为反向的,然后再输出,比如用strrev来吧字符串反向一下