Ans
code:-
#include <iostream>
#include<string>
using namespace std;
int solution(string s,int num1,int num2){
//if operation is addition
if(s=="+")
return num1+num2;
//if operation is subtraction
else if(s=="-")
return num1-num2;
//if operation is multiplication
else if(s=="*")
return num1*num2;
//if operation is division
else if(s=="/"){ //divide by zero
if(num2==0) return -2;
return num1/num2;}
//if operation is max
else if(s=="max")
{//if num1 is max
if(num1>num2) return num1;
else return num2;}
//if operation is to find the min
else if(s=="min") {
//if num1 is min
if(num1<num2) return num1;
else return num2;
}
//if no match return -1
return -1;
}
int main()
{
string s;
int num1,num2;
cin>>s;
cin>>num1;
cin>>num2;
cout<<solution(s,num1,num2);
return 0;
}
If any doubt ask in the comments.
CC++ Compiler: CPP (gcc-5.x) 0 Simple Calculator Given two integers and a string, create a simple...
IN C++ Given ProblemSolution class. Use a pointer to object of “ProblemSolution” class to invoke the “CalculateSum” and “Print” methods of “ProblemSolution”. Write a function: void Solution(int N1, int N2) that accepts two integers N1 and N2. The function should instantiate “ProblemSolution” object with N1 and N2 values and call “CalculateSum” and “Print” method by creating a pointer to the object of “ProblemSolution”. Input 12 5 Output 17 Assume that, N1, N2 and sum are integers within...
61. The following program is accepted by the compiler: int sum( int x, int y ) { int result; result = x + y; } T__ F__ 62. The following implementation is accepted by the compiler: void product() { int a; int b; int c; int result; cout << "Enter three integers: "; cin >> a >> b >> c; result = a * b * c; ...
Complete a partially written C++ program that includes a function that return a value. The program is a simple calculator that prompts the user of 2 number and an operation (+, -, * or, /). The two number and the operator are passed to the function where the appropriate arithmetic operation is performed. The result is return to the main function () where the arithmetic operation and result are displayed. For example 3 * 4 = 12 The source code...
Do not change anything in the supplied code below that will be the Ch12_Ex9.cpp except to add documentation and your name. Please use the file names listed below since your file will have the following components: Ch12_Ex9.cpp given file //Data: 18 42 78 22 42 5 42 57 #include <iostream> #include "unorderedArrayListType.h" using namespace std; int main() { unorderedArrayListType intList(25); int number; cout << "Enter 8 integers: "; for (int count = 0; count < 8; count++)...
What am I doing wrong here...…. Question is this : In this exercise, you will create a program that displays a table consisting of four rows and three columns. The first column should contain the numbers 10 through 13. The second and third columns should contain the results of squaring and cubing, respec- tively, the numbers 10 through 13. The table will look similar to the one shown in Figure 9-38. If necessary, create a new project named Introductoryl6 Project,...
#include <iostream> #include <cstdlib> #include <time.h> #include <string> using namespace std; int main() { srand(time (0)); int number, guess, response, reply; int score = 0 number = rand() % 100 + 1; do { do { cout << "Enter your guess "; cin >> guess; score++; if (guess < number) cout << guess << " is too low! Enter a higher number. "; else if (guess > number) cout << guess << " is too high! Enter a lower number....
The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried to divide the code in 3 parts (Patient.h, Patient.cpp and Main.cpp), but it is giving me errors. Patient.h #ifndef PATIENT_H #define PATIENT_H #include <string> #include "Patient.cpp" using namespace std; class Patient{ private : string firstname; string lastname; string location; static int cnt; int id; public : Patient(string, string, string);...
I'm just a beginner in programming,how to make this program more simple without using #include<iostream> and #include<redex> here is the question Terms to know: If-else statement,for..while..do while,loops,pointer,address,continue,return,break. Create a C++ program which contain a function to ask user to enter user ID and password. The passwordmust contain at least 6 alphanumeric characters, 1 of the symbols !.@,#,$,%,^,&,* and 1 capital letter.The maximum allowable password is 20. Save the information. Test the program by entering the User ID and password. The...
Using Python. 3) Create a single-linked list (StudentList) where the data in the link is an object of type pointer to Student as defined below. Note that you need to store and pass a pointer of type Student so that you do not create duplicate objects. Test your list with the provided program. You will find example code for a single-linked list of integers in Moodle that you can base your solution on. For your find methods, you can either...
Need C++ coding for this lab exercise given below :) 4. Lab Exercise — Templates Exercise 1 - Function Templating For this part of the lab make a template out of the myMax function and test it on different data types. Copy maxTemplate.cpp to your Hercules account space. Do that by: Entering the command:cp /net/data/ftp/pub/class/115/ftp/cpp/Templates/maxTemplate.cpp maxTemplate.cpp Compile and run the program to see how it works. Make a template out of myMax. Don't forget the return type. Modify the prototype appropriately. Test your myMax template on int, double,...