Question

Help answer Questions in C++ 14. Create a function that swaps the values of the two...

Help answer Questions in C++ 14. Create a function that swaps the values of the two inputs; it should do so as a pass by reference. 15. Create a function that returns the max of two numbers. 16. Create a function that rolls a dice named ROLL. It should create a random number between 1 and 6. Create another function that rolls two dice and says SNAKE EYES if you both rolls are a 1. Call these functions until you get snake eyes. Count how many times this happens. (Suggested to use a "static" variable for counting.)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Question 14:

Here a new C++ program with name "main.cpp" is created, which contains following code.

main.cpp :

//c++ program to swap two numbers
#include <iostream> //header files
using namespace std;
void swap(int &,int &);//function prototype
int main() //main method
{
int num1, num2;//declaring variables
cout<<"Enter number 1 :";//asking num1
cin>>num1;//reading num1
cout<<"Enter number 2 :";//asking num2
cin>>num2;//reading num2
//printing value of num1 and num2 before swapping
cout<<"Value of num1 and num2 before swapping"<<endl;
cout<<"num1 : "<<num1<<", num2 : "<<num2<<endl;
swap(num1,num2);//calling function
//printing value of num1 and num2 after swapping
cout<<"Value of num1 and num2 after swapping"<<endl;
cout<<"num1 : "<<num1<<", num2 : "<<num2;
return 0;
}
//function defination
void swap(int &a,int &b)
{
int temp;//declaring temp variable
temp=a;
a=b;
b=temp;
}

======================================================

Output : Compile and Run main.cpp to get the screen as shown below

Screen 1 :main.cpp

******************************

Question 2:

main.cpp :

//c++ program that returns max to two number
#include <iostream>//header files
using namespace std;
int findmax(int,int);//function prototype
//main method
int main()
{   
int num1, num2;//declaring variables
cout<<"Enter number 1 : ";//asking num1
cin>>num1;//reading num1
cout<<"Enter number 2: ";//asking num2
cin>>num2;//reading num2
//print Maximum
cout<<"Maximum of "<<num1<<" and "<<num2<<" is : "<<findmax(num1,num2);
return 0;
}//function defination
int findmax(int num1,int num2)
{
int max;//declaring variable to store max
//checking numbers
if(num1>num2)
{
max=num1;
}
else
{
max=num2;
}
//return max
return max;
}
============================================

output :

Screen 1:

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.

Add a comment
Know the answer?
Add Answer to:
Help answer Questions in C++ 14. Create a function that swaps the values of the two...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Use Python: Dice Rolls Create a function named build_roll_permutations which returns all 36 permutations of rolling...

    Use Python: Dice Rolls Create a function named build_roll_permutations which returns all 36 permutations of rolling two six sided dice. That is, each dice has a number 1 through 6 on one of its sides. The return value is a list which contains tuples. Each tuple represents a possible dice roll of two dice. Card Deck Create a function named build_deck that returns a full deck of cards. The cards are created by a rank and a suit (e.g. 2♡)....

  • Please write the code using matlab 1) i. Create an anonymous function named optimist, that accepts...

    Please write the code using matlab 1) i. Create an anonymous function named optimist, that accepts a single variable as input i Create a row vector Tthat represents the number of seconds in two minutes, starting ii. Call the function optimist on the vector T, store the result in variable R1 and returns the double of that variable from one and ending at a hundred and twenty v. Create an anonymous function named pessimist, that accepts a single variable as...

  • can someone help me with this C++ problem write your game() function and 3+ functions that...

    can someone help me with this C++ problem write your game() function and 3+ functions that simulate the game of Jeopardy Dice according to the following game mechanics and specifications. Game Mechanics There are two players: the user and the computer, who alternate turns until one of them reaches 80 points or higher. The user is always the first player and starts the game. If any player reaches 80 points or more at the end of their turn, the game...

  • Please i need helpe with this JAVA code. Write a Java program simulates the dice game...

    Please i need helpe with this JAVA code. Write a Java program simulates the dice game called GAMECrap. For this project, assume that the game is being played between two players, and that the rules are as follows: Problem Statement One of the players goes first. That player announces the size of the bet, and rolls the dice. If the player rolls a 7 or 11, it is called a natural. The player who rolled the dice wins. 2, 3...

  • Please help as soon as you can Thnx! // ==== Callbacks ==== /* Step 1: Create...

    Please help as soon as you can Thnx! // ==== Callbacks ==== /* Step 1: Create a higher-order function * Create a higher-order function named consume with 3 parameters: a, b and cb * The first two parameters can take any argument (we can pass any value as argument) * The last parameter accepts a callback * The consume function should return the invocation of cb, passing a and b into cb as arguments */ /* Step 2: Create several...

  • Programming in C (using only #include <stdio.h>) 1. Create and use a new function called average....

    Programming in C (using only #include <stdio.h>) 1. Create and use a new function called average. 2. Average will accept two integer arguments, (here I will name them sum and n). n is the count of values included in sum. 3. The function will return the integer average of sum. 4. Define and use a function that checks an integer to see if it is positive (returns true if the integer is positive) Note: Choosing proper definition attributes (names, arguments,...

  • code in C++ Create a program that uses the pass by reference operator instead of the...

    code in C++ Create a program that uses the pass by reference operator instead of the return command. Your main program will need to: create empty variables call void function 1 with no input to display your name to the screen call function 2 to collect the square feet that a gallon of paint covers from user call function 2 to collect the square feet of wall that needs to be painted call function 3 to calculate the number of...

  • Write a C PROGRAM that will simulate rolling a die. When rolling a die, one will...

    Write a C PROGRAM that will simulate rolling a die. When rolling a die, one will get a die face value of 1-6. We can use rand function and math ceiling function to get a random number of 1-6 generated. The program will simulating rolling 5 dice simultaneously and store their face values into an array of size 5. The program will keep rolling the dice and print the following: 1. All face values in one line 2. If any...

  • can someone help me fix my jeopardy dice game I am having a hard time figuring...

    can someone help me fix my jeopardy dice game I am having a hard time figuring out what i am doing wrong #include #include using namespace std; //this function makes a number between 1 and 6 come out just like a dice int rollDie() { return (rand() % 6+1); } //this function asks the user with a printed statement if they want to roll the dice and gives instructions for yes and no (y/n) void askYoNs(){ cout<<"Do you want to...

  • Write two functions: Main should call the first function. The first function should use getline to...

    Write two functions: Main should call the first function. The first function should use getline to read a line of data: getline(cin,variableToHoldLineOfData); It should then call the second function, sending the line of data it just read. The second function should determine the number of CAPITAL letters, the number of lowercase letters, and the number of everything else (that's not capital or lower case). Count the length of the string and then use a for loop to go through each...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT