Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE IN C Create and debug this program in Visual Studio. Name your code Source.c and upload for testing. You will write 3 functions: int

PLEASE IN C

Create and debug this program in Visual Studio. Name your code Source.c and upload for testing.

You will write 3 functions:

int readDoubleArray (double d[], int size) which reads numbers into double array d[] until size numbers have been read, or until the user types a newline, whichever comes first. Returns the number of array elements read. HINT: to read in an array in a loop with scanf(), use the following trick to detect the end of line:

char c=0; int count = scanf("%lf%c", &(d[i]), &c); //add code here to handle 2 cases: count <2, meaning user typed an empty line, and c==' ', meaning input is finished 

double dotProduct(double a[], double b[], int size) which returns the sum of the products of a[i]*b[i], for arrays of length "size"

void printDoubleArray (double d[], int size) which prints the numbers in d[] on a single line, separated by a comma and a space, terminated with a newline

Your main() program should:

(1) Prompt the user to enter a list of numbers followed by a non-numeric. Call readDoubleArray() to put them into a double array already declared: Ex:

Enter a list of numbers followed by ENTER: -1 2.2 3 q 

(2) Prompt the user to enter a second list of numbers, with the same # of items as the first. followed by a non-numeric. Call readDoubleArray() to put them into another double array already declared: Ex:

Enter more numbers, followed by ENTER: 2 4.1 5 q 

(3) Call the dot product function and print the results, and print the array contents using printDoubleArray(): Ex:

The dot product of: -1, 2.2, 3 and 2, 4.1, 5 is 22.02 

(4) If the user enters no numbers for either array, just a non-numeric, print "Error: zero length array input" and exit the program. This error check should NOT be in readDoubleArray(), it should be in the main() program when it checks the size returned by readDoubleArray(): Ex:

Enter a list of numbers followed by a non-numeric: -q Error: zero length array input 

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

Marketing Database Analytics

Authors: Andrew D. Banasiewicz

1st Edition

0415657881, 978-0415657884

More Books

Students also viewed these Databases questions

Question

jive the amplitude, period, and an equation for each curv 27t

Answered: 1 week ago