C++ program Create a table using a 40x5 array of doubles and make sure each colu
ID: 3573672 • Letter: C
Question
C++ program
Create a table using a 40x5 array of doubles and make sure each column has a title. Also have the program write the data to a text file. Use the same titles as the table below, the tables should look the same or at least very similar to each other. The numbers do not have to be the same. Remember this is a C++ program.
f (Hz) Vs p-p (V) | EXRVo p-p Theoc | ExpAv(dB) Av(dB 100 10 0.00482 0.00000 0.01926 0.00000 10 0.04321 0.00000 400 0.07653 0.00000 500 44 0.11 89y 0.13657 0.23024 0.27532 531 0.33535 0.41723 1000 9.375 0.45757 0.56057 2000 8.125 1.59701 1.80353 3000 6.875 301030 3.25455 4000 5781 443697 4.75994 5000 577236 6.02060 6000 4.375 6.989/0 778044 3.594 9.09080 888844 10000 10.83184 10.54780 20000 1.5 16.47817 30000 1.062 20.04321 19.47751 40000 0.8125 22.52313 21.80353 50000 0.6875 2445258 60000 0.5312 26.03144 -25.49484 80000 0.4062 28.52548 27.82520 100000 0.3438 3046148 29.27388 - 071354000 0000 7237354044 2-8 U000 5 3 2 5 559644 08 7-8 7 34453 0000_6 5 7 0 3 4 90000 3 7-1 6 0 5 5 2-8-8 47705927 001245-8 2 7 01-8 5 4 4 82482 00001 069-3579 OOOO-0 0 0 0 1 3 4-6 7-8 1122222 4113-8 26-1 3 9 4 5 7 107600 8-8 2-5 44 CO CL 2 5 9 2 3 5 0 3 9 378 OB 14332151 4936-8 0 5 7 706290 ed 0147-335913 37425326 h r( 0000-1 2 3 4 504 90 85054054 TA 0-0 0 0 0 0 0 0 1 3 4 569 060 4-6-8-0 11222223 4-8-1 5 5 5 1 549 55228 27-63 o) 00004 3727-8 7-9-6-5-6 1-8 3-0 4 8653-1-8 7 5359 86543 9999-8-6 5 43 0-0-0-0-0-0-0-0-0-0-0 |0-0-0-0-0-0-0-0-0-0-0 00 0000000 0000 00 0-0-0-0-0-0-0 0000000 0-0 1234578 1234568 0000000 5-6-00) T 2 3 1234568Explanation / Answer
HI, Please find my code to write double data with title.
Please let me know in case of any issue.
#include <iostream>
#include <fstream>
using namespace std;
int main(){
// declaring title array and initializing with values
string title[] = {"f(Hz)", "Vs p-p(v)", "Exp Vo p-p(V",
"Theoe Av(dB)", "Exp Av(dB"};
// declaring double array of size 40x5
double arr[40][5];
//opening file
string filename;
cout<<"Enter output file name: ";
cin>>filename;
ofstream output(filename.c_str());
// read data in arr : Its user task
// writing to file
// writing title
output<<title[0]<<" "<<title[1]<<" "<<title[2]<<" "
<<title[3]<<" "<<title[4]<<endl;
// now writing data
for(int i=0; i<40; i++){
for(int j=0; j<5; j++){
output<<arr[j]<<" ";
}
output<<endl;
}
output.close();
cout<<"File written successfully"<<endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.