Question

Create a table using a 40x5 array of doubles and make sure each column has a...

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <ctime>
#include <cstdlib>
#include <iomanip>
#include <fstream>

using namespace std;

int main()
{
   //Declaring a constant
const long m_rand = 1000000L;
  
//Declaring variables
double x1 = 20.50, x2 = 30.50, x;

srand(time(NULL));
  
//Declaring double array
double arr[40][5];

//Defines an output stream for the data file
ofstream dataOut;


/* This for lopp will generate double type
* values and populate them into an array
*/
for(int i=0;i<40;i++)
{
for(int j=0;j<5;j++)
{
   //Generating double type random values
arr[i][j]= x1 + ( x2 - x1) * (rand() % m_rand) / m_rand;
   }  
   }

//creating and Opening the output file
dataOut.open("D:\\doubleArray.txt");
  
  
//This for loop is used to display headings
   for(int i=0;i<5;i++)
{       
   cout<<"col"<<i+1<<"\t";
   dataOut<<"col"<<i+1<<"\t";

}
cout<<"\n"<<endl;
dataOut<<"\n"<<endl;

//Setting precision
std::cout << std::setprecision(2) << std::fixed;
  
//This nested for loop is used to display the elements in the array
   for(int i=0;i<40;i++)
{
  
for(int j=0;j<5;j++)
{
cout<<arr[i][j]<<"\t";
dataOut<<std::fixed<< std::setprecision(2)<<arr[i][j]<<"\t";
   }  
   cout<<"\n";
   dataOut<<"\n";
   }

return 0;
}

______________________

Output:

CProgram Files (x86)\Dev-CppiMinGW64\bin\randomdoubles.exe CO11 CO14 20.64 20.67 20.56 20.67 20.55 20.81 20.82 20.59 20.81 20

____________________

doubleArray.txt (We can see this file under D Dive.As we specified the path of the file as D:\\doubleArray.txt)

col1 col2 col3 col4 col5  

20.64   20.67   20.56   20.67   20.55  
20.81   20.82   20.59   20.81   20.80  
20.57   20.63   20.54   20.60   20.69  
20.58   20.51   20.69   20.60   20.76  
20.53   20.55   20.73   20.51   20.56  
20.59   20.79   20.53   20.79   20.62  
20.81   20.78   20.77   20.81   20.50  
20.68   20.70   20.63   20.62   20.51  
20.54   20.75   20.57   20.61   20.53  
20.61   20.65   20.65   20.72   20.53  
20.64   20.62   20.74   20.81   20.67  
20.53   20.76   20.81   20.51   20.70  
20.55   20.53   20.75   20.78   20.63  
20.55   20.80   20.58   20.62   20.56  
20.51   20.58   20.64   20.79   20.81  
20.53   20.69   20.70   20.56   20.65  
20.55   20.63   20.55   20.55   20.68  
20.66   20.51   20.63   20.72   20.70  
20.67   20.57   20.79   20.65   20.51  
20.80   20.67   20.52   20.60   20.72  
20.64   20.70   20.59   20.52   20.67  
20.77   20.59   20.62   20.78   20.69  
20.71   20.72   20.67   20.74   20.53  
20.70   20.64   20.68   20.52   20.77  
20.68   20.66   20.79   20.64   20.71  
20.77   20.70   20.70   20.77   20.55  
20.82   20.73   20.63   20.50   20.63  
20.51   20.53   20.67   20.63   20.69  
20.78   20.72   20.74   20.75   20.79  
20.77   20.57   20.52   20.75   20.51  
20.58   20.65   20.58   20.61   20.55  
20.71   20.73   20.74   20.61   20.77  
20.51   20.66   20.53   20.83   20.70  
20.74   20.67   20.80   20.52   20.68  
20.52   20.82   20.55   20.65   20.57  
20.75   20.70   20.81   20.81   20.67  
20.74   20.76   20.58   20.76   20.73  
20.65   20.73   20.80   20.82   20.72  
20.80   20.69   20.52   20.68   20.60  
20.82   20.82   20.57   20.73   20.75  

______Thank You

Add a comment
Know the answer?
Add Answer to:
Create a table using a 40x5 array of doubles and make sure each column has a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • using C language Create an array of doubles with 5 elements. In the array prompt the...

    using C language Create an array of doubles with 5 elements. In the array prompt the user to enter 5 temperature values (in degree Fahrenheit). Do this within main. Create a user defined function called convert2Cels. This function will not return any values to main with a return statement. It should have parameters that include the temperature array and the number of elements. The function should convert the values for Fahrenheit to Celsius and save them back into the same...

  • USING C++ Create an array of 8 doubles (initialize how you want). Create a pointer that...

    USING C++ Create an array of 8 doubles (initialize how you want). Create a pointer that points to the first element. Using the pointer only (no array indices allowed), print out the contents of each entry.

  • Create a program that uses a Jagged Array. The program will create an array with 50...

    Create a program that uses a Jagged Array. The program will create an array with 50 rows. Each of the values for each element of the array will be randomly generated. The random values will be between 1 and 20. Depending on the value generated for each row, you will create an array with that number of columns for that row. Each column created will contain the value to the left plus 1. After you create and populate the entire...

  • This should be in Java Create a simple hash table You should use an array for...

    This should be in Java Create a simple hash table You should use an array for the hash table, start with a size of 5 and when you get to 80% capacity double the size of your array each time. You should create a class to hold the data, which will be a key, value pair You should use an integer for you key, and a String for your value. For this lab assignment, we will keep it simple Use...

  • In Java. Write a program in a single file that: Main: Creates 10 random doubles, all...

    In Java. Write a program in a single file that: Main: Creates 10 random doubles, all between 1 and 11, Calls a class that writes 10 random doubles to a text file, one number per line. Calls a class that reads the text file and displays all the doubles and their sum accurate to two decimal places. There has to be three classes, main for create random numbers, one to write , one to read all in the same file...

  • Be sure to include the number of total swaps in each sort. Create a total_Time variable...

    Be sure to include the number of total swaps in each sort. Create a total_Time variable is the total time it takes all 1000 iterations to run. DO NOT INCLUE THE TIME IT TAKES TO GENERATE A UNIQUE RANDOM ARRAY EACH LOOP. In java, Write a computer program that prompts the user for one number, n for the number of items in the array to sort and create and sort 1000 different arrays of this size,  timing the run to get...

  • Task: Comparing the performance between Linear Probing and Double Hashing. Requirements: Please make sure your program...

    Task: Comparing the performance between Linear Probing and Double Hashing. Requirements: Please make sure your program compiles, otherwise your submission will not be graded and you will receive zero. Point deduction rule: Compile warning: 3 points each. Minor error: such as not meeting the assignment input/output requirement, 5 points each. Major error: examples include, infinite loop, runtime errors, any runtime exception, 15 points each. Any code not compliant to the assignment requirement (e.g., not using List interface and AbstractMap and...

  • In JAVA Create a program with an array with the following data: 50 12 31 76...

    In JAVA Create a program with an array with the following data: 50 12 31 76 5 23 15 Use a text file (.txt created in notepad) to read the data into the array. Write a sort method (your choice of sorting algorithm) to sort the array values values - highest to lowest. Write a method to determine the minimum value. Your program should call the sort and minimum methods. Output the sorted array and minimum value.  

  • please make sure to write down all the coding and the output for it and to...

    please make sure to write down all the coding and the output for it and to do all three steps Student Name: 1. Write a class named Employee that holds the following data about an employee in attributes: name, ID number, department, and job title. (employee.py) 2. Create a UML diagram for Employee class. (word file) 3. Create a program that stores Employee objects in a dictionary. Use the employee ID number as the key. (employee_App.py) The program should present...

  • Write a javascript file Create an object constructor (using new and function ) to hold a...

    Write a javascript file Create an object constructor (using new and function ) to hold a recipes information. It has to include properties for title (a string), servings (a number), and ingredients (an array of strings). It also has to have a method called print(nOfServings). in your app, create a single object using this contractor and call its print method On separate lines (a Document.write() statement for each), log (display on console) the recipe information so it looks like: myObj.print(2)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT