Question

I need the real code for this program: (convert pseudocode to C++) ——————————————————— Start Program Type...

I need the real code for this program: (convert pseudocode to C++)
———————————————————
Start Program
Type Vector is Structure Defined
x is double variable
y is double variable
End Vector Type
Function Prototype Get Choice(parameters: int &)
Function Prototype vAddition (parameters: vector v1, vector v2, vector &v3)
Function Prototype vSubstract(parameters: vector v1, vector v2, vector &v3)
Function Prototype sMult(parameters: int k, vector v, vector &v3)
Function Prototype sProduct (parameters: vector v1, vector v2)
Function Prototype getMag (parameter: vector v)
Function Prototype vPrint (parameter: vector v)
Start Main
Initialize K to 10
Initialize Vector 1 to (4,9)
Initialize Vector 2 to (3,-1)
Call function getchoice(argument: choice)
Start do while loop
while choice is not equal to 0
start switch cases
start case 1
call vaddition(arguments: v1, v2, v3)
call vprint(argument: v3)
end case 1
start case 2
call vsubtract(arguments: v1, v2, v3)
call vprint(argument: v3)
end case 2
start case 3
call getvchoice(argument: vchoice)
if choice = 1
call sMult(arguments: k, v1, v3 )

call sPrint(argument: v3)
end if
if choice = 2
call sMult(arguments: k, v2, v3)
call sPrint(argument: v3)
end if
end Case 3
start case 4
call sProduct (arguments: v1,v2)
end case 4
start case 5
getvchoice(argument: vchoice)
if vchoice = 1
call vMag(argument: v1)
if vchoice = 2
call vMag(argument: v2)
end case 5
Call getchoice(argument: choice)
End do while loop
end main
void getchoice(parameters: int &choice)
choose an option
1. Add Two Vectors
2. Subtract Two Vectors
3. Scalar Multiplication
4. Scalar Product
5. Calculate Vector Magnitude
0. Exit Program
Obtain the user input
while choice < 0 or choice > 5
1. Add Two Vectors
2. Subtract Two Vectors
3. Scalar Multiplication
4. Scalar Product
5. Calculate Vector Magnitude
0. Exit Program
Obtain the User Input
void getvchoice(parameters: int &vchoice)
start do
choose the vector you would like to multiply
1. vector v1
2. vector v2

obtain user input
while vchoice is not equal to 1 and vchoice is not equal to 2
end do/while
void vprint(parameter: vector v)
The result is (v.x, v.y)
void vAddition(parameters: vector v1, vector v2, vector &v3)
v3.x = v1.x + v2.x
v3.x = v1.x + v2.x
void vSubtract(parameters: vector v1, vector v2, vector &v3)
v3.x = v1.x - v2.x
v3.y = v1.y - v2.y
void sMult(parameters: int k, vector v, vector &v3)
v3.x = k*v.x
v3.y = k*v.y
void sProduct(parameters: vector v1, vector v2)
The Scalar Product is: v1.x*v2.x + v1.y*v2.y
void getMag(parameters: vector v)
The magnitude of the vector is the square root of: (v.x * v.x + v.y * v.y)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi there,

Following is the code in C++,If you still have any queries feel free to ask in the comments box.

Code:

/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;
struct vector
{
    double x;
    double y;
};
void getchoice(int &amp);
void vAddition (vector v1, vector v2,vector &v3);
void getvchoice(int &amp);
void vSubstract(vector v1, vector v2, vector &v3);
void sMult(int k, vector v, vector &v3);
void sProduct (vector v1, vector v2);
void getMag (vector v);
void vPrint(vector v);

void getchoice(int &amp)
{
cout<<"Choose an option"<<endl;
cout<<"1. Add Two Vectors"<<endl;
cout<<"2. Subtract Two Vectors"<<endl;
cout<<"3. Scalar Multiplication"<<endl;
cout<<"4. Scalar Product"<<endl;
cout<<"5. Calculate Vector Magnitude"<<endl;
cout<<"0. Exit Program"<<endl;
cin>>amp;
}

void getvchoice(int &amp)
{
    do{
        cout<<"Choose the vector you would like to multiply ";
        cout<<"1. vector v1"<<endl;
        cout<<"2. vector v2"<<endl;
        cin>>amp;
    }while(amp!=1 && amp!=2);
}

void vAddition (vector v1, vector v2,vector &v3)
{
v3.x = v1.x + v2.x;
v3.y = v1.y + v2.y;
}

void vSubstract(vector v1, vector v2, vector &v3)
{
v3.x = v1.x - v2.x;
v3.y = v1.y - v2.y;
}

void sMult(int k, vector v, vector &v3)
{
v3.x = k*v.x;
v3.y = k*v.y;
}

void sProduct (vector v1, vector v2)
{
     cout<<"The Scalar Product is: "<<v1.x*v2.x<<"+"<< v1.y*v2.y<<endl;
}

void getMag (vector v)
{
     cout<<"The magnitude of the vector is the square root of: ("<<v.x * v.x + v.y * v.y<<")"<<endl;
}

void vPrint(vector v)
{
     cout<<"The result is ("<<v.x<<","<<v.y<<")"<<endl;
}


int main()
{
    int k=10;
    vector v1;
    v1.x=4;
    v1.y=9;
    vector v2;
    v2.x=3;
    v2.y=-1;
    vector v3;
    int choice;
    int vchoice;
    getchoice(choice);
    do{
        switch(choice)
        {
            case 1:
            vAddition(v1, v2, v3);
            vPrint(v3);
            break;
          
            case 2:
            vSubstract(v1, v2, v3);
            vPrint(v3);
            break;
          
            case 3:
         
            getvchoice(vchoice);
            if(vchoice==1)
            {
                sMult(k, v1, v3);
                vPrint(v3);
            }
            if(vchoice==2)
            {
                sMult(k, v2, v3);
                vPrint(v3);
            }
            break;
          
            case 4:
            sProduct(v1,v2);
            break;
          
            case 5:
            getvchoice(vchoice);
            if(vchoice == 1)
             getMag(v1);
            if(vchoice == 2)
             getMag(v2);
            break;
          
          
          
        }
      
        getchoice(choice);
      
    }while(choice!=0);
  
  

    return 0;
}


Output :

Choose an option                                                                                                                                              

1. Add Two Vectors                                                                                                                                            

2. Subtract Two Vectors                                                                                                                                       

3. Scalar Multiplication                                                                                                                                      

4. Scalar Product                                                                                                                                             

5. Calculate Vector Magnitude                                                                                                                                 

0. Exit Program                                                                                                                                               

1                                                                                                                                                             

The result is (7,8)                                                                                                                                           

Choose an option                                                                                                                                              

1. Add Two Vectors                                                                                                                                            

2. Subtract Two Vectors                                                                                                                                       

3. Scalar Multiplication                                                                                                                                      

4. Scalar Product                                                                                                                                             

5. Calculate Vector Magnitude                                                                                                                                 

0. Exit Program                                                                                                                                               

2                                                                                                                                                             

The result is (1,10)                                                                                                                                          

Choose an option                                                                                                                                              

1. Add Two Vectors                                                                                                                                            

2. Subtract Two Vectors                                                                                                                                       

3. Scalar Multiplication                                                                                                                                      

4. Scalar Product                                                                                                                                             

5. Calculate Vector Magnitude                                                                                                                                 

0. Exit Program                                                                                                                                               

3                                                                                                                                                             

Choose the vector you would like to multiply 1. vector v1                                                                                                     

2. vector v2                                                                                                                                                  

1                                                                                                                                                             

The result is (40,90)                                                                                                                                         

Choose an option                                                                                                                                              

1. Add Two Vectors                                                                                                                                            

2. Subtract Two Vectors                                                                                                                                       

3. Scalar Multiplication                                                                                                                                      

4. Scalar Product                                                                                                                                             

5. Calculate Vector Magnitude

0. Exit Program                                                                                                                                               

4                                                                                                                                                             

The Scalar Product is: 12+-9                                                                                                                                  

Choose an option                                                                                                                                              

1. Add Two Vectors                                                                                                                                            

2. Subtract Two Vectors                                                                                                                                       

3. Scalar Multiplication                                                                                                                                      

4. Scalar Product                                                                                                                                             

5. Calculate Vector Magnitude                                                                                                                                 

0. Exit Program                                                                                                                                               

5                                                                                                                                                             

Choose the vector you would like to multiply 1. vector v1                                                                                                     

2. vector v2                                                                                                                                                  

2                                                                                                                                                             

The magnitude of the vector is the square root of: (10)                                                                                                       

Choose an option                                                                                                                                              

1. Add Two Vectors                                                                                                                                            

2. Subtract Two Vectors                                                                                                                                       

3. Scalar Multiplication                                                                                                                                      

4. Scalar Product                                                                                                                                             

5. Calculate Vector Magnitude                                                                                                                                 

0. Exit Program                                                                                                                                               

0                                                                                                                                                             

                                                                                                                                                              

                                                                                                                                                              

...Program finished with exit code 0                                                                                                                          

Press ENTER to exit console

Add a comment
Know the answer?
Add Answer to:
I need the real code for this program: (convert pseudocode to C++) ——————————————————— Start Program Type...
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
  • How can I convert the following C code to MIPS Assembly? +++++++++++++++++++++++++++++++++ MIPS main program ++++++++++++++++++++++++++++++++...

    How can I convert the following C code to MIPS Assembly? +++++++++++++++++++++++++++++++++ MIPS main program ++++++++++++++++++++++++++++++++ .data # Defines variable section of an assembly routine. array: .word x, x, x, x, x, x, x, x, x, x # Define a variable named array as a word (integer) array # with 10 unsorted integer numbers of your own. # After your program has run, the integers in this array # should be sorted. .text # Defines the start of the code...

  • Using java fix the code I implemented so that it passes the JUnit Tests. MATRIX3 public...

    Using java fix the code I implemented so that it passes the JUnit Tests. MATRIX3 public class Matrix3 { private double[][] matrix; /** * Creates a 3x3 matrix from an 2D array * @param v array containing 3 components of the desired vector */ public Matrix3(double[][] array) { this.matrix = array; } /** * Clones an existing matrix * @param old an existing Matrix3 object */ public Matrix3(Matrix3 old) { matrix = new double[old.matrix.length][]; for(int i = 0; i <...

  • I need assistance with the C++ code below to remove the "this" pointers while maintaining the...

    I need assistance with the C++ code below to remove the "this" pointers while maintaining the code's current output and functionality. Also, there should be a private class in the header file, but I'm not sure what I should include there. Any help would be greatly appreciated! ***main.cpp driver file*** #include <iostream> #include "vector.h" using namespace std; int main() {   vectorInfo v1(7, 6);   vectorInfo v2(5, 4);       v1.set(3, 2);   cout << "v1 : ";   v1.print();       cout << "v2 :...

  • Any help in the compiler error //Driver Program //***************** /** * * CSCI 241 Assignment 8...

    Any help in the compiler error //Driver Program //***************** /** * * CSCI 241 Assignment 8, Part 3 * * Author: your name * z-ID: your z-ID * Date: due date of assignment * * This program builds, sorts and prints lists using the quicksort and * merge sort algorithms. */ #include <iostream> #include <iomanip> #include <vector> #include <string> #include "sorts.h" #include "quicksort.h" #include "mergesort.h" using std::cout; using std::fixed; using std::left; using std::setprecision; using std::string; using std::vector; // Data files...

  • I need a c++ code please. 32. Program. Write a program that creates an integer constant...

    I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...

  • Need help problem 9-13 C++ Homework please help WRITE FUNCTION PROTOTYPES for the following functions. The...

    Need help problem 9-13 C++ Homework please help WRITE FUNCTION PROTOTYPES for the following functions. The functions are described below on page 2. (Just write the prototypes) When necessary, use the variables declared below in maino. mm 1.) showMenu m2.) getChoice 3.) calcResult m.) showResult 5.) getInfo mm.) showName 7.) calcSquare 8.) ispositive int main { USE THESE VARIABLES, when needed, to write function prototypes (#1 - #8) double num1 = 1.5; double num2 = 2.5; char choice; double result;...

  • Please in C Language Thank you! The following program source code is incomplete 1 #include <stdio.h> 2 3 // TODO:...

    Please in C Language Thank you! The following program source code is incomplete 1 #include <stdio.h> 2 3 // TODO: 1) Add the typedef here: 5// TODO: 2) Modify the parameter of repeat to add irn the function pointer for the function to be called repeatedly: 8 void repeat (int times) for (int k 0; k < times; ++k) 12 // TODO: 3) Add the call to the function pointer here: 14 15 17 void test (void) 18 printf("Test!\n"); 19...

  • Example program #include <string> #include <iostream> #include <cmath> #include <vector> using namespace std; vector<int> factor(int n)...

    Example program #include <string> #include <iostream> #include <cmath> #include <vector> using namespace std; vector<int> factor(int n) {     vector <int> v1;     // Print the number of 2s that divide n     while (n%2 == 0)     {         printf("%d ", 2);         n = n/2;         v1.push_back(2);     }     // n must be odd at this point. So we can skip     // one element (Note i = i +2)     for (int i = 3; i <=...

  • C++ EXERCISE (DATA STRUCTURES). I just need a code for some functions that are missing. Please...

    C++ EXERCISE (DATA STRUCTURES). I just need a code for some functions that are missing. Please help me figure out. Thanks. C++ BST implementation (using a struct) Enter the code below, and then compile and run the program. After the program runs successfully, add the following functions: postorder() This function is similar to the inorder() and preorder() functions, but demonstrates postorder tree traversal. displayParentsWithTwo() This function is similar to the displayParents WithOne() function, but displays nodes having only two children....

  • ​​​​​​ 11.   A _____________ error does not cause the compiler to generate an error, but does...

    ​​​​​​ 11.   A _____________ error does not cause the compiler to generate an error, but does cause the program to produce incorrect results. Syntax, logic, variable name, function name 12.   A syntax error occurs when the programmer violates one or more grammar rules of the C language. True or False 13.   Given this line of code: y = sqrt(x); x would be known as the argument. True or False 14.   A void function does not return a value to the...

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