In: Computer Science
Q1) Create a function called max that receives two integer values and returns the value of the bigger integer.
Q2) Complete the missing code in the following program. Assume that a cosine function has already been created for you. Consider the following function header for the cos function. double cos (double x) #include void output_separator() { std::cout << "================"; } void greet_name(string name) { std::cout << "Hey " << name << "! How are you?"; } int sum(int x, int y){ return x + y; } int main() { std::string name; int num1, num2, result; double num_dec, result_dec; std::cout << "Please enter your name: "; std::cin >> name; Answer ; // call the greet_name function and pass the user's name Answer ; // call the output_separator function std::cout << "Please input 2 integer values: "; std::cin >> num1 >> num2; std::cout << "Please input a double value: "; std::cin >> num_dec; std::cout << "Here are the results of my function test"; Answer ; // store the result of the sum function into // result and pass num1 and num2 as parameters std::cout << "Sum result: " << result; Answer ; // store the result of the cos function into // result_dec and pass num_dec as the parameter std::cout << "Cosine result: " << result_dec; return 0; }
Answer 1:
#include<iostream>
using namespace std;
int max(int n1,int n2){
if(n1<n2)
return n2;
return n1;
}
int main(){
cout<<"Max : "<<max(10,20)<<endl;
cout<<"Max : "<<max(24,15)<<endl;
}
Answer 2:
#include<iostream>
#include <cmath>
double cos (double x);
void output_separator() {
std::cout << "================";
}
void greet_name(std::string name) {
std::cout << "Hey " << name << "! How are you?";
}
int sum(int x, int y){
return x + y;
}
int main() {
std::string name;
int num1, num2, result;
double num_dec, result_dec;
std::cout << "Please enter your name: ";
std::cin >> name;
// call the greet_name function and pass the user's name Answer ;
// call the output_separator function
std::cout << "Please input 2 integer values: ";
std::cin >> num1 >> num2;
std::cout << "Please input a double value: ";
std::cin >> num_dec;
std::cout << "Here are the results of my function test";
// store the result of the sum function into // result and pass num1 and num2 as parameters
std::cout << "Sum result: " << result;
// store the result of the cos function into
// result_dec and pass num_dec as the parameter
result_dec = cos(num_dec);
std::cout << "Cosine result: " << result_dec; return 0;
}
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me
clang version 7.0.0-3.ubuntu0.18.04.1 (tags/RELEASE_700/final), : clang++-7 -pthread -o main main.cpp ../main Max : 20 Max : 24
clang version 7.0.0-3.ubuntu0.18.04.1 (tags/RELEASE_700/final), > clang++-7 -pthread -o main main.cpp 3./main Please enter your name: Uday Please input 2 integer values: 10 20 Please input a double value: 10 Here are the results of my function testSum result: 0Cosine result: 2.07364e-3170,