Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A) Write C++ code of a function named dot_Product( ) that returns either the pro

ID: 3739821 • Letter: A

Question

A) Write C++ code of a function named dot_Product( ) that returns either the product of two numbers x1 and y1 or the dot product of a pair of two-dimensional vectors (x1, y1) and (x2, y2) or the dot product of a pair of three-dimensional vectors (x1, y1, z1) and (x2, y2, z2), according to whether the function is passed 2, 4, or 6 parameters. For example, with four arguments (3.0, 8.0, -4. 0, 6.0), the call dot_Product would return (3.0) (-4.0) + (8.0) (6.0) = 36.0.

B]  

Write the C++ code of a function that takes as inputs, a number, position, and digit. The function should return a new number with the digit at position 'position' changed to 'digit'. Start counting the digits from the left means left most digit will be at position zero.

For example:

number = 127856, position = 3, digit = 9: the function returns 127956

number = 2431, position = 0, digit = 5: the function returns 5431

You can write helper functions such as countTheTotalDigitsOfNumber or ReturnDigitAtPosition (returns the value of a digit given a position). Think carefully on the number of parameters and return values of each function. cin and cout should only be done in the main function. The rest of functions should exchange values via parameters.

NOTE ; YOU CANNOT USE ANY break, continue or goto statement IN THIS

Explanation / Answer

A) //in this i use function overloading ....depending on no. of arguments in calling function one of these function is // called.


double dot_product(double x1 , double y1 ){
return x1*y1;
}
double dot_product(double x1 , double x2 , double y1 , double y2 ){
double sum = x1*y1;
sum+=x2*y2;
return sum;
}
double dot_product(double x1 , double x2 , double x3 , double y1 , double y2 , double y3 ){
double sum = x1*y1;
sum+=x2*y2;
sum+=x3*y3;
return sum;
}

B)

int changePosDig(int num, int pos, int dig){
int temp=num;
int arr[20];
int i=0;
while(temp>0){
arr[i]= temp%10;
temp/=10;
i++;
}
arr[i-pos-1]=dig;
temp=0;
for(int j=i-1;j>=0;j--){
temp+=arr[j];
temp*=10;
}
temp/=10;
return temp;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote