Question

In: Computer Science

Code: please use in visual studio 2019 c++ (not java) In total you will write 6...

Code: please use in visual studio 2019 c++ (not java)

In total you will write 6 functions:

Functions :

A ) addInts, returns int; input is two ints; Add the values of the two parameters and return the sum

B) subInts , returns int; input is two ints; Subtract the values of the two parameters and return the difference

C) multInts, returns int; input is two ints; multiple the values of the two parameters and return the product

D) divInts, returns int; input is two ints; Divide the values of the two parameters and return the quotient

E) modInts, returns int; input is two ints; compute the residual of the values of the two parameters and return the residual

F) A function called computeOperation ( ) that , returns an int; input is three parameters: one 'control' int, and two ints;  

if the control int ( the first parameter) is :

Control

Control Parameter compute return value :
1 Return sum of 2nd and 3td parameters
2 Return diff of 2nd and 3td parameters
3 Return product of 2nd and 3td parameters
4 Return quotient of 2nd and 3td parameters
5 Return modulus of 2nd and 3td parameters

expect to see both Function Declarations and of course the Function Definitions for all 6 functions

expect to see some obvious test code or data sets.  

expect to see a switch statement not a series of if statements if it is appropriate.

To Be Clear:

in the main function there should be a homework header and then a bunch of 'call's to the

computeOperation ( ) function.  

And

computeOperation should then have code to invoke one of the 5 low level compute functions. The value that is returned should be returned by computeOperator.

Solutions

Expert Solution

/*
The C++ program that contains 6 functions called as addInts,subInts , multInts, modInts,computeOperation ( ).
The program test some sample values of x and y variables. Then call the function, computeOperation with operation code value in a range of 1 to 6, x and y values as 3 arguments to the function. Then, print the results of return values of the function on the console output.
*/

//arithmatic.cpp
//include header files
#include<iostream>
using namespace std;
//Function prototypes
int addInts(int , int);
int subInts(int , int);
int multInts(int , int);
int divInts(int , int);
int modInts(int , int);
int computeOperation (int , int ,int);
//start of main function
int main()
{
   //Set sample values for x and y values
   int x=10;
   int y=5;
   //Set result to 0
   int result=0;
   //Set operationcode to 1 for addition
   int operationcode=1;
   result=computeOperation(operationcode,x,y);
   cout<<"computeOperation("<<operationcode<<","
       <<x<<","<<y<<") = " <<result<<endl;

   //Set operationcode to 1 for subtracation
   operationcode=2;
   result=computeOperation(operationcode,x,y);
   cout<<"computeOperation("<<operationcode<<","
       <<x<<","<<y<<") = " <<result<<endl;

   //Set operationcode to 1 for multiplication
   operationcode=3;
   result=computeOperation(operationcode,x,y);
   cout<<"computeOperation("<<operationcode<<","
       <<x<<","<<y<<") = " <<result<<endl;

   //Set operationcode to 1 for division
   operationcode=4;
   result=computeOperation(operationcode,x,y);
   cout<<"computeOperation("<<operationcode<<","
       <<x<<","<<y<<") = " <<result<<endl;

   //Set operationcode to 1 for modulus
   operationcode=5;
   result=computeOperation(operationcode,x,y);
   cout<<"computeOperation("<<operationcode<<","
       <<x<<","<<y<<") = " <<result<<endl;

   system("pause");
   return 0;
}
/*Function, addInts takes two arguments of integer
type and returns the sum of the values as return value*/
int addInts(int x , int y)
{
   return x+y;
}
/*Function, subInts takes two arguments of integer
type and returns the difference of the values as return value*/
int subInts(int x , int y)
{
   return x-y;
}
/*Function, multInts takes two arguments of integer
type and returns the product of the values as return value*/
int multInts(int x , int y)
{
   return x*y;
}
/*Function, divInts takes two arguments of integer
type and returns the quotient of the values as return value*/
int divInts(int x , int y)
{
   return x/y;
}
/*Function, modInts takes two arguments of integer
type and returns the remainder of the values as return value*/
int modInts(int x , int y)
{
   return x%y;
}
/*
The function , computeOperation takes three
input arguments of integer type opcode, x and y variables.
Then using switch case, select the appropriate
function call . Then store the return value in result.
Returns the result value.
*/
int computeOperation (int opcode,int x , int y)
{
   int result=0;
   switch(opcode)
   {
   case 1:
       result= addInts(x,y);
       break;
   case 2:
       result= subInts(x,y);
       break;
   case 3:
       result= multInts(x,y);
       break;
   case 4:
       result= divInts(x,y);
       break;
   case 5:
       result= modInts(x,y);
       break;
   }
   return result;
}

Sample Output:


Related Solutions

ONLY USE VISUAL STUDIO (NO JAVA CODING) VISUAL STUDIO -> C# -> CONSOLE APPLICATION In this...
ONLY USE VISUAL STUDIO (NO JAVA CODING) VISUAL STUDIO -> C# -> CONSOLE APPLICATION In this part of the assignment, you are required to create a C# Console Application project. The project name should be A3<FirstName><LastName>P2. For example, a student with first name John and Last name Smith would name the project A1JohnSmithP2. Write a C# (console) program to calculate the number of shipping labels that can be printed on a sheet of paper. This program will use a menu...
I need the code for following in C++ working for Visual studio please. Thanks Use a...
I need the code for following in C++ working for Visual studio please. Thanks Use a Struct to create a structure for a Player. The Player will have the following data that it needs maintain: Struct Player int health int level string playerName double gameComplete bool isGodMode Create the 2 functions that will do the following: 1) initialize(string aPlayerName) which takes in a playername string and creates a Player struct health= 100 level= 1 playerName = aPlayerName gameComplete = 0...
Please use original C++ code for this. This is for visual studio. Program 5: Shipping Calculator...
Please use original C++ code for this. This is for visual studio. Program 5: Shipping Calculator The Speedy Shipping Company will ship packages based on how much they weigh and how far they are being sent. They will only ship small packages up to 10 pounds. You have been tasked with writing a program that will help Speedy Shipping determine how much to charge per delivery. The charges are based on each 500 miles shipped. Shipping charges are not pro-rated;...
C++ Visual Studio 2019 Part A : Program Description: Write a program to generate a report...
C++ Visual Studio 2019 Part A : Program Description: Write a program to generate a report based on input received from a text file. Suppose the input text file student_grades.txt contains the student’s Last name , First name, SSN, Test1, Test2, Test3 and Test4. (25%) i.e. Alfalfa   Aloysius   123-45-6789 40.0    90.0   100.0    83.0 Generate the output Report File student_final.txt in the following format : LastName FirstName   SSN Test1   Test2   Test3   Test4 Average FinalGrade i.e. Alfalfa   Aloysius   123-45-6789 40.0    90.0   100.0   ...
Please code in C#-Visual Studio Tasks The program needs to contain the following A comment header...
Please code in C#-Visual Studio Tasks The program needs to contain the following A comment header containing your name and a brief description of the program Output prompting the user for the following inputs: Name as a string Length of a rectangle as a double Width of a rectangle as a double Length of a square as an int After accepting user input, the program outputs the following: User name Area of a rectangle with dimensions matching the inputs Area...
PS: Please don't use #include <bits/stdc++.h>. Visual studio compatible please. Write a C++ program to find...
PS: Please don't use #include <bits/stdc++.h>. Visual studio compatible please. Write a C++ program to find least common multiple (LCM) of two, three and four integer values. The integer values are entered from the keyboard and the outputs are printed to the console. The LCM of two, three and four integer values are computed using Prime factorization method. You have to use arrays to hold input values and use functions/methods to get data from the keyboard, display output to the...
use VISUAL STUDIO CODE to write this javascript program Exercise 1 (a) Create a HTML file...
use VISUAL STUDIO CODE to write this javascript program Exercise 1 (a) Create a HTML file that uses createElement and appendChild to dynamically insert three paragraphs when a button is clicked. (b) Create a HTML file that includes JavaScript that is similar to: let recs = [“my item …1”,”my item…2”, …] i.e. an array that contains several CSV item records. When the user clicks a button, each array element will be rendered as a list element. Use a HTML list....
You should use Visual Studio to write and test the program from this problem.   Write a...
You should use Visual Studio to write and test the program from this problem.   Write a complete program with a for loop that (5 pts) uses proper variable types. (10 pts) uses a for loop to read in a real numbers exactly 8 times (10 pts) adds the number read in the loop to a running sum. (10 pts) Computes the average of the 8 numbers as a real number. (5 pts) Prints the correct result with 2 decimal places,...
Please do this in visual studio C++. Overview In this programming challenge, you will create an...
Please do this in visual studio C++. Overview In this programming challenge, you will create an Employee Tree application. Instructions Begin this assignment by writing your own version of a class template that will create a binary tree that can hold values of any data type. Design an EmployeeInfo class that holds the following employee information: Employee ID Number (int) Employee Name (string) Next, use the template you designed to implement a binary tree whose nodes hold an instance of...
C# ( asp.net ) 2019 Visual Studio I have a dropdown where you can select (...
C# ( asp.net ) 2019 Visual Studio I have a dropdown where you can select ( integer, string, date ) After selecting the desired dropdown option, user can input a list of inputs. For example; for integer: 2,5,7,9,1,3,4 And then , I have a 'sort' button Can you please help me with the code behind for sorting them( For integer, string, and date ) Thank you.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT