请用C++ 编写程序,计算结果保存在TXT

程序是:#include<stdio.h>#include<math.h>voidmain(){floatA,B,x,y,I;printf("enterAandB\n")... 程序是:
#include <stdio.h>
#include<math.h>
void main ()
{
float A,B,x,y,I;
printf ("enter A and B \n");
scanf("%f%f",&A,&B);
printf("波长是%f,相位差是%f",A,B);

for (x=-35.0;x<35;x=x+0.14)
for(y=-35.0;y<35;y=y+0.14)
{ if (x*x+y*y<1225)
I=A*A*sin(atan2(x, y))*sin(atan2(x,y))*B;
else
I=0.0;
printf("%f ",I);
}
printf("\n");
}

最好,显示500*500的矩形的!
程序可改动
我用的是VC ++编译,并且我需要复制过去就直接能编译的程序,因为我vc还不是很了解!
麻烦你了
编译时:
ompiling...
数据1.c
d:\vc98\include\eh.h(32) : fatal error C1189: #error : "eh.h is only for C++!"
执行 cl.exe 时出错.

数据1.obj - 1 error(s), 0 warning(s)

还有能不能将运行结果导入excle结果最好500*500显示!
若excle不显示500*500,可以修改x=x+0.14和 y=y+0.14,显示100*100的!

其他地方可以改!
展开
 我来答
zhanghai0302
2008-10-25
知道答主
回答量:1
采纳率:0%
帮助的人:0
展开全部
楼上大哥,问题补充有误,担忧乘不上下面的只能用这个形式:呵呵
我用的是VC ++编译,并且我需要复制过去就直接能编译的程序,因为我vc还不是很了解!
麻烦你了
编译时:
Configuration: 新建 文本文档 - Win32 Debug
ompiling...
新建 文本文档.c
d:\vc98\include\new(16) : error C2061: syntax error : identifier 'bad_alloc'
d:\vc98\include\new(16) : error C2059: syntax error : ';'
d:\vc98\include\new(16) : error C2059: syntax error : ':'
d:\vc98\include\new(27) : error C2059: syntax error : '}'
d:\vc98\include\new(28) : error C2061: syntax error : identifier 'nothrow'
d:\vc98\include\new(28) : error C2059: syntax error : ';'
d:\vc98\include\new(34) : warning C4229: anachronism used : modifiers on data are ignored
d:\vc98\include\new(34) : error C2061: syntax error : identifier 'delete'
d:\vc98\include\new(34) : error C2059: syntax error : ';'
d:\vc98\include\new(34) : error C2059: syntax error : 'type'
d:\vc98\include\new(35) : warning C4229: anachronism used : modifiers on data are ignored
d:\vc98\include\new(35) : error C2061: syntax error : identifier 'new'
d:\vc98\include\new(35) : error C2059: syntax error : ';'
d:\vc98\include\new(35) : error C2059: syntax error : 'type'
d:\vc98\include\new(36) : warning C4229: anachronism used : modifiers on data are ignored
d:\vc98\include\new(36) : error C2061: syntax error : identifier 'new'
d:\vc98\include\new(36) : error C2059: syntax error : ';'
d:\vc98\include\new(36) : error C2059: syntax error : 'type'
d:\vc98\include\new(41) : error C2054: expected '(' to follow 'inline'
d:\vc98\include\new(41) : warning C4229: anachronism used : modifiers on data are ignored
d:\vc98\include\new(41) : error C2085: 'operator' : not in formal parameter list
d:\vc98\include\new(41) : error C2146: syntax error : missing ',' before identifier 'new'
d:\vc98\include\new(41) : error C2143: syntax error : missing ';' before '('
d:\vc98\include\new(41) : error C2059: syntax error : ')'
d:\vc98\include\new(44) : error C2054: expected '(' to follow 'inline'
d:\vc98\include\new(44) : warning C4229: anachronism used : modifiers on data are ignored
d:\vc98\include\new(44) : error C2085: 'operator' : not in formal parameter list
d:\vc98\include\new(44) : error C2146: syntax error : missing ',' before identifier 'delete'
d:\vc98\include\new(44) : error C2143: syntax error : missing ';' before '('
d:\vc98\include\new(44) : error C2059: syntax error : ')'
d:\vc98\include\new(52) : error C2061: syntax error : identifier 'throw'
d:\vc98\include\new(52) : error C2059: syntax error : ';'
d:\vc98\include\new(52) : error C2059: syntax error : ')'
d:\vc98\include\fstream(17) : error C2143: syntax error : missing ')' before ':'
d:\vc98\include\fstream(17) : error C2081: 'ios_base' : name in formal parameter list illegal
d:\vc98\include\fstream(17) : error C2143: syntax error : missing '{' before ':'
d:\vc98\include\fstream(17) : error C2059: syntax error : ':'
d:\vc98\include\fstream(17) : error C2059: syntax error : ')'
d:\vc98\include\fstream(20) : error C2143: syntax error : missing '{' before '<'
d:\vc98\include\fstream(20) : error C2059: syntax error : '<'
d:\vc98\include\fstream(23) : error C2061: syntax error : identifier 'bool'
d:\vc98\include\fstream(23) : error C2059: syntax error : ';'
d:\vc98\include\fstream(23) : error C2143: syntax error : missing ')' before '&'
d:\vc98\include\fstream(23) : error C2143: syntax error : missing '{' before '&'
d:\vc98\include\fstream(23) : error C2059: syntax error : '&'
d:\vc98\include\fstream(23) : error C2059: syntax error : ')'
d:\vc98\include\fstream(30) : error C2061: syntax error : identifier 'bool'
d:\vc98\include\fstream(30) : error C2059: syntax error : ';'
d:\vc98\include\fstream(30) : error C2143: syntax error : missing ')' before '&'
d:\vc98\include\fstream(30) : error C2143: syntax error : missing '{' before '&'
d:\vc98\include\fstream(30) : error C2059: syntax error : '&'
d:\vc98\include\fstream(30) : error C2059: syntax error : ')'
d:\vc98\include\fstream(38) : error C2143: syntax error : missing '{' before '<'
d:\vc98\include\fstream(38) : error C2059: syntax error : '<'
d:\vc98\include\fstream(41) : error C2061: syntax error : identifier 'bool'
d:\vc98\include\fstream(41) : error C2059: syntax error : ';'
d:\vc98\include\fstream(41) : error C2143: syntax error : missing ')' before '*'
d:\vc98\include\fstream(41) : error C2081: '_iobuf' : name in formal parameter list illegal
d:\vc98\include\fstream(41) : error C2143: syntax error : missing '{' before '*'
d:\vc98\include\fstream(41) : error C2059: syntax error : ')'
d:\vc98\include\fstream(42) : error C2054: expected '(' to follow '_Fi'
d:\vc98\include\fstream(43) : error C2061: syntax error : identifier 'bool'
d:\vc98\include\fstream(43) : error C2059: syntax error : ';'
d:\vc98\include\fstream(43) : error C2143: syntax error : missing ')' before '*'
d:\vc98\include\fstream(43) : error C2081: '_iobuf' : name in formal parameter list illegal
d:\vc98\include\fstream(43) : error C2143: syntax error : missing '{' before '*'
d:\vc98\include\fstream(43) : error C2059: syntax error : ')'
d:\vc98\include\fstream(44) : error C2054: expected '(' to follow '_Fi'
d:\vc98\include\fstream(46) : error C2143: syntax error : missing '{' before '<'
d:\vc98\include\fstream(46) : error C2059: syntax error : '<'
d:\vc98\include\fstream(57) : error C2143: syntax error : missing '{' before '<'
d:\vc98\include\fstream(57) : error C2059: syntax error : '<'
d:\vc98\include\fstream(60) : error C2061: syntax error : identifier 'bool'
d:\vc98\include\fstream(60) : error C2059: syntax error : ';'
d:\vc98\include\fstream(60) : error C2143: syntax error : missing ')' before '*'
d:\vc98\include\fstream(60) : error C2081: '_iobuf' : name in formal parameter list illegal
d:\vc98\include\fstream(60) : error C2143: syntax error : missing '{' before '*'
d:\vc98\include\fstream(60) : error C2059: syntax error : ')'
d:\vc98\include\fstream(61) : error C2054: expected '(' to follow '_Fi'
d:\vc98\include\fstream(62) : error C2061: syntax error : identifier 'bool'
d:\vc98\include\fstream(62) : error C2059: syntax error : ';'
d:\vc98\include\fstream(62) : error C2143: syntax error : missing ')' before '*'
d:\vc98\include\fstream(62) : error C2081: '_iobuf' : name in formal parameter list illegal
d:\vc98\include\fstream(62) : error C2143: syntax error : missing '{' before '*'
d:\vc98\include\fstream(62) : error C2059: syntax error : ')'
d:\vc98\include\fstream(63) : error C2054: expected '(' to follow '_Fi'
d:\vc98\include\fstream(65) : error C2143: syntax error : missing '{' before '<'
d:\vc98\include\fstream(65) : error C2059: syntax error : '<'
d:\vc98\include\fstream(254) : error C2143: syntax error : missing '{' before '<'
d:\vc98\include\fstream(254) : error C2059: syntax error : '<'
d:\vc98\include\fstream(292) : error C2143: syntax error : missing '{' before '<'
d:\vc98\include\fstream(292) : error C2059: syntax error : '<'
d:\vc98\include\fstream(331) : error C2143: syntax error : missing '{' before '<'
d:\vc98\include\fstream(331) : error C2059: syntax error : '<'
d:\vc98\include\eh.h(4) : error C2061: syntax error : identifier 'namespace'
d:\vc98\include\eh.h(4) : error C2059: syntax error : ';'
d:\vc98\include\eh.h(7) : error C2065: 'ofstream' : undeclared identifier
d:\vc98\include\eh.h(7) : error C2146: syntax error : missing ';' before identifier 'fout'
d:\vc98\include\eh.h(7) : warning C4013: 'fout' undefined; assuming extern returning int
d:\vc98\include\eh.h(8) : error C2143: syntax error : missing ';' before 'type'
d:\vc98\include\eh.h(9) : error C2065: 'cout' : undeclared identifier
d:\vc98\include\eh.h(9) : error C2297: '<<' : illegal, right operand has type 'char [14]'
d:\vc98\include\eh.h(9) : error C2065: 'endl' : undeclared identifier
d:\vc98\include\eh.h(10) : error C2065: 'cin' : undeclared identifier
d:\vc98\include\eh.h(10) : error C2065: 'A' : undeclared identifier
d:\vc98\include\eh.h(10) : error C2065: 'B' : undeclared identifier
d:\vc98\include\eh.h(10) : warning C4552: '>>' : operator has no effect; expected operator with side-effect
d:\vc98\include\eh.h(11) : error C2297: '<<' : illegal, right operand has type 'char [7]'
d:\vc98\include\eh.h(11) : fatal error C1003: error count exceeds 100; stopping compilation
执行 cl.exe 时出错.
新建 文本文档.obj - 1 error(s), 0 warning(s)

还有能不能将运行结果导入excle结果最好500*500显示!
若excle不显示500*500,可以修改x=x+0.14和 y=y+0.14,显示100*100的!

其他地方可以改

下层则是出现这种情况:
--------------------Configuration: 新建 文本文档 (2) - Win32 Debug--------------------
Compiling...
新建 文本文档 (2).c
c:\documents and settings\administrator\桌面\新建 文本文档 (2).c(7) : error C2143: syntax error : missing ';' before 'type'
c:\documents and settings\administrator\桌面\新建 文本文档 (2).c(9) : error C2065: 'A' : undeclared identifier
c:\documents and settings\administrator\桌面\新建 文本文档 (2).c(9) : error C2065: 'B' : undeclared identifier
c:\documents and settings\administrator\桌面\新建 文本文档 (2).c(11) : error C2065: 'x' : undeclared identifier
c:\documents and settings\administrator\桌面\新建 文本文档 (2).c(11) : warning C4244: '=' : conversion from 'const double ' to 'int ', possible loss of data
c:\documents and settings\administrator\桌面\新建 文本文档 (2).c(11) : warning C4244: '=' : conversion from 'double ' to 'int ', possible loss of data
c:\documents and settings\administrator\桌面\新建 文本文档 (2).c(13) : error C2065: 'y' : undeclared identifier
c:\documents and settings\administrator\桌面\新建 文本文档 (2).c(13) : warning C4244: '=' : conversion from 'const double ' to 'int ', possible loss of data
c:\documents and settings\administrator\桌面\新建 文本文档 (2).c(13) : warning C4244: '=' : conversion from 'double ' to 'int ', possible loss of data
c:\documents and settings\administrator\桌面\新建 文本文档 (2).c(16) : error C2065: 'I' : undeclared identifier
c:\documents and settings\administrator\桌面\新建 文本文档 (2).c(16) : warning C4244: '=' : conversion from 'double ' to 'int ', possible loss of data
c:\documents and settings\administrator\桌面\新建 文本文档 (2).c(18) : warning C4244: '=' : conversion from 'const double ' to 'int ', possible loss of data
执行 cl.exe 时出错.

新建 文本文档 (2).obj - 1 error(s), 0 warning(s)
怎么修改。
百度网友3117ea2
2008-10-25 · 超过19用户采纳过TA的回答
知道答主
回答量:33
采纳率:0%
帮助的人:26.5万
展开全部
#include <iostream>
#include <cmath>
#include <fstream>
using namespace std;

int main(){
ofstream fout("output.txt");
float A, B, x, y, l;
cout<<"enter A and B"<<endl;
cin>>A>>B;
cout<<"波长是"<<A<<"相位差是"<<B;
for(x=-35.0; x<35; x=x+0.14)
for(y=-35.0;y<35; y=y+0.14){
if(x*x+y*y<1225)
I=A*A*sin(atan2(x,y))*sin(atan2(x,y))*B;
else
I=0.0;
fout<<I<<"\t";
}
cout<<endl;
fout.close();
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
clover526
2008-10-25 · TA获得超过358个赞
知道小有建树答主
回答量:330
采纳率:0%
帮助的人:161万
展开全部
#include <stdio.h>
#include<math.h>
void main ()
{
FILE * fp = NULL;
fp = fopen("result.txt","w");
double A,B,x,y,I;
printf ("enter A and B \n");
scanf("%lf%lf",&A,&B);
printf("波长是%lf,相位差是%lf",A,B);
for (x=-35.0;x<35;x=x+0.14)
{
for(y=-35.0;y<35;y=y+0.14)
{
if (x*x+y*y<1225)
I=A*A*sin(atan2(x, y))*sin(atan2(x,y))*B;
else
I=0.0;
fprintf(fp,"%lf ",I);
}
fprintf(fp,"\n");
}
fclose(fp);
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式