Question

In: Computer Science

Q1) Create a function called max that receives two integer values and returns the value of...

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; }

Solutions

Expert Solution

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,


Related Solutions

Write a function called draw_card. It takes no arguments and returns an integer representing the value...
Write a function called draw_card. It takes no arguments and returns an integer representing the value of a blackjack card drawn from a deck. Get a random integer in the range 1 to 13, inclusive. If the integer is a 1, print "Ace is drawn" and return 1. If the integer is between 2 and 10, call it x, print "<x> is drawn" and return x (print the number, not the string literal "<x>"). If the number is 11, 12,...
Make a python code. Write a function named max that accepts two integer values as arguments...
Make a python code. Write a function named max that accepts two integer values as arguments and returns the value that is the greater of the two. For example, if 7 and 12 are passed as arguments to the function, the function should return 12. Use the function in a program that prompts the user to enter two integer values. The program should display the value that is the greater of the two. Write the program as a loop that...
Write a function convert_date that takes an integer as a parameter and returns three integer values...
Write a function convert_date that takes an integer as a parameter and returns three integer values representing the input converted into days, month and year (see the function docstring). Write a program named t03.py that tests the function by asking the user to enter a number and displaying the output day, month and year. Save the function in a PyDev library module named functions.py A sample run for t03.py: Enter a date in the format MMDDYYYY: 05272017 The output will...
In Python Create a function called ????. The function receives a "string" that represents a year...
In Python Create a function called ????. The function receives a "string" that represents a year (the variable with this "String" will be called uve) and a list containing "strings" representing bank accounts (call this list ????). • Each account is represented by 8 characters. The format of each account number is "** - ** - **", where the asterisks are replaced by numeric characters. o For example, “59-04-23”. • The two central characters of the "string" of each account...
Python. Create a function that receives the name of an auto maker and returns a slice...
Python. Create a function that receives the name of an auto maker and returns a slice of the dataframe with the cars from that auto maker. For instance, it may receive 'ford' and return a slice with all the cars produced by 'ford' meaning they have 'ford' in their name. Call the function for 'ford' to see if it works properly. Hint: You may create a list comprehension producing a list of all the index labels that include the auto-maker's...
Python program. Write a function called cleanLowerWord that receives a string as a parameter and returns...
Python program. Write a function called cleanLowerWord that receives a string as a parameter and returns a new string that is a copy of the parameter where all the lowercase letters are kept as such, uppercase letters are converted to lowercase, and everything else is deleted. For example, the function call cleanLowerWord("Hello, User 15!") should return the string "hellouser". For this, you can start by copying the following functions discussed in class into your file: # Checks if ch is...
Write a C function called weighted_digit_sum that takes a single integer as input, and returns a...
Write a C function called weighted_digit_sum that takes a single integer as input, and returns a weighted sum of that numbers digits. The last digit of the number (the ones digit) has a weight of 1, so should be added to the sum "as is". The second from last digit (the tens digit) has a weight of 2, and so should be multiplied by 2 then added to the sum. The third from last digit should be multiplied by 1...
Design a function called middle_value, that takes 3 integers, and returns the integer with the middle...
Design a function called middle_value, that takes 3 integers, and returns the integer with the middle value. If there is a tie, any of the possible middle values can be returned. Example: middle_value(1, 2, 8) -> 2 middle_value(9, 7, 7) -> 7 middle_value(3, 3, 3) -> 3 Design a function called combine_strings that takes two phrases and appends the longer string onto the back of the shorter one with no space between the two phrases joined. Example: If the phrases...
a. Write a c++ function called IsPalindrome that receives a 3-digit number and returns whether it...
a. Write a c++ function called IsPalindrome that receives a 3-digit number and returns whether it is palindrome or not. [2.5 marks] b. Write a c++ function, called GCD that receives two parameters n, d, and prints their greatest common divisor [2.5 marks] Now after you created the two functions, you have to write a main function that can call the above functions according to user choice. Write a menu that allows the user to select from the following options...
Create the function fact that had a positive integer argument and returns its factorial . Recall...
Create the function fact that had a positive integer argument and returns its factorial . Recall that factorial (n) = 1*2*3***n. For example factorial (4)=1*2*3*4=24, (python)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT