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 &);
void vAddition (vector v1, vector v2,vector &v3);
void getvchoice(int &);
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 &)
{
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 &)
{
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
I need the real code for this program: (convert pseudocode to C++) ——————————————————— Start Program Type...
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 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 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, 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 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 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: 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)
{
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 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 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...