Write a program that simulates rolling two twenty-sided dice 100000 times, counting now many times the sum of the two dice is 2. Based on these results as well as the results of the program (snakeeyes.py) shown in class, make a guess as to how often one can expect to roll snake-eyes (two Is) on a pair of dice labeled I through n, for any positive integer n. S
Q: Type and turn in a complete C program to solve the following problems: Question 1: Write a program…
A: #include <stdio.h> int main(){ int grades[100]; float average=0;…
Q: Write a recursive function that takes as a parameter a nonnegative integer and generates the…
A: While doing programming in any programming language, you need to use various variables to store…
Q: Write a program in c++ that will allow a user to find the hypotenuse of a right triangle using the…
A: Given: We have to write a a program in c++ that will allow a user to find the hypotenuse of a…
Q: Write C++ program that accepts coefficients of a quadratic equation from the user and displays the…
A: #include <iostream>#include <cmath>using namespace std;int main() { float a, b, c,…
Q: Question 12: Code the given problem using python The Physics teacher in Alexandra's class is…
A: Answer in step2
Q: The programming language is C++, write a program for each items base on the given statement. 1.…
A: Code: #include <iostream>using namespace std; int main() { int grade, newGrade; cout <<…
Q: Write a program, using a void function, that takes as input an integer and outputs two times the…
A: #include<iostream> using namespace std; void function1(int input){ if(input%2==0)…
Q: 3. Marry has planned to do build a wall of height 2m around her rectangular garden. The cost of…
A: The total cost of building complete wall = Area of complete wall * Rate per m2 Area of complete…
Q: Question 12: Code the given problem using python The Physics teacher in Alexandra's class is…
A: Given:
Q: Write C Program that receive number of students in a Lecture, and decide how much form of exam…
A: logic:- read number of students read width and height of lecture hall. define sizeLecture(double…
Q: 9. Do Programming Exercise 3 from Chapter 5 using a function grade(score) that returns the letter…
A: Functions in python: Functions provide a way to break problems or processes down into smaller and…
Q: A palindrome is a string whose first half is equal to the reverse of its second half. - Examples of…
A: Program plan: Define check_palindrome function as follows: Initialize two pointer variables,…
Q: A geometric sequence is a sequence of numbers where each term after the first is found by…
A: // GeometricSeries class definition class GeometricSeries { private: // a represent first term…
Q: in C# Sometimes figuring letter grades is hard. Write a program that asks for, and reads from the…
A: C# program
Q: 39. Write a program for the following problem. An instructor needs a program that accepts a student…
A: Given : semester average grade 90 -100 A 80-89 B 70-79…
Q: Problem 3) Write a code for computing solutions of difference equations, y[n] + al*y[n-1] +…
A: Find a possible solution below.
Q: MACHINE PROBLEM 2 WRITE A COMPUTER PROGRAM USING ANY LANGUAGE OF YOUR CHOICE THAT WILL IMPLEMENT…
A: The code and the output for the above given question is below:
Q: Please answer the question in C++ only Given an integer N, let us consider a triangle of numbers of…
A: The procedure to solve the given problem: After taking the required inputs from the user, start with…
Q: Direction: Provide solution for Problem Solving Phase: d) Flowehart e.) Source Code in Ć Machine…
A: Algorithm: Take the distance, efficiency, and price of gas from user. Calculate the cost of commute…
Q: C++ Code is allowed: Sachin has a rectangular paper of his usual work. Sachin knows that he will…
A: Dynamic programming is the technique in the computer programming which helps to efficiently solve…
Q: Define function print_popcorn_time() with parameter bag_ounces. If bag_ounces is less than 3, print…
A: Python program for above : # required function def print_popcorn_time(bag_ounces): if…
Q: Problem 2 Modify your program in Problem 1, such that if the requested term does not exist in the…
A: please see the next step for solution
Q: (Ransom Note Problem) in python A kidnapper kidnaps you and writes a ransom note. He does not write…
A: Program code: def ransom_note(magazine, ransom): hash_words = {} # Create the hash tabled…
Q: Question 1: Write a program using functions, which can print a rectangle of stars (Asterisks) of…
A: Define the function rectangle to hold the height and width. In main function take the value from the…
Q: Problem: Using PYTHON, create a code that asks you to enter three numbers: a, b, and x. Create a…
A: Ans:) In this program, we need to create a recursive function that will print the multiples of x in…
Q: The athlete is given two attempts to shoot. The highest score counts. From the list of attempts, get…
A: #include <bits/stdc++.h>using namespace std; int main() { int number_of_atheletes=0; //…
Q: Goldbach conjecture states that every even number greater than 2 can be expressed as a sum of two…
A: Algorithm to check whether the Goldbach conjecture holds for ‘N’. Start Check whether the entered…
Q: You should consider the following points in your solution: 1- The program should not contain any…
A: import turtle as tlist=["brown","red","meganta","blue","green","orange"]n=0for i in range(6): for…
Q: write a C/C++ program that defines a function Lucas() that calculates the n th number in a Lucas…
A: This can be done using recursion and using loops
Q: 1.Write a program in C++ , to count the number of people in each of the following age groups: 0-16…
A: Following is the approach of the program to count the number of persons of different age…
Q: Question 12: Code the given problem using python The Physics teacher in Alexandra's class is…
A: Here is the detailed and simplified python code for the given question:
Q: Task 11 Write a Python program that takes a number from the user and prints its digits from left to…
A: The programming methodology for the program is given by: Input the number in num variable using…
Q: Q:1 a) Can a predefined function be recursively called by the programmer? Elaborate. b) Write a…
A: a) A predefined function cannot be recursively called by the programmer as its definition is…
Q: u will show the only Survivor step off Genetic Algorithm -The selected survivors (solutions) will…
A: Write a simple python code where you will show the only Survivor step off Genetic Algorithm -The…
Q: Problem #1: [35 pts] Profit calculation for an Avocado farm Write a program that helps a farmer…
A: .
Q: Note: C++ Programming Answer Required The annual snake festival is upon us and all the snakes of the…
A: Algorithm: The first line contains a single integer, R, which denotes the number of reports to be…
Q: C++ Question, Write a Computer Code: Let l be a line in the x-y plane. If l is a vertical line, its…
A: #include <iostream> using namespace std; int main(){ float m,x1,x2,y1,y2,b; cout…
Q: Problem 2. An electricity board charges the following rates mentioned in the table for the use of…
A: As per the given question, we need to calculate the monthly bill of a user based on the selected…
Q: 4. A newly opened college ground is rectangular in shape and the Management decides to build a fence…
A: Algorithm: Step 1: Start Step 2: declare variables l and b Step 3: read l(length), b(width) Step 4:…
Q: Problem 2. (Playing the Waltz) Write a program called playwaltz.py that accepts from standard input,…
A: Write a program playvalt2.py that accepts from standard input, a sequence of 32 integers…
Q: I need help problem: A two dimensional random walk simulates the behavior of a particle moving in a…
A: Since the Programming language is not mentioned in the question, we will answer this question in…
Q: Q1:Write a program in C++ language to find an average of student with seven subjects by using…
A: #include <iostream>using namespace std; float average(float marks[]) //function to find…
Q: In this problem, your task is to complete the reverseNumber(num) function. The input of the function…
A: n = 1000; rev = 0 while(n > 0): a = n % 10 rev = rev * 10 + a n = n // 10 print(f'\noutput:…
Q: 4. A newly opened college ground is rectangular in shape and the Management decides to build a fence…
A: Algorithm: Step 1: Start Step 2: declare variables l and b Step 3: read l(length), b(width) Step 4:…
Q: Problem #2: [50 pts] Write a program that calculates the net salary after tax deduction according to…
A: Code and output is given in step2
Q: Write a closure function that finds and returns the bonus for the employee salary according to the…
A: Here I have created a function named closure(). In this function, I have first of all declared a…
Q: Write a program that will calculate and print bills for the city power company. The rates vary…
A: The C++ program with the given description will be created as follows: Declare int variables for ID…
Q: 4. A newly opened college ground is rectangular in shape and the Management decides to build a fence…
A: Algorithm: Step 1: Start Step 2: declare variables l and b Step 3: read l(length), b(width) Step 4:…
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
- Please code in C++. Write a program that simulates a coin-tossing game. At the beginning of the game, each of N players has a single fair coin and M points. The game performs a sequence of passes until only a minimum number of players remain. In a pass the players toss their coins into the air and when the coins fall to earth, the players count the number of coins that show heads and the number of coins that show tails. If the number of heads exceed the number of tails, then the players who tossed heads increase their points by an integer P and the players who tossed tails decrease their points by the same integer P. The players perform the opposite actions when the number of tails is greater than the number of heads. If the number of heads equals the number of tails, then no player’s points change. If any player’s points fall below one, then the player leaves the game, never to return. The game employs a second integer K to compute P’s value. K’s and P’s initial values are one.…(Numerical) Write a program that tests the effectiveness of the rand() library function. Start by initializing 10 counters to 0, and then generate a large number of pseudorandom integers between 0 and 9. Each time a 0 occurs, increment the variable you have designated as the zero counter; when a 1 occurs, increment the counter variable that’s keeping count of the 1s that occur; and so on. Finally, display the number of 0s, 1s, 2s, and so on that occurred and the percentage of the time they occurred.(Conversion) a. Write a C++ program to convert meters to feet. The program should request the starting meter value, the number of conversions to be made, and the increment between metric values. The display should have appropriate headings and list the meters and the corresponding feet value. If the number of iterations is greater than 10, have your program substitute a default increment of 10. Use the relationship that 1 meter = 3.281 feet. b. Run the program written in Exercise 6a on a computer. Verify that your program begins at the correct starting meter value and contains the exact number of conversions specified in your input data. c. Modify the program written in Exercise 6a to request the starting meter value, the ending meter value, and the increment. Instead of the condition checking for a fixed count, the condition checks for the ending meter value. If the number of iterations is greater than 20, have your program substitute a default increment of (ending value - starting value) / 19.
- Use C++ Write a program that simulates flipping a coin to make decisions. The input is how many decisions are needed, and the output is either heads or tails. Assume the input is a value greater than 0. Ex: If the input is: 3 the output is: heads tails heads For reproducibility needed for auto-grading, seed the program with a value of 2. In a real program, you would seed with the current time. In that case, every program's output would be different, which is what is desired but can't be auto-graded. Note: A common student mistake is to call srand() before each call to rand(). But seeding should only be done once, at the start of the program, after which rand() can be called any number of times. Your program must define and call the following function that returns "heads" or "tails".string HeadsOrTails()C++ Programming Exercise: A real estate office handles, say, 50 apartment units. When the rent is, say, $600 per month, all the units are occupied. However, for each, say, $40 increase in rent, one unit becomes vacant. Moreover, each occupied unit requires an average of $27 per month for maintenance. How many units should be rented to maximize the profit? Write a program that prompts the user to enter: a. The total number of of units. b. The rent to occupy all the units. c. The increase in rent that results in a vacant unit. d. Amount to maintain a rented unit. The program then outputs the number of units to be rented to maximize the profit.in C# Sometimes figuring letter grades is hard. Write a program that asks for, and reads from the user, a midterm exam grade and a final exam grade. Compute the average of those two grades and ouput a letter grade based on the scale shown below. CHALLENGE PROBLEM: One of my graduate school classes modified the above calculation. This professor said that the final grade would be determined by the simple average of the midterm and the final, however, if the student scored better on the final than they did on the midterm, the professor would weight the midterm exam at 25%, and the final exam at 75% when computing the final grade. Modify your code to use this professors modification in determining letter grade. Here is the grading scale:
- Please can be handwritten. Question 2: Implementing a Recursive Function . Write recursive function, recursionprob(n), which takes a positive number as its argument and returns the output as shown below. The solution should clearly write the steps as shown in an example in slide number 59 and slide number 60 in lecture slides. After writing the steps, trace the function for “recursiveprob(5)” as shown in an example slide number 61. Function Output: >> recursionprob(1) 1 >> recursionprob(2) 1 4 >> recursionprob(3) 1 4 9 >>recrusionprob(4) 1 4 9 16Question 2: Implementing a Recursive Function .Write recursive function, recursionprob(n), which takes a positive number as its argument and returns the output as shown below. The solution should clearly write the steps as shown in an example in slide number 59 and slide number 60 in lecture slides. After writing the steps, trace the function for “recursiveprob(5)” as shown in an example slide number 61. Function Output: >> recursionprob(1) 1 >> recursionprob(2) 1 4 >> recursionprob(3) 1 4 9 >>recrusionprob(4) 1 4 9 16(IN PYTHON) Problem 2 Write a function count_8s(string) that performs the following actions: Receives a single parameter called string that we expect to be a string. If we receive something that is NOT a string, raise a TypeError with the message “Non-string input received.” Uses recursion to count the number of eights in the string. Use a string of length 0 as your base case. Otherwise, determine if the first character in string is “8” or not, and call count_8s() again with the rest of the string as an argument. Returns the number of eights found in the string. NOTE: You are not to use a while or for loop in your code.
- (b) Good Programming practices help in improving programs readability and understandability both for a programmer and for a general user. What changes would you make in the following program, written by a beginner, keeping in view the good programming practices. You are also required to write the output of the program if a user wants to find factorial of number 6. Note: The Program finds/calculates factorial of a number using a user defined recursive function. #include<iostream> using namespace std; int f(int n); int main() {int n; cout << "Enter: "; cin >> n; cout << "Answer = " <<factorial(n); return 0; } int f(int n) { if(n > 1)return n * f(n - 1); else return 1; }Problem B Musical Key ConversionThe chromatic scale is a 12-note scale in music in which all notes are evenly spaced: that is, the ratio of the frequency between any two consecutive notes is constant. The notes are typically labeled in the following sequence: A, A#, B, C, C#, D, D#, E, F, F#, G, G# After G#, the labels loop back and start over with A (one octave higher). To convert between musical keys, you can shift all notes in a piece of music a constant number of steps along the scale above. For example, the sequence of notes E, E, F, G, G, F, E, D, C, C, D, E, E, D, D can be converted to another musical key by shifting everything up three steps: E, E, F, G, G, F, E, D, C, C, D, E, E, D, D G, G, G#, A#, A#, G#, G, F, D#, D#, F, G, G, F, F Notice that G was converted to A#, since going three steps up required us to loop off of the top of the scale back to the bottom: G -> G# -> A -> A#. Technically we should note that this would be A# of the next octave up, but we’ll…Problem B. Musical Key ConversionThe chromatic scale is a 12-note scale in music in which all notes are evenly spaced: that is, the ratio of the frequency between any two consecutive notes is constant. The notes are typically labeled in the following sequence: A, A#, B, C, C#, D, D#, E, F, F#, G, G# After G#, the labels loop back and start over with A (one octave higher). To convert between musical keys, you can shift all notes in a piece of music a constant number of steps along the scale above. For example, the sequence of notes E, E, F, G, G, F, E, D, C, C, D, E, E, D, D can be converted to another musical key by shifting everything up three steps: E, E, F, G, G, F, E, D, C, C, D, E, E, D, D G, G, G#, A#, A#, G#, G, F, D#, D#, F, G, G, F, F Notice that G was converted to A#, since going three steps up required us to loop off of the top of the scale back to the bottom: G -> G# -> A -> A#. Technically we should note that this would be A# of the next octave up, but we’ll…