Using c++.. 1. Write a program to find the sum(), Subtraction(), Multiplication(), Division() operations using Switch statement and functions. 2. Write a program to find the summation of N numbers. Use two functions. One function will take the input from user and the other will perform the summation from 1 to N. 3. Write a program to find the factorial of a number. Use two functions. One function will take the input from user and the other will perform the factorial. 4. Write a program using functions to find the ‘Even’ or ‘Odd’ number Submit your source code and output screen capture.
QUESTION 1 C++ CODE:
#include<iostream>
#include<iomanip>
using namespace std;
//function to add two numbers
int addition(int x,int y)
{
return x+y;
}
//function to subtract two numbers
int subtraction(int x,int y)
{
return x-y;
}
//function to multiply two numbers
int multiplication(int x,int y)
{
return x*y;
}
//function to divide two numbers
double division(int x,int y)
{
return (double)x/y;
}
//main function
int main()
{
//variable for storing the choice
int choice;
//variable to store the results of operations and
input
int x,y,r,r2,r3;
double r4;
//infinite looping
while(1)
{
//displaying the menu
cout<<"\n1.
Addition" ;
cout<<"\n2.
Subtraction";
cout<<"\n3.
Multiplication";
cout<<"\n4. Divison";
cout<<"\n5. Exit";
//getting the choice from the
user
cout<<"\nEnter your choice:
";
cin>>choice;
//choosing the action based on the
input
switch(choice)
{
// for
addition
case 1:
cout<<"Enter the first number: ";
cin>>x;
cout<<"Enter the second
number: ";
cin>>y;
r=addition(x,y);
cout<<"\nThe sum of
"<<x<<" and "<<y<<" is
"<<r<<endl;
break;
//subtraction
case 2:
cout<<"Enter the first number: ";
cin>>x;
cout<<"Enter the second
number: ";
cin>>y;
r2=subtraction(x,y);
cout<<"\nThe
subtraction of "<<y<<" from "<<x<<" is
"<<r2<<endl;
break;
//
multiplication
case 3:
cout<<"Enter the first number: ";
cin>>x;
cout<<"Enter the second
number: ";
cin>>y;
r3=multiplication(x,y);
cout<<"\nThe multiply
of "<<x<<" and "<<y<<" is
"<<r3<<endl;
break;
//division
case 4:
cout<<"Enter the first number: ";
cin>>x;
cout<<"Enter the second
number: ";
cin>>y;
r4=division(x,y);
cout<<"\nThe division
of "<<x<<" by "<<y<<" is ";
cout<<fixed <<
setprecision(2)<<r4<<endl;
break;
//for closing
the application
case 5:
cout<<"\nClosing the application...";
exit(0);
break;
default:cout<<"\nEnter 1,2,3,4, or 5";
}
}
}
SCREENSHOT FOR OUTPUT:
QUESTION 2 C++ CODE:
#include<iostream>
using namespace std;
//function to find the sum of n numbers
int summation(int n)
{
int sum=0,i=0;
//loop to find the sum of n numbers
for(i=1;i<=n;i++)
{
sum=sum+i;
}
return sum;
}
//function to get the input from the user
int get_input()
{
int n;
//getting input from the user
cout<<"Enter a number: ";
cin>>n;
//return the value
return n;
}
int main()
{
//calling the functions
int n=get_input();
int r=summation(n);
//printing the sum of n numbers
cout<<"The sum of "<<n<<" numbers is
"<<r;
return 0;
}
SCREENSHOT FOR OUTPUT:
QUESTION 3 C++ CODE:
#include<iostream>
using namespace std;
//function to find the factorial of n numbers
int factorial(int n)
{
int product=1,i=0;
if (n==0)
return 1;
//loop to find the factorial of n numbers
for(i=1;i<=n;i++)
{
product=product*i;
}
return product;
}
//function to get the input from the user
int get_input()
{
int n;
//getting input from the user
cout<<"Enter a number: ";
cin>>n;
//return the value
return n;
}
int main()
{
//calling the functions
int n=get_input();
int r=factorial(n);
//printing the sum of n numbers
cout<<"The factorial of "<<n<<" is
"<<r;
return 0;
}
SCREENSHOT FOR OUTPUT:
QUESTION 4 C++ CODE:
#include<iostream>
using namespace std;
//function to a number odd or even
void odd_even(int n)
{
if (n % 2 ==0)
{
cout<<"The given number
"<<n<<" is even"<<endl;
}
else
{
cout<<"The
given number "<<n<<" is odd"<<endl;
}
}
//function to get the input from the user
int get_input()
{
int n;
//getting input from the user
cout<<"Enter a number: ";
cin>>n;
//return the value
return n;
}
int main()
{
//calling the functions
int n=get_input();
odd_even(n);
}
SCREENSHOT FOR OUTPUT:
Using c++.. 1. Write a program to find the sum(), Subtraction(), Multiplication(), Division() operations using Switch...
usingc++ 1. Write a program to find the Sum(), Subtraction(), Multiplication(), Division() operations using Switch statement. For Division operation, please include denominator equals to zero check.
Problem 9: (20 Points) Write a CH program to implement sum, subtraction, multiplication and division operations of two numbers. Please use functions and switch statements. Please provide option to the user to continue the program after each operation. Please provide option to 'Exit' the program also
Write a C++ Program that simulates a basic calculator using functions which performs the operations of Addition, Subtraction, multiplication, and Division. ( make sure you cover the case to avoid division by a zero) Display a menu for the list of operations that can be calculated and get the input from the user about his choice of calculation. Based on user choice of operation, take the input of number/numbers from user. Assume all input values are of type double. Calculations...
Write a C++ Program that simulates a basic calculator using functions which performs the operations of Addition, Subtraction, multiplication, and Division. ( make sure you cover the case to avoid division by a zero) Display a menu for list of operations that can be calculated and get the input from user about his choice of calculation. Based on user choice of operation, take the input of number/numbers from user. Assume all input values are of type double. Calculations must be...
1. Write a program that takes a number as input and check whether the number is positive, negative or zero. 2. Write a C++ program that prompts the user to enter a number and checks whether the entered number is even or odd. 3. Using switch-case statement write a C++ program that prompts the user to enter 1, 2 or 3 and display "Red" if selection is 1, "Yellow" if selection is 2, or "Green" if selection is 3. 4. Write...
Write a java calculator program that perform the following operations: 1. function to Addition of two numbers 2. function to Subtraction of two numbers 3. function to Multiplication of two numbers 4. function to Division of two numbers 5. function to Modulus (a % b) 6. function to Power (a b ) 7. function to Square root of () 8. function to Factorial of a number (n!) 9. function to Log(n) 10. function to Sin(x) 11. function to Absolute value...
Problem 3 (35) Design a calculator that performs four operations: addition, multiplication, division and subtraction with 2 integer type numbers a) Ask user what type of operation to perform (+, , * or/) a. If the user inputs 'none' then the program terminates. Otherwise it will keep continuing the calculation. (hint: use while) b) Ask user to provide 2 integer number inputs c) Perform operation (whatever operation they mentioned in a) d) Print result e) In division operation, perform a...
Using Assembly Language (MIPS), design a program calculator that can perform the following: Addition, Subtraction, Multiplication, Division, Power and Square Root Functions. Code must be able to accept floating point as well.
Write a C++ program to take two numbers as input from the user , compute the addition, subtraction, multiplication and division of these numbers and display the desired formatted results.
PLease IN C not in C++ or JAVA, Lab3. Write a computer program in C which will simulate a calculator. Your calculator needs to support the five basic operations (addition, subtraction, multiplication, division and modulus) plus primality testing (natural number is prime if it has no non-trivial divisors). : Rewrite your lab 3 calculator program using functions. Each mathematical operation in the menu should be represented by a separate function. In addition to all operations your calculator had to support...