Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program 8 - Dot Product The objective of this Program is to gain experience using nested loops and arrays in a program by reading, storing

image text in transcribed

image text in transcribed

Program 8 - Dot Product The objective of this Program is to gain experience using nested loops and arrays in a program by reading, storing and processing data from a file Design a C++ program to calculate the dot product of two arrays. The program should e program should be general enough to process a different number of data sets each time it is run, so the number of data process several sets of data from one file. Th sets to be processed is an entry in the file ta set, your program should do the following 1) Use a loop structure to read the data from a file and store it in two different arrays. 2) Once all the data has been read in, use a second loop to find the dot product of the two arrays. For example, the dot product of two arrays, x andy, with 3 elements each would be dotproduct-Xo * yo + x1 * y1 + x2 * y2 3) Print out the array values, with two decimal places, side by side, including the element number, and then print out the dot product value. Label the information clearly For example, a data set consisting of 2 arrays of 4 elements each could be arranged in a file like this 4 2.0 3.0 0.0 2.0 4.0 6.0 8.5 The printout for this data set would look something like the following. Array 2 2.0 4.0 6.0 8.5 Element Array 1 3.0 0.0 The dot product of the two arrays is 28.0 You should not need more than two arrays. Process each data set before you read in the next data set. You may assume there are never more than 50 elements in any array. You may choose to include functions in the program, but that is not a requirement. Test your program with the datafile Prog8data.tx available in Blackboard The data file contains 5 lines of text at the beginning describing how the file is set up Be sure to read, and print these lines of text, as well as the filename. Please do not alter the contents or arrangement of this file Use standard programming practices, including good use of variable names and good comments Program 8 - Dot Product The objective of this Program is to gain experience using nested loops and arrays in a program by reading, storing and processing data from a file Design a C++ program to calculate the dot product of two arrays. The program should e program should be general enough to process a different number of data sets each time it is run, so the number of data process several sets of data from one file. Th sets to be processed is an entry in the file ta set, your program should do the following 1) Use a loop structure to read the data from a file and store it in two different arrays. 2) Once all the data has been read in, use a second loop to find the dot product of the two arrays. For example, the dot product of two arrays, x andy, with 3 elements each would be dotproduct-Xo * yo + x1 * y1 + x2 * y2 3) Print out the array values, with two decimal places, side by side, including the element number, and then print out the dot product value. Label the information clearly For example, a data set consisting of 2 arrays of 4 elements each could be arranged in a file like this 4 2.0 3.0 0.0 2.0 4.0 6.0 8.5 The printout for this data set would look something like the following. Array 2 2.0 4.0 6.0 8.5 Element Array 1 3.0 0.0 The dot product of the two arrays is 28.0 You should not need more than two arrays. Process each data set before you read in the next data set. You may assume there are never more than 50 elements in any array. You may choose to include functions in the program, but that is not a requirement. Test your program with the datafile Prog8data.tx available in Blackboard The data file contains 5 lines of text at the beginning describing how the file is set up Be sure to read, and print these lines of text, as well as the filename. Please do not alter the contents or arrangement of this file Use standard programming practices, including good use of variable names and good comments

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data, Mining, And Analytics Components Of Strategic Decision Making

Authors: Stephan Kudyba

1st Edition

1466568704, 9781466568709

More Books

Students also viewed these Databases questions