Free考研资料
标题:
具体题目讨论帖
[打印本页]
作者:
沦陷在2009
时间:
08-3-19 11:53
标题:
具体题目讨论帖
———过滤广告线
———过滤广告线
———过滤广告线
———过滤广告线
———过滤广告线
———过滤广告线
若你有什么具体不明白的问题,可以发在这个帖子里面
呵呵 请勿新开帖[我错了 - - 有需求的可开新帖,如果问题有代表性还有奖励 - -]
[
本帖最后由 沦陷在2009 于 2008-3-25 20:47 编辑
]
作者:
沦陷在2009
时间:
08-3-19 21:30
/*设计一个计算+、-、*、/的程序
程序循环从标准输入读入表达式:
输入: 4+2 回车
则输出:4+2=6
输入: 4*2 回车
则输出:4*2=8
………
当用户输入:000回车时程序退出
实现要求:
1、有输入提示和输出提示,如要输入表达式时,可以提示: \"pealse intput arithmetic expression: \" 输出时,提示:
\" 4+2=6\"。 计算在用户输入的表达式为 0 0 0 时程序结束。
2、为你的程序加上注释,使得其清晰可读。
3、尝试利用调试程序来修改你程序的逻辑错误。 */
#include <iostream>
using namespace std;
void main()
{
long double opd1,opd2,result;
long int op;
cout << \"pealse intput arithmetic expression: \" ;
cin >> opd1 >> op >> opd2 ;
if( opd1!=0 && op!=0 && opd2!=0 )
{
if (op == \'+\' || op == \'-\' || op == \'*\' || op == \'/\' )
{
switch(op)
{
case \'+\':
result = opd1 + opd2;
cout<<opd1<< op << opd2<<\"=\"<<result<<endl;
break;
case \'-\':
result = opd1 - opd2;
cout<<opd1<< op << opd2<<\"=\"<<result<<endl;
break;
case \'*\':
result = opd1 * opd2;
cout<<opd1<< op << opd2<<\"=\"<<result<<endl;
break;
case \'/\':
result = opd1 / opd2;
cout<<opd1<< op << opd2<<\"=\"<<result<<endl;
break;
default : cout <<endl;
}
}
else cout << \"This is not a arithmetic expression ! \" ;
}
else cout <<\"quit the program!\"<<endl;
}
我不知道到底哪儿出问题了 程序编译没有错误 可是没能达到题目要求 呵呵
后续:问题已解决,只需将long int op;改成char op;便可
但是我不是怎么明白为什么改了char型后就可以了 哪位高人指教一下
[
本帖最后由 沦陷在2009 于 2008-3-19 22:13 编辑
]
作者:
iamgwh
时间:
08-3-20 08:48
提示:
作者被禁止或删除 内容自动屏蔽
作者:
沦陷在2009
时间:
08-4-1 22:43
要求是输入一个3×4的数组,然后再逆序输出,然后就是控制只能输入12个数,输完12个数后自动逆序输出12个数;
以下是没有加入控制输入的语句,烦高人指点:
【小贴士:复制整段代码,然后粘帖到VC++中去,选定全部代码,再 ALT+F8 系统会帮你
自动排版
好】
#include <iostream>
using namespace std;
int main()
{
int i,j;
int a[3][4] ;
for (i=0;i<3;i++)
{
for (j=0;j<4;j++)
{
cin >> a
[j];
}
}
for (i=2;i>=0;i--)
{
for (j=3;j>=0;j--)
{
cout << a
[j] << \" \" ;
}
}
return 0;
}
作者:
langzixiaosan99
时间:
08-5-3 13:26
提示:
作者被禁止或删除 内容自动屏蔽
作者:
智轩
时间:
08-6-18 21:00
很好的贴子,很好的问题。
作者:
zxmin112
时间:
08-6-19 16:05
我说一点,关于做表达式的那个题目:
输入的表达式我们可以把它做为一个字符串来处理,我们可以通过math.h文件里边的函数来识别数字与符号;
作者:
zxmin112
时间:
08-6-19 16:21
C++忘光了.逆序输出的那个基本就那个程序.我稍微的补了点.不知道对不对.
#include <iostream>
using namespace std;
int main()
{
int i,j;
int a[3][4] ;
for (i=0;i<3;i++)
{
Cout<<”input number of the lines ”<<i<<endl;
for (j=0;j<4;j++)
{
cin >> a
[j];
}
}
cout<<”output the arry”<<endl;
for (i=2;i>=0;i--)
{
for (j=3;j>=0;j--)
{
cout << a
[j] << \" \" ;
}
}
return 0;
}
作者:
zxmin112
时间:
08-6-19 16:22
是a
[j]
欢迎光临 Free考研资料 (http://test.freekaoyan.com/)
Powered by Discuz! X3.2