herrDeng網內搜尋

自訂搜尋

Ads

2016年10月21日 星期五

Ex7 C++寫入csv檔

請用C++亂數~N(70,10)產生100個隨機亂數

寫進csv檔

20 則留言:

A10433015 提到...

#include<fstream>
#include <iostream>
#include<cstdlib>
#include<random>
#include<ctime>
#include<cmath>
using namespace std;
int main(){
fstream fout;
fout.open("text.csv", ios::out | ios::trunc);
int seed = clock();
mt19937_64 gen(seed);

normal_distribution<double> x(70, 10);
int a[100];
double sum = 0;
double s = 0;
double sum2;
for (int i = 0; i < 100; i++){
a[i] = (int)(round(x(gen)));
fout << a[i] << ",";
fout << "\n";
}
fout.close();
system("Pause");
return (0);
}

A10433018 提到...

#include<iostream>
#include<cstdlib>
#include<random>
#include<ctime>
#include<fstream>
using namespace std;
int main()
{
fstream fout;
fout.open("test.csv", ios::out | ios::trunc);
int seed = clock();
mt19937_64 gen(seed);
normal_distribution<double> x(70, 10);
int a[1000];
double s = 0;
for (int i = 0; i < 100; i++){
a[i] = x(gen);
cout << a[i] << "\t";
fout << a[i]<<",\n";
s = a[i]+s;
if (i % 10 == 9)cout << endl;
}
fout.close();
system("Pause");
return 0;
}

a10433024 提到...

#include&lt;fstream&gt;
#include &lt;iostream&gt;
#include&lt;cstdlib&gt;
#include&lt;random&gt;
#include&lt;ctime&gt;
#include&lt;cmath&gt;
using namespace std;
int main(){
fstream fout;
fout.open("text.csv", ios::out | ios::trunc);
int seed = clock();
mt19937_64 gen(seed);

normal_distribution&lt;double&gt; x(70, 10);
int a[100];
double sum = 0;
double s = 0;
double sum2;
for (int i = 0; i &lt; 100; i++){
a[i] = (int)(round(x(gen)));
fout &lt;&lt; a[i] &lt;&lt; ",";
fout &lt;&lt; "\n";
}
fout.close();
system("Pause");
return (0);
}

a10433036 提到...

#include&lt;fstream&gt;
#include &lt;iostream&gt;
#include&lt;cstdlib&gt;
#include&lt;random&gt;
#include&lt;ctime&gt;
#include&lt;cmath&gt;
using namespace std;
int main(){
fstream fout;
fout.open("text.csv", ios::out | ios::trunc);
int seed = clock();
mt19937_64 gen(seed);

normal_distribution&lt;double&gt; x(70, 10);
int a[100];
double sum = 0;
double s = 0;
double sum2;
for (int i = 0; i &lt; 100; i++){
a[i] = (int)(round(x(gen)));
fout &lt;&lt; a[i] &lt;&lt; ",";
fout &lt;&lt; "\n";
}
fout.close();
system("Pause");
return (0);
}

A10433021 提到...

#include
#include
#include
using namespace std;
int main(){
fstream fout;
fout.open("test.csv", ios::out | ios::trunc);
fout << "hello, 1,2,3\n";
fout << "hello, 2,2,4\n";
fout.close();
system("Pause");
return 0;
}

b10233127李昆和 提到...

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <random>
#include <ctime>
using namespace std;
int main()
{
fstream fout;
fout.open("test.csv",ios::out | ios::trunc);
int seed = clock();
mt19937_64 gen(seed);
normal_distribution<double> X(70, 10);
double a[1000];
double sum = 0;
double sum2 = 0;
for (int i = 0; i < 1000; i++){
a[i] = X(gen);
fout << a[i] << "\t";
sum += a[i];

if (i % 10 == 9)fout << endl;
}
sum = sum / 1000.0;

for (int i = 0; i < 1000; i++){
sum2 += (a[i] * a[i]) - (sum * sum);
}
sum2 = sum2 / 1000;
double s = sqrt(sum2);

fout << (clock()-seed)/1000.0 <<"sec." << endl;
system("Pause");
return 0;
}

b10233137 提到...

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <random>
#include <ctime>
using namespace std;
int main()
{
fstream fout;
fout.open("test.csv", ios::out | ios::trunc);
int seed = clock();
mt19937_64 gen(seed);
normal_distribution<double> X(70, 10);
double a[1000];
double sum = 0;
double sum2 = 0;
for (int i = 0; i < 1000; i++){
a[i] = X(gen);
fout << a[i] << "\t";
sum += a[i];

if (i % 10 == 9)fout << endl;
}
sum = sum / 1000.0;
for (int i = 0; i < 1000; i++){
sum2 += (a[i] * a[i]) - (sum * sum);
}
sum2 = sum2 / 1000;
double s = sqrt(sum2);
fout << (clock() - seed) / 1000.0 << "sec." << endl;
system("Pause");
return 0;
}

b10233137 提到...

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <random>
#include <ctime>
using namespace std;
int main()
{
fstream fout;
fout.open("test.csv", ios::out | ios::trunc);
int seed = clock();
mt19937_64 gen(seed);
normal_distribution<double> X(70, 10);
double a[1000];
double sum = 0;
double sum2 = 0;
for (int i = 0; i < 1000; i++){
a[i] = X(gen);
fout << a[i] << "\t";
sum += a[i];

if (i % 10 == 9)fout << endl;
}
sum = sum / 1000.0;
for (int i = 0; i < 1000; i++){
sum2 += (a[i] * a[i]) - (sum * sum);
}
sum2 = sum2 / 1000;
double s = sqrt(sum2);
fout << (clock() - seed) / 1000.0 << "sec." << endl;
system("Pause");
return 0;
}

B10233169 陳振萱 提到...

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <random>
#include <ctime>
#include <cmath>
using namespace std;
int main()
{
fstream fout;
fout.open("test.csv", ios::out | ios::trunc);
int seed = clock();
mt19937_64 gen(seed);
normal_distribution<double> X(70, 10);
double a[1000];
double sum = 0;
double sum2 = 0;
for (int i = 0; i < 1000; i++){
a[i] = X(gen);
cout << a[i] << "\t";
sum += a[i];

if (i % 10 == 9)cout << endl;
}
sum = sum / 1000.0;
for (int i = 0; i < 1000; i++){
sum2 += (a[i] * a[i]) - (sum * sum);
}
sum2 = sum2 / 1000;
double s = sqrt(sum2);
cout << (clock() - seed) / 1000.0 << "sec." << endl;
system("Pause");
return 0;
}

B10433011 提到...

#include<iostream>
#include<fstream>
#include<cstdlib>
#include<random>
#include<ctime>
using namespace std;
int main(){
fstream fout;
fout.open("test.csv", ios::out | ios::trunc);
int test = clock();
mt19937_64 gen(test);
normal_distribution<double>dis(70, 10);
int a[100];
for (int i = 0; i < 100; i++){
a[i] = (int)(round(dis(gen)));
fout << a[i] << "\n";
}
fout.close();
fout << endl;
system("Pause");
return 0;
}

B10433080 提到...

#include
#include
#include
#include
#include
#include
using namespace std;
int main(){
fstream fout;
fout.open("text.csv", ios::out | ios::trunc);
int seed = clock();
mt19937_64 gen(seed);

normal_distribution x(70, 10);
int a[100];
double sum = 0;
double s = 0;
double sum2;
for (int i = 0; i < 100; i++){
a[i] = (int)(round(x(gen)));
fout << a[i] << ",";
fout << "\n";
}
fout.close();
system("Pause");
return (0);
}

B10433092 提到...

#include
#include
#include
#include
#include
#include
using namespace std;
int main(){
fstream fout;
fout.open("text.csv", ios::out | ios::trunc);
int seed = clock();
mt19937_64 gen(seed);

normal_distribution x(70, 10);
int a[100];
double sum = 0;
double s = 0;
double sum2;
for (int i = 0; i < 100; i++){
a[i] = (int)(round(x(gen)));
fout << a[i] << ",";
fout << "\n";
}
fout.close();
system("Pause");
return (0);
}

B10233095 提到...

#include
#include
#include
#include
#include
using namespace std;
int main()
{
fstream fout;
fout.open("test.csv",ios::out | ios::trunc);
int seed = clock();
mt19937_64 gen(seed);
normal_distribution X(70, 10);
double a[1000];
double sum = 0;
double sum2 = 0;
for (int i = 0; i < 1000; i++){
a[i] = X(gen);
fout << a[i] << "\t";
sum += a[i];

if (i % 10 == 9)fout << endl;
}
sum = sum / 1000.0;

for (int i = 0; i < 1000; i++){
sum2 += (a[i] * a[i]) - (sum * sum);
}
sum2 = sum2 / 1000;
double s = sqrt(sum2);

fout << (clock()-seed)/1000.0 <<"sec." << endl;
system("Pause");
return 0;
}

b10233072 提到...

#include
#include
#include
#include
#include
using namespace std;
int main()
{
fstream fout;
fout.open("test.csv",ios::out | ios::trunc);
int seed = clock();
mt19937_64 gen(seed);
normal_distribution X(70, 10);
double a[1000];
double sum = 0;
double sum2 = 0;
for (int i = 0; i < 1000; i++){
a[i] = X(gen);
fout << a[i] << "\t";
sum += a[i];

if (i % 10 == 9)fout << endl;
}
sum = sum / 1000.0;

for (int i = 0; i < 1000; i++){
sum2 += (a[i] * a[i]) - (sum * sum);
}
sum2 = sum2 / 1000;
double s = sqrt(sum2);

fout << (clock()-seed)/1000.0 <<"sec." << endl;
system("Pause");
return 0;
}

B10433103 提到...

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <random>
#include <ctime>
#include <cmath>
using namespace std;

int main(){
fstream fout;
fout.open("test.csv",::ios::out|ios::trunc);
int seed=clock();
mt19937_64 gen(seed);
normal_distribution<double>dis(70,10);
double a[100];
double sum=0;
for(int i=0;i<100;i++){
a[i]=(int)(round(dis(gen)));
fout<< a[i];
sum+=a[i];
if(i%10==9)fout <<endl;
fout.close();
}
system("pause");
return 0;
}

B10233108 提到...

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <random>
#include <ctime>
using namespace std;
int main()
{
fstream fout;
fout.open("test.csv",ios::out | ios::trunc);
int seed = clock();
mt19937_64 gen(seed);
normal_distribution<double> X(70, 10);
double a[1000];
double sum = 0;
double sum2 = 0;
for (int i = 0; i < 1000; i++){
a[i] = X(gen);
fout << a[i] << "\t";
sum += a[i];

if (i % 10 == 9)fout << endl;
}
sum = sum / 1000.0;

for (int i = 0; i < 1000; i++){
sum2 += (a[i] * a[i]) - (sum * sum);
}
sum2 = sum2 / 1000;
double s = sqrt(sum2);

fout << (clock()-seed)/1000.0 <<"sec." << endl;
system("Pause");
return 0;
}

B10233082 唐偉強 提到...

#include
#include
#include
#include
#include
#include
using namespace std;
int main(){
fstream fout;
fout.open("text.csv", ios::out | ios::trunc);
int seed = clock();
mt19937_64 gen(seed);

normal_distribution x(70, 10);
int a[100];
double sum = 0;
double s = 0;
double sum2;
for (int i = 0; i < 100; i++){
a[i] = (int)(round(x(gen)));
fout << a[i] << ",";
fout << "\n";
}
fout.close();
system("Pause");
return (0);
}

B10133186 提到...

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <random>
#include <ctime>
using namespace std;
int main()
{
fstream fout;
fout.open("test.csv",ios::out | ios::trunc);
int seed = clock();
mt19937_64 gen(seed);
normal_distribution<double> X(70, 10);
double a[1000];
double sum = 0;
double sum2 = 0;
for (int i = 0; i < 1000; i++){
a[i] = X(gen);
fout << a[i] << "\t";
sum += a[i];

if (i % 10 == 9)fout << endl;
}
sum = sum / 1000.0;

for (int i = 0; i < 1000; i++){
sum2 += (a[i] * a[i]) - (sum * sum);
}
sum2 = sum2 / 1000;
double s = sqrt(sum2);

fout << (clock()-seed)/1000.0 <<"sec." << endl;
system("Pause");
return 0;
}

b10233074 提到...

#include
#include
#include
#include
#include
#include
using namespace std;
int main(){
fstream fout;
fout.open("text.csv", ios::out | ios::trunc);
int seed = clock();
mt19937_64 gen(seed);

normal_distribution x(70, 10);
int a[100];
double sum = 0;
double s = 0;
double sum2;
for (int i = 0; i < 100; i++){
a[i] = (int)(round(x(gen)));
fout << a[i] << ",";
fout << "\n";
}
fout.close();
system("Pause");
return (0);
}

B10233077 提到...

#include
#include
#include
#include
#include
#include
using namespace std;
int main(){
fstream fout;
fout.open("text.csv", ios::out | ios::trunc);
int seed = clock();
mt19937_64 gen(seed);

normal_distribution x(70, 10);
int a[100];
double sum = 0;
double s = 0;
double sum2;
for (int i = 0; i < 100; i++){
a[i] = (int)(round(x(gen)));
fout << a[i] << ",";
fout << "\n";
}
fout.close();
system("Pause");
return (0);
}

Related Posts Plugin for WordPress, Blogger...

熱門文章