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

Codeblocks (C code) Write a program that prompts the user with the following mai

ID: 3668660 • Letter: C

Question

Codeblocks (C code) Write a program that prompts the user with the following main menu that prompts the user for an input. The program should check that the user input is valid and should prompt the user again otherwise:

E – Enter a Value

D – Dot product

C – Cross product

N – Vector Norm

A – Sum

M – Scalar Multiply

P – Print Value

Q – Terminate Program

If the user enters E from the main menu, the following prompt will be given: 1 – Enter a value for vector 1 2 – Enter a value for vector 2 3 – Enter a value for vector 3 a – Enter a value for scalar a b – Enter a value for scalar b c – Enter a value for scalar c If the user enters 1, 2 or 3, the following prompt will be given: Enter the x-,y-,and z-coordinates separated by spaces for vector . If the user enters a, b or c, the following prompt will be given: Enter the value of scalar . This operation will check for valid inputs. At the conclusion of this operation, the program will return to the main menu.

If the user enters D, the following prompt will be given: Dot Product: 1 – Enter a value for vector 1 2 – Enter a value for vector 2 3 – Enter a value for vector 3 a – Enter a value for scalar a b – Enter a value for scalar b c – Enter a value for scalar c Enter first argument, second argument, and where the resultant will be stored separated by spaces: So the user would enter “2 3 a” to take the dot product of vector 2 and vector 3 and store the result to scalar a. The operation will check for valid inputs. Both arguments must be vectors and the result must be a scalar. At the conclusion of this operation, the program will return to the main menu.

If the user enters C, the following prompt will be given: Cross Product: 1 – Enter a value for vector 1 2 – Enter a value for vector 2 3 – Enter a value for vector 3 a – Enter a value for scalar a b – Enter a value for scalar b c – Enter a value for scalar c Enter first argument, second argument, and where the resultant will be stored separated by spaces: So the user would enter “2 3 1” to take the cross product of vector 2 and vector 3 and store the result to vector 1. The operation will check for valid inputs. The arguments must be vectors and result must be a vector. At the conclusion of this operation, the program will return to the main menu.

If the user enters N, the following prompt will be given: Norm: 1 – Enter a value for vector 1 2 – Enter a value for vector 2 3 – Enter a value for vector 3 a – Enter a value for scalar a b – Enter a value for scalar b c – Enter a value for scalar c Enter argument, and where the resultant will be stored separated by spaces: So the user would enter “2 a” to take the square root of the dot project of vector 2 with vector 2 and store the result to scalar a. The operation will check for valid inputs. The argument must be a vector and the result must be a scalar. At the conclusion of this operation, the program will return to the main menu.

If the user enters A, the following prompt will be given: Sum: 1 – Enter a value for vector 1 2 – Enter a value for vector 2 3 – Enter a value for vector 3 a – Enter a value for scalar a b – Enter a value for scalar b c – Enter a value for scalar c Enter first argument, second argument, and where the resultant will be stored separated by spaces: So the user would enter “2 3 2” to add the vector two to the vector 3 and store the result to vector 2. The user issues “a 2 2” to add a to each element of 2 and store the result to vector 2. The user will enter “a b c” to add the scalar a to the scalar b and store the result to scalar c. The operation will check for valid inputs. At the conclusion of this operation, the program will return to the main menu.

If the user enters M, the following prompt will be given: Sum: 1 – Enter a value for vector 1 2 – Enter a value for vector 2 3 – Enter a value for vector 3 a – Enter a value for scalar a b – Enter a value for scalar b c – Enter a value for scalar c Enter first argument, second argument, and where the resultant will be stored separated by spaces: So the user would enter “a 1 2” to multiply each element of vector1 by scalar a and store the result to vector 2. The user will enter “a b c” to multiply the scalar a to the scalar b and store the result to scalar c. The operation will check for valid inputs. At the conclusion of this operation, the program will return to the main menu. If the user enters P, the following prompt will be given: Sum: 1 – Enter a value for vector 1 2 – Enter a value for vector 2 3 – Enter a value for vector 3 a – Enter a value for scalar a b – Enter a value for scalar b c – Enter a value for scalar c Enter value to be printed. Vectors are to be printed in the following format: 2.15x + -1.74y +5.57z The operation will check for valid inputs. At the conclusion of this operation, the program will return to the main menu. If the user enters Q, immediately terminate the program.

Rules: All data types vectors and scalars should be of type float.

Vectors contain three fields representing and x, y, and z value The value of each of the vectors and scalars will be stored until program termination.

The initial value of each scalar and vector will be 0.

NO FUNCTION SHALL HAVE MORE THAN 15 LINES OF CODE

Explanation / Answer

# include<stdio.h>
#include<conio.h>
#include<stdlib.h>

float a=0,b=0,c=0;                                     \global variables
float x1=0,y1=0,z1=0,x2=0,y2=0,z2=0,x3=0,y3=0,z3=0;    \global variables
void main()
{
char z;
while(1)
{
   printf("E-Enter a value D-Dot product C-Cross roduct N-Vector Norm A-Sum M-Scalar Multiply P-Print Value Q-Terminate Program");
   scanf("%c",&z);
   switch(z)
   {
    case 'E':
     enter();
     break;
    case 'D':
     dot();
     break;
    case'C':
     cross();
     break;
    case'N':
     norm();
     break;
    case'A':
     sum();
     break;
    case'M':
     scalar();
     break;
    case'P':
     print();
     break;
    case'Q':
     exit();
    default:
     printf("Entered option is invalid.");
   }
}
}

void enter()
{
char m;
clrscr();
printf("1 – Enter a value for vector 1 2 – Enter a value for vector 2 3 – Enter a value for vector 3 a – Enter a value for scalar a b – Enter a value for scalar b c – Enter a value for scalar c");
switch(m)
{
   case '1':
    printf("Enter the x-,y-,and z-coordinates separated by spaces for vector . ");
    scanf("%f%f%f ",&x1,&y1,&z1);
   case '2':
    printf("Enter the x-,y-,and z-coordinates separated by spaces for vector . ");
    scanf("%f%f%f ",&x2,&y2,&z2);
   case '3':
    printf("Enter the x-,y-,and z-coordinates separated by spaces for vector . ");
    scanf("%f%f%f ",&x3,&y3,&z3);
   case 'a':
    printf(" Enter the value of scalar .");
    scanf("%f",&a);
   case 'b':
    printf(" Enter the value of scalar .");
    scanf("%f",&b);
   case 'c':
    printf(" Enter the value of scalar .");
    scanf("%f",&c1);
   default:
    printf("Invalid value.");
}
}

void dot()
{
clrscr();
int arg1,arg2;
char res;
printf("1 – Enter a value for vector 1 2 – Enter a value for vector 2 3 – Enter a value for vector 3 a – Enter a value for scalar a b – Enter a value for scalar b c – Enter a value for scalar c");
scanf("%f",&m);
char m;
switch(m)
{
   case '1':
    printf("Enter the x-,y-,and z-coordinates separated by spaces for vector . ");
    scanf("%f%f%f ",&x1,&y1,&z1);
   case '2':
    printf("Enter the x-,y-,and z-coordinates separated by spaces for vector . ");
    scanf("%f%f%f ",&x2,&y2,&z2);
   case '3':
    printf("Enter the x-,y-,and z-coordinates separated by spaces for vector . ");
    scanf("%f%f%f ",&x3,&y3,&z3);
   case 'a':
    printf(" Enter the value of scalar .");
    scanf("%f",&a);
   case 'b':
    printf(" Enter the value of scalar .");
    scanf("%f",&b);
   case 'c':
    printf(" Enter the value of scalar .");
    scanf("%f",&c1);
   default:
    printf("Invalid value.");
}
   printf("Enter first argument, second argument, and where the resultant will be stored separated by spaces:");
    scanf("%d%d%c",&arg1,arg2,res);
   if((arg1==1 && arg2==2)||(arg1==2 && arg2==1))
    {
     if(res=='a')
      {
       a=x1*x2+y1*y2+z1*z2;
       printf("otput is: %d",a);
      }
     else if(res=='b')
      {
       b=x1*x2+y1*y2+z1*z2;
       printf("otput is: %d",b);
      }
     else if(res=='c')
      {
       c=x1*x2+y1*y2+z1*z2;
       printf("otput is: %d",c);
      }
    }
   else if((arg1==2 && arg2==3)||(arg1==3 && arg2==2))
    {
     if(res=='a')
      {
       a=x3*x2+y3*y2+z3*z2;
       printf("otput is: %d",a);
      }
     else if(res=='b')
      {
       b=x3*x2+y3*y2+z3*z2;
       printf("otput is: %d",b);
      }
     else if(res=='c')
      {
       c=x3*x2+y3*y2+z3*z2;
       printf("otput is: %d",c);
      }
    }
    else if((arg1==1 && arg2==3)||(arg1==1 && arg2==3))
    {
     if(res=='a')
      {
       a=x3*x1+y3*y1+z3*z1;
       printf("otput is: %d",a);
      }
     else if(res=='b')
      {
       b=x3*x1+y3*y1+z3*z1;
       printf("otput is: %d",b);
      }
     else if(res=='c')
      {
       c=x3*x1+y3*y1+z3*z1;
       printf("otput is: %d",c);
      }
    }

}

void cross()
{
clrscr();
int arg1,arg2;
char res;
printf("1 – Enter a value for vector 1 2 – Enter a value for vector 2 3 – Enter a value for vector 3 a – Enter a value for scalar a b – Enter a value for scalar b c – Enter a value for scalar c");
scanf("%f",&m);
char m;
switch(m)
{
   case '1':
    printf("Enter the x-,y-,and z-coordinates separated by spaces for vector . ");
    scanf("%f%f%f ",&x1,&y1,&z1);
   case '2':
    printf("Enter the x-,y-,and z-coordinates separated by spaces for vector . ");
    scanf("%f%f%f ",&x2,&y2,&z2);
   case '3':
    printf("Enter the x-,y-,and z-coordinates separated by spaces for vector . ");
    scanf("%f%f%f ",&x3,&y3,&z3);
   case 'a':
    printf(" Enter the value of scalar .");
    scanf("%f",&a);
   case 'b':
    printf(" Enter the value of scalar .");
    scanf("%f",&b);
   case 'c':
    printf(" Enter the value of scalar .");
    scanf("%f",&c1);
   default:
    printf("Invalid value.");
}
   printf("Enter first argument, second argument, and where the resultant will be stored separated by spaces:");
    scanf("%d%d%c",&arg1,arg2,res);
   if((arg1==1 && arg2==2))
    {
     if(res=='3')
      {
       x3=y1*z2-z1*x2;
       y3=z3*y1-x1*z2;
       z3=x1*y2-y1*x2;
      }
    }
   else if((arg1==3 && arg2==2))
    {
     if(res=='1')
      {
       x1=y3*z2-z3*x2;
       y1=z1*y3-x3*z2;
       z1=x3*y2-y3*x2;
      }
    }
    else if((arg1==1 && arg2==3))
    {
     if(res=='2')
       x2=y1*z3-z1*x3;
       y2=z2*y1-x1*z3;
       z2=x1*y3-y1*x3;
     }
    }
}

void norm()
{
clrscr();
int arg1;
char res;
printf("1 – Enter a value for vector 1 2 – Enter a value for vector 2 3 – Enter a value for vector 3 a – Enter a value for scalar a b – Enter a value for scalar b c – Enter a value for scalar c");
scanf("%f",&m);
char m;
switch(m)
{
   case '1':
    printf("Enter the x-,y-,and z-coordinates separated by spaces for vector . ");
    scanf("%f%f%f ",&x1,&y1,&z1);
   case '2':
    printf("Enter the x-,y-,and z-coordinates separated by spaces for vector . ");
    scanf("%f%f%f ",&x2,&y2,&z2);
   case '3':
    printf("Enter the x-,y-,and z-coordinates separated by spaces for vector . ");
    scanf("%f%f%f ",&x3,&y3,&z3);
   case 'a':
    printf(" Enter the value of scalar .");
    scanf("%f",&a);
   case 'b':
    printf(" Enter the value of scalar .");
    scanf("%f",&b);
   case 'c':
    printf(" Enter the value of scalar .");
    scanf("%f",&c1);
   default:
    printf("Invalid value.");
}
   printf("Enter first argument and where the resultant will be stored separated by spaces:");
    scanf("%d%c",&arg1,res);
   if(arg1==1)
    {
     if(res=='a')
      {
      a=sqrt(x1*x1+y1*y1+z1*z1);
      printf("the result is: %f",a);
      }
     else if(res=='b')
      {
      b=sqrt(x1*x1+y1*y1+z1*z1);
      printf("the result is: %f",b);
      }
     else if(res=='c')
      {
      b=sqrt(x1*x1+y1*y1+z1*z1);
      printf("the result is: %f",c);
      }
    }
   else if(arg1==2)
    {
     if(res=='a')
      {
      a=sqrt(x2*x2+y2*y2+z2*z2);
      printf("the result is: %f",a);
      }
     else if(res=='b')
      {
      b=sqrt(x2*x2+y2*y2+z2*z2);
      printf("the result is: %f",b);
      }
     else if(res=='c')
      {
      c=sqrt(x2*x2+y2*y2+z2*z2);
      printf("the result is: %f",c);
      }
    }
    else if(arg1==3)
   {
     if(res=='a')
      {
      a=sqrt(x3*x3+y3*y3+z3*z3);
      printf("the result is: %f",a);
      }
     else if(res=='b')
      {
      b=sqrt(x3*x3+y3*y3+z3*z3);
      printf("the result is: %f",b);
      }
     else if(res=='c')
      {
      c=sqrt(x3*x3+y3*y3+z3*z3);
      printf("the result is: %f",c);
      }
    }
  
}

so similarly, we will do for the rest of the function...