BASIC转为C++

来源:百度知道 编辑:UC知道 时间:2024/07/03 03:38:01
想问问以下BASIC语句怎么转换成C++语句,(请把头文件也写出来,即写出完整的答案).
1)获得随机数
10 A=RND(1)
20 PRINT A
RUN
.15237845

2)顺序文件(*.dat)的读写操作
10 A=59:OPEN "AAA" FOR OUTPUT AS #1
20 WRITE #1,"YES","NO",A
30 CLOSE #1
40 OPEN "AAA" FOR INPUT AS #1
50 INPUT #1,A$,B$,C:CLOSE#1
60 PRINT A$,B$,C
RUN
YES
NO
59

#include <iostream>

using namespace std;

int main(){
float a=rand();
cout<<a;
return 0;
}

#include <iostream>
#include <fstream>

using namespace std;

int main () {
int A=59;
ofstream out("AAA");
out<<"YES"<<endl<<"NO"<<endl<<A;
out.close();
ifstream in("AAA");
string s;
while(getline(in,s)) cout <<s<<endl;
in.close();
return 0;
}

int main()
{
srand (time(NULL));

int i = rand();
printf ("i=%d\n",i);

return 0;
}
第二个看得有点糊涂,就不蒙了