请用C++ 编写程序,计算结果保存在TXT
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了请用C++ 编写程序,计算结果保存在TXT相关的知识,希望对你有一定的参考价值。
程序是:
#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的!
其他地方可以改!
我用的是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)
怎么修改。 参考技术A #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();
参考技术B #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);
本回答被提问者采纳
实验任务3
1.编写程序,输入商品名、单价和数量,计算总金额。将程序代码和运行结果截图。(30分)
2.编写程序,任意输入一个汉字,给出其Unicode编码。将程序代码和运行结果截图。(20分)
3.编程程序,输入三角形的三条边,计算该三角形的周长。将程序代码和运行结果截图。(30分)
4.将你的代码与教材P45页的代码进行比较,并回答如下问题。(请用红色字体作答)
P45所给的代码中,a+b>c、a+c>b和c+b>a分别表示什么含义?(5分)
a+b>c&&a+c>b&&c+b>a表示什么含义?(5分)
这段代码中为什么要使用if语句?(10分)()提示:可参考教材P49-50,或者课程群的相关视频)
5.附加题:在以上调试程序的过程中,记录下至少一种错误信息和解决方法。(10分)
错误信息:
解决方法:
以上是关于请用C++ 编写程序,计算结果保存在TXT的主要内容,如果未能解决你的问题,请参考以下文章
对于‘用C#编写一个员工工资计算’问题的代码编写风格和结构设计考虑的比较发现自己还是太弱,大家可以在评论区中提出我代码中的不足
怎么用C或C++来编写一个抓包程序,或者是编写一个能够保存抓出的包然后分析出结果的程序,要个思路!
C++程序编写压缩器/解压器(长度-游程编码的压缩/解压+霍夫曼编码压缩/解压 (霍夫曼树))