in python
This is the animal speaking game. Print the following menu for your user:
------------------------------------
1) Dog
2) Cat
3) Lion
4) Sheep
5) Exit
Please enter a selection.
------------------------------------
If the user enters 1, print("Bark")
If the user enters 2, print("Meow")
If the user enters 3, print("Roar")
If the user enters 4, print("Baah")
If the user enters 5, exit the program.
define functions for each animal. For example:
def dog() :
def cat() :
and so forth ...
When called, each animal function should return a string associated with the animal.
For example, dog() should return "bark" and cat() should return "Meow".
In the main() function, if the user selects selection 1 for dog, call the dog() function and print the return value "bark"
Add error checking code to determine if the user enters a menu
number less than 1 or greater than 5. If so, tell the user
the
correct range of menu selections is 1 - 5.
Be sure to put your name and assignment number at the top of the program in comments.
You should implement the following functions and call them from the main() function
- getUserInput() which prints the menu and returns the user input to the main() function
- dog()
- cat()
- lion()
- sheep()
In: Computer Science
develop a multithreaded version of radix
sort
c language
In: Computer Science
Write a program that implements a stack of integers, and exercises the stack based on commands read from cin. To do this, write a class called Stack with exactly the following members:
class Stack {
public:
bool isEmpty();
// returns true if stack has no elements stored
int top();
// returns element from top of the stack
// throws runtime_error("stack is empty")
int pop();
// returns element from top of the stack and removes it
// throws runtime_error("stack is empty")
void push(int);
// puts a new element on top of the stack
private:
vector<int> elements;
};
The program should read commands from cin until either end-of-file is reached or the command end is entered. (You can manually test for end-of-file by entering CTRL-D.) Each time the program expects a new command it should first print a prompt: "stack> "
Your program should catch all errors that happen and continue execution until the end command or end-of-file.
In case the command push is read, the program should read an integer value from cin and push it onto the stack. In case top is read, the program should print the top integer of the stack to cout. In case pop is read, the program should print the top integer of the stack to cout, and remove it from the stack. In case the command list is read, the program should print all values currently on the stack, without modifying the stack. (Exact format see below.)
Your program should check whether a "number" to be pushed is actually a number. If not, print an error message (see below), and reset cin such that it will again accept commands. (See Section 7.6 of the zyBook.) Also, your program should ignore all characters behind a number to be pushed that are on the same input line (example see below).
An example of a correct execution of this program is shown below:
stack> push 5 stack> pop 5 stack> pop error: stack is empty stack> push 6 stack> push 4bb stack> push foo error: not a number stack> list [4,6] stack> list [4,6] stack> top 4 stack> hello error: invalid command stack> end
You may want to use the compare() function (Links to an external site.) on a string to check which command has been entered.
Use of arrays, a built-in stack class, or container classes from std:: other than vector, is not allowed.
In: Computer Science
Task 2: Recursive Binary Search Part A - Target in list? Write a function simple recursive binary search(lst, target) which returns True if target is in lst; otherwise False. You must use recursion to solve this problem (i.e. do not use any loops).
Part B - Where is target? Write a function advanced recursive binary search(lst, target, lo, hi) which returns the index of an instance of target in lst between lo and hi, or None if target is not in that range. When first calling the function, lo = 0 and hi = len(lst)-1. You must use recursion to solve this problem (i.e. do not use any loops).
PYTHON CODE
In: Computer Science
/*
A right-angle triangle with integer sides a, b, c, such as 3, 4, 5,
is called a Pythagorean triple. The condition is that hypotenuse to
power of 2 is equal to adding of square of the 2 other sides. In
this example 25 = 16 + 9. Use brute force approach to find all the
triples such that no side is bigger than 50.
For this you should first implement the following Triangle class
and its methods. Then use it in main() to find all pythagorean
triples and put then in a std::vector. Finally print them out as
triples, like
(3, 4, 5)
.....
Make sure your output contains a triple only once, and not any
reordered ones, this means (3, 4, 5) is the same as (4, 3, 5) and
so only the increasing order triple should be printed out. This
means only (3, 4, 5) shoud be printed.
You program should print out all possible pythogorean triples with
sides <= 50.
*/
class Triangle
{
public:
Triangle(int a, int b, int c) // constructor.
Implement this
{}
bool isPythagorean() const // implement this
properly
{
return false;
}
private: // what do you put in private section?
}
int main()
{
}
In: Computer Science
For this assignment, you will apply what you learned in analyzing a simple Java™ program by writing your own Java™ program that creates and accesses an array of integers. The Java™ program you write should do the following:
Complete this assignment by doing the following:
Program Summary: This program demonstrates these basic Java
concepts:
* - Creating an array based on user input
* - Accessing and displaying elements of the array
*
* The program should declare an array to hold 10 integers.
* The program should then ask the user for an integer.
* The program should populate the array by assigning the user-input
integer
* to the first element of the array, the value of the first element
+ 100 to
* the second element of the array, the value of the second element
+ 100 to
* the third element of the array, the value of third element + 100
to
* the fourth element of the array, and so on until all 10 elements
of the
* array are populated.
*
* Then the program should display the values of each of the
array
* elements onscreen. For example, if the user inputs 4, the
output
* should look like this:
*
* Enter an integer and hit Return: 4
* Element at index 0: 4
* Element at index 1: 104
* Element at index 2: 204
* Element at index 3: 304
* Element at index 4: 404
* Element at index 5: 504
* Element at index 6: 604
* Element at index 7: 704
* Element at index 8: 804
* Element at index 9: 904
***********************************************************************/
package prg420week4_codingassignment;
// We need to import the following library if we want to use
the
// Scanner class to get user input.
import java.util.Scanner;
public class PRG420Week4_CodingAssignment {
public static void main(String[] args) {
// LINE 1. DECLARE AN ARRAY OF INTEGERS
// LINE 2. ALLOCATE MEMORY FOR 10 INTEGERS WITHIN THE
ARRAY.
// Create a usable instance of an input device
Scanner myInputScannerInstance = new Scanner(System.in);
// We will ask a user to type in an integer. Note that in this
practice
// code WE ARE NOT VERIFYING WHETHER THE USER ACTUALLY
// TYPES AN INTEGER OR NOT. In a production program, we would
// need to verify this; for example, by including
// exception handling code. (As-is, a user can type in XYZ
// and that will cause an exception.)
System.out.print("Enter an integer and hit Return: ");
// Convert the user input (which comes in as a string even
// though we ask the user for an integer) to an integer
int myFirstArrayElement =
Integer.parseInt(myInputScannerInstance.next());
// LINE 3. INITIALIZE THE FIRST ARRAY ELEMENT WITH THE CONVERTED
INTEGER myFirstArrayElement
// LINE 4. INITIALIZE THE SECOND THROUGH THE TENTH ELEMENTS BY
ADDING 100 TO THE EACH PRECEDING VALUE.
// EXAMPLE: THE VALUE OF THE SECOND ELEMENT IS THE VALUE OF THE
FIRST PLUS 100;
// THE VALUE OF THE THIRD ELEMENT IS THE VALUE OF THE SECOND PLUS
100; AND SO ON.
// LINE 5. DISPLAY THE VALUES OF EACH ELEMENT OF THE ARRAY IN
ASCENDING ORDER BASED ON THE MODEL IN THE TOP-OF-CODE COMMENTS.
}
}
In: Computer Science
Use Booth’s algorithm to multiply the 4-bit numbers, x and y, below, represented in twos complement. Show all your work.
In: Computer Science
please clear and direct anawar
Construct a B+ tree for the following set of key values under the assumption that the number of key values that fit in a node is 3.
Key values (3,10,12,14,29,38,45,55,60,68,11,30)
Show the step involved in inserting each key value.
In: Computer Science
Write a program that prints out the characters of a string each on a line and counts these characters. (Do not use the length function len() ).
In: Computer Science
There is many answer regarding this question on this website. So please I hope to get a new clear answer
E-commerce in Saudi Arabia has received a boost following the launch of several digital payment platforms in the last few years, a development that should support the growing number of online shoppers and contribute to government efforts to diversify the economy. Saudi Arabia is one of the fastest-growing markets in the Middle East for electronic payments, investments in the e-commerce market are set to rise under the government’s Vision 2030 strategy and National Transformation Programe (NTP), which both aim to improve communications connectivity and data transmission throughout the country as part of the broader diversification drive
. Answer the following questions:
1. What are the different methods of e-payment systems used in e-commerce platforms in Saudi Arabia?
2. Discuss the benefits of the multiple types of e-payment system to the customers?
3. Discuss the benefits of the multiple types of e-payment system to the e-commerce business?
4. What are some factors affecting the e-commerce business when choosing the e-payment gateways?
5. Explain some issues related to the e-payment system in the e-commerce platforms?
In: Computer Science
Hi,
I'm trying to make a basic GUI quiz in python using tkinter.
I would like the user to have to press a start button to begin the quiz and then be asked 5 different questions with the total score showing at the end. Ideally it would be a multiple choice quiz with the user having 4 different answers to choose from.
A very basic example of this would be appreciated so I can understand where exactly I'm going wrong.
Thanks in advance
In: Computer Science
In: Computer Science
/*
The following function receives the class marks for all student in
a course and compute standard deviation. Standard deviation is the
average of the sum of square of difference of a mark and the
average of the marks. For example for marks={25, 16, 22}, then
average=(25+16+22)/3=21. Then standard deviation = ((25-21)^2 +
(16-21)^2+(22-21)^2)/3.
Implement the function bellow as described above. Then write a test
console app to use the function for computing the standard
deviation of a list of marks that user inputs as floats in the
range of 0.f to 100.f. User signals end of the list by entering -1
as final mark. Make sure to verify user input marks are valid and
in the range, before processing them.
*/
float ComputeMarksStandardDeviation(std::array<float>
marks)
{
}
In: Computer Science
WRITE IN C++
Create a class named Coord in C++
Class has 3 private data items
int xCoord;
int yCoord;
int zCoord;
write the setters and getters. They should be inline functions
void setXCoord(int) void setYCoord(int) void setZCoord(int)
int getXCoord() int getYCoord() int getZCoord()
write a member function named void display() that displays the data items in the following format
blank line
xCoord is ????????
yCoord is ????????
zCoord is ????????
Blank line
Example
blank line
xCoord is 101
yCoord is -234
zCoord is 10
Blank line
In: Computer Science
could a business use it information technology to increase switching costs and lock in its customers and suppliers? Use business examples to support your answer
In: Computer Science