# RQ3
def largest_factor(n):
"""Return the largest factor of n that is smaller than n.
>>> largest_factor(15) # factors are 1, 3, 5
5
>>> largest_factor(80) # factors are 1, 2, 4, 5, 8, 10, 16, 20, 40
40
"""
"*** YOUR CODE HERE ***"
# RQ4
# Write functions c, t, and f such that calling the with_if_statement and
# calling the with_if_function do different things.
# In particular, write the functions (c,t,f) so that calling with_if_statement function returns the integer number 1,
# but calling the with_if_function function throws a ZeroDivisionError.
def if_function(condition, true_result, false_result):
"""Return true_result if condition is a true value, and
false_result otherwise.
>>> if_function(True, 2, 3)
2
>>> if_function(False, 2, 3)
3
>>> if_function(3==2, 3+2, 3-2)
1
>>> if_function(3>2, 3+2, 3-2)
5
"""
if condition:
return true_result
else:
return false_result
def with_if_statement():
"""
>>> with_if_statement()
1
"""
if c():
return t()
else:
return f()
def with_if_function():
return if_function(c(), t(), f())
def c():
"*** YOUR CODE HERE ***"
def t():
"*** YOUR CODE HERE ***"
def f():
"*** YOUR CODE HERE ***"
In: Computer Science
In Java, write the method public static void insertUnique(List l, T e), user of the ADT List. The method takes a list l and an element e and inserts the element at the end of the list only if it is not already there. Example 0.2. If l : A → B → C, then after calling insertUnique(l, "C"), the list does not change. Calling insertUnique(l, "D") will make l be : A → B → C → D.
In: Computer Science
construct the trace table or trace table list for the
function call CR (111) where the definition of CR () is
bool CR ( int n )
{
bool w,x,y,z,r;
int c;
c= 3*n;
c + = 16;
c=c%5;
w=c==4;
In: Computer Science
Implement a calculator (not postfix notation) using Swift Programming Language(Swift 3, basic ios app). Please use MVC model(CalculatorBrain.swift can be the model and ViewController.swift can be the view). Also please post the sreenshot of the storyboard that you make.
Requirements:
Implement add subtract, multiply, divide, pi, sqrt, Euler’s natural number (e), co-sine and equals.
Ensure you have the ability to handle multiple operations in sequence
Implement the ability to enter floating point numbers into the display
Add 4 more buttons (ex. sine)
Handle multiple operations in a sequence.
Add a memory function to your calculator that stores and retrieves a number. Implement the following buttons at the top of the keyboard
MC = Memory clear sets memory to 0
MR – Memory recall uses the number in memory acting as it you typed that number in yourself
MS – Memory Store puts the number on display into memory
M+ – Memory takes the number on the display, adds it to the memory, and puts the result into memory.
Implement a clear (C) button. If the clear button is pressed once, it should take whatever was typed before the last enter and put it to 0. If the clear is entered twice, it should clear the stack.
Show the history of every operand and operation input by displaying it.
In: Computer Science
Problem 2: show all work
A. Find the complement of F = WX + YZ. B. Show that FF’ = 0 C. Show that F + F’ = 1
In: Computer Science
I need an answer in C++, please
TITLE
PRIME FACTORIZATION USING AN ARRAY-BASED STACK
INTRODUCTION
This project revisits one of the problems in Project 2, and it will re-use a function within the solution developed there.
An integer is prime if it is divisible only by itself and 1. Every integer can be written as a product of prime numbers, unique except for their order, called its prime factorization. For example,
1776 = 37 x 3 x 2 x 2 x 2 x 2.
DESCRIPTION
Design, implement, document, and test an interactive program that reads positive integers from the terminal and writes their prime factorizations to the screen. The program should list the factors of each integer in decreasing order, as in the example above, and should terminate when the user enters 0 or a negative value.
INPUT
The program's input is positive integers, entered from the terminal, terminated by 0 or a negative value.
OUTPUT
The program's output consists of prompts for the input values and the input values' prime factorizations. It writes this output to the terminal.
ERRORS
The program can assume that its input is integers; it need not detect any errors.
EXAMPLE
A session with the program might look like this:
Enter a positive integer (0 to stop): 1776
Prime factors: 1776 = 37 x 3 x 2 x 2 x 2 x 2
Enter a positive integer (0 to stop): 6463
Prime factors: 6463 = 281 x 23
Enter a positive integer (0 to stop): 349856
Prime factors: 349856 = 29 x 29 x 13 x 2 x 2 x 2 x 2 x 2
Enter a positive integer (0 to stop): 36423479
Prime factors: 36423479 = 36423479
Enter a positive integer (0 to stop): 1
Prime factors: 1 = 1
Enter a positive integer (0 to stop): 0
OTHER REQUIREMENTS
Implement a stack abstract data type in a class in which a typedef statement specifies the type of the stack's items. Use a sequential (array-based) stack implementation. As the program identifies prime factors, it should save them by pushing them onto a stack of integers provided by this class.
If d >= 2 is the smallest integer that divides an integer n, then d is prime. Therefore the program can identify prime factors (in ascending order) by repeatedly identifying the smallest factor of the target value and then dividing the target value by the factor. The program need not test that these smallest factors are prime or attempt to list only prime values; this will happen automatically.
Thus, to identify the prime factors of n, first find the smallest factor that divides n, push it onto the stack, and divide n by the factor. Then find the smallest factor of the new value of n; handle it the same way. Continue in this way until n = 1. Then pop and print the values until the stack is empty.
This scheme identifies prime factors in order of increasing magnitude; saving the values on the stack and then popping and printing them displays them in decreasing order, as specified.
HINT
Recall that you wrote a function that returns the smallest factor of its positive integer argument back in Project 2. You can re-use that function in this project.
HAND IN
See About Programming Assignments for a description of what to hand in: design document, user document, code, tests, and summary.
Question: If we wanted to report each integer's prime factors in increasing order, would the stack be necessary or helpful? Explain.
Project 2:
PRIME FACTORIZATION
The smallest nontrivial factor of a positive integer is necessarily prime. (Can you prove this?) Write a program that takes advantage of this fact in a recursive function that writes the prime factors of an integer to the terminal in ascending order.
A run of the program that exercises this function might look like this:
Enter a positive integer: 5432
The prime factors of 5432 are 2 2 2 7 97
Hint: Begin by writing a function that returns the smallest factor (greater than 1) of its positive integer argument. The recursive function will call this one.
QUESTION: How would you modify the function to print the prime factors in descending order?
In: Computer Science
|
-9 |
-5 |
-2 |
0 |
1 |
3 |
7 |
11 |
17 |
19 |
21 |
25 |
27 |
31 |
37 |
41 |
a
index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
int search(int a[], int t, int l, int r){
if(l<=r){
int m=(l+r)/2;
if(t==a[m]) return m;
else if (t<a[m]) return search(a, t, l,m-1);
else return search(a, t, m+1, r)
}
return -1;
}
In: Computer Science
Need it ASAP!!!
Write a complete Java program to compute personal income tax. Your program should prompt the user to enter the taxable income (double) and output the income tax (double) according to the table below:
First $20,000 0 Next $20,000 ($20,001 to $40,000) 10 Next $20,000 ($40,001 to $60,000) 20 The remaining (Above $60,000) 30
The tax payable should be rounded to 2 decimal places. The name of this program (class) will be Tax
In: Computer Science
Write two python codes for a TCP client and a server using a Socket/Server Socket. The client sends a file name to the server. The server checks if there is any integer value in the file content. If there is an integer number, the server will send a message to the client “Integer exists” otherwise, the message “Free of Integers”
In: Computer Science
The Learning Journal is a tool for self-reflection on the learning process. In addition to completing directed tasks, you should use the Learning Journal to document your activities, record problems you may have encountered and to draft answers for Discussion Forums and Assignments. The Learning Journal should be updated regularly (on a weekly basis), as the learning journals will be assessed by your instructor as part of your Final Grade.
Your learning journal entry must be a reflective statement that considers the following questions:
1. Describe what you did. This does not mean that you copy and paste from what you have posted or the assignments you have prepared. You need to describe what you did and how you did it.
2. Describe your reactions to what you did.
3. Describe any feedback you received or any specific interactions you had. Discuss how they were helpful.
4. Describe your feelings and attitudes.
5. Describe what you learned.
Another set of questions to consider in your learning journal statement include:
1. What surprised me or caused me to wonder?
2. What happened that felt particularly challenging? Why was it challenging to me?
3. What skills and knowledge do I recognize that I am gaining?
4. What am I realizing about myself as a learner?
5. In what ways am I able to apply the ideas and concepts gained to my own experience?
Finally, describe one important thing that you are thinking about in relation to the activity.
Minimum of 500 words.
These weeks Topics
Topics:
In: Computer Science
JAVA Code
Learning objectives; File I/O practice, exceptions, binary search, recursion.
Design and implement a recursive version of a binary search. Instead of using a loop to repeatedly check for the target value, use calls to a recursive method to check one value at a time. If the value is not the target, refine the search space and call the method again. The name to search for is entered by the user, as is the indexes that define the range of viable candidates can be entered by the user (that are passed to the method). The base case that ends recursion is either finding the value within the range or running out of data to search. The program will work on an array of sorted String objects read in from a text file. Your program will generate an exception, that provides a message to the user, if the file can't be found or if the starting index is after the ending index. You will create your own text file of first names in alphabetical order (binary search required ordering) to test your program.
In: Computer Science
In: Computer Science
You are to create a program to request user input and store the data in an array of structures, and then display the data as requested. The data you are collecting refers to a set of images. The images are OCT images taken of the lining of the bladder. The data you provide will help diagnose the image as cancerous or not, but your code does not need to do that at the moment.
1) Define a global structure that contains the following information:
a) File number (must be >0)
b) Diagnosis number (1-8)
c) Number of layers in the image
d) Maximum average intensity of a single row (should be a float) e)
Width of brightest layer
2)
be a global variable.
Declare an array of 9 of the structures in #1. This array should
3) Initialize each of the file numbers in the array to -1.
4) Create a loop that will continue asking the user for the above
data until the file number 0 is given, or until information has been provided for 9 images.
5) If the user provides a file number less than 0, ask again. Do
not ask for further information if the user provides a file number
equal to 0.
6) If the user provides a diagnosis number that is not between 1
and 8, ask again.
7) Store the data in the array of structures in the order it is provided.
8) Write a function to display the information for a particular file number. If the file number was not found, nothing is displayed. The function will return a 1 if the file number was found or a 0 if the file number was not in the array.
9) In your main function, after the loop which requests the data, create another loop that will request a file number from the user and then call the function written for #8 to display the data for that file number. This loop will continue until a file number is provided that is not found.
10) In your main function, after the code for #9, add a loop that will display the information for all items stored in the array in order.
C++ Coding Please
In: Computer Science
This document describes a computer program you must write in Python and submit to Gradescope. For this project, the program will simulate the operation of a vending machine that sells snacks, accepting coins and dispensing products and change. In an actual vending machine, a program running on an embedded computer accepts input from buttons (e.g. a numeric keypad) and devices such as coin acceptors, and its output consists of signals that control a display, actuate motors to dispense products, etc.. However, for this project you will build a simulation where all of the necessary input signals are replaced by keyboard input from a user, and all output signals and actions are indicated by printing text to the terminal. 2. PREVIEW Here is a sample session of using the kind of vending machine simulator you are going to write. This example is meant to convey the general idea. A longer sample input and output for the program can be found in Section 7. Red boxes indicate keyboard input from the user. CREDIT : $0 .00 > inventory 0 Nutrition nuggets $1 .00 (5 available ) 1 Honey nutrition nuggets $1 .20 (5 available ) 2 Almonds $18 .00 (4 available ) 3 Nutrition nugget minis $0 .70 (10 available ) 4 A carrot $4 .00 (5 available ) 5 Pretzels $1 .25 (8 available ) CREDIT : $0 .00 > 3 MSG : Insufficient credit CREDIT : $0 .00 > quarter CREDIT : $0 .25 > quarter CREDIT : $0 .50 > quarter CREDIT : $0 .75 > 3 VEND : Nutrition nugget minis RETURN : nickel CREDIT : $0 .00 > 3. OPERATIONAL SPECIFICATION This section describes how your program must operate. The program will be given one command line option, which is the name of a text file containing the inventory. The format of this file is described below (Section 3.1). The program will read this file to determine the starting inventory of snacks. It will then begin the simulation, in which it reads user commands and responds accordingly. The required commands are described in Section 3.4. 3.1. Inventory. Before starting the simulation, your program must open, read, and close the text file specified in the first command line argument after the script name. This file will consists of 6 lines, each of which describes one of the six snacks available for purchase. The format of a line is stock,price,name where stock is the number of the snack available at the beginning of the simulation, price is the price of the snack in cents (which will be a multiple of 5), and name is a string not containing the character ”,” that describes the snack. The order of the snacks is important, because when ordering from the machine, a snack is indicated by its 0-based index; thus snack 2 means the third line of the inventory file. Here is a sample inventory you can use for testing: 6,125,Cheesy dibbles 10,115,Oat biscuits 12,75,Sugar rings 5,150,Celery crunchies 6,205,Astringent persimmon 10,95,Almond crescents This inventory file is available for download from https://dumas.io/teaching/2020/fall/mcs260/project2/sample_inventory.txt This inventory indicates, for example, that snack 2 is Sugar rings, of which there are initially 12 available, each of which has a cost of $0.75. 3.2. The simulation. After reading the inventory, your program should enter a loop (the command loop) in which it does the following, repeatedly, in order: • Print CREDIT: followed by the total amount of credit currently deposited in the machine, printed on the same line. The credit is initially $0.00. It should always be printed as a dollar sign, followed by a dollar amount with two digits after the decimal point. • Print a prompt > • Wait for one line of user input • Perform the action associated with the user input, which may involve additional output (see Section 3.4) Note that during the simulation, you need to keep track of the credit (the total amount of money deposited to the machine) and display it on each iteration of the loop. The remaining stock of each snack must also be tracked, as this will change as a result of purchases and restocking. 3.3. Control logic overview. The next section describes the commands your simulation must accept from the user. This section is a high-level description of the underlying principles of operation; for full details see Section 3.4. The simulated vending machine allows the user to insert coins to add credit. If the credit already equals or exceeds the price of the most expensive snack in the inventory, any coin inserted will be immediately returned. The user can select a snack by number (0–5), and if the credit currently in the machine equals or exceeds the price of the snack, then the snack is dispensed. Any change (the difference of the credit and the price) is dispensed as coins. Finally, a maintenance worker can specify that one of the snacks is being restocked, i.e. more of that snack has been loaded into the machine. Restocked snacks are then available for purchase. 3.4. Commands. The simulation must support the following commands: • quarter - simulates deposit of one quarter ($0.25). If the current credit is less than the most expensive item in the inventory (including any items that may be out of stock), the coin is accepted and credit increases by $0.25. Otherwise, the coin is rejected by printing the line RETURN: quarter to indicate that the quarter just deposited is returned. • dime - simulates deposit of one dime ($0.10). The logic is the same as the quarter command, except that if the dime is not accepted, the line to be printed is RETURN: dime • nickel - simulates deposit of one dime ($0.05). The logic is the same as the quarter command, except that if the nickel is not accepted, the line to be printed is RETURN: nickel • inventory - display the current inventory in the format of 0-based index, followed by name, followed by price, and then a parenthetical statement of the number available, in this format: 0 Cheesy dibbles $1.25 (6 available) 1 Oat biscuits $1.15 (10 available) 2 Sugar rings $0.75 (12 avilable) 3 Celery crunchies $1.50 (5 available) 4 Astringent persimmon $2.05 (6 available) 5 Almond crescents $0.95 (10 available) • Any of the digits 0, 1, 2, 3, 4, 5 - this is a request to purchase the snack whose 0-based index in the inventory is the given integer. The action depends on the current credit and stock: – If the current credit is sufficient to purchase that snack, and if the stock of that snack is positive, then the machine dispenses the snack followed by change. Dispensing the snack is simulated by printing VEND: Name of snack where “Name of snack” is replaced by the name specified in the inventory. Then, returning change is simulated by printing lines such as RETURN: quarter RETURN: dime RETURN: nickel so that each line corresponds to one coin that is returned. The process for making change is subject to additional rules, described in Section 3.5. After a successful purchase and dispensing of change, the stock of that item decreases by one, and the credit is set to $0.00. – If the stock of the requested item is zero, the following line is printed: MSG: Out of stock The credit is unchanged, and the loop begins again immediately. (For example, if the credit was also insufficient for that item, no message is printed to that effect.) – If the stock of the requested item is positive, but the current credit is NOT sufficient to purchase that snack, then the following line is printed: MSG: Insufficient credit The credit is unchanged. • restock - add to the inventory of one snack. This command never appears on a line by itself, and is always followed by a space and then two integers separated by spaces. The first integer is the 0-based index of a snack, and the second is the number of additional items loaded. The effect of this command is to immediately increase the inventory of that snack. The current credit is not changed. For example, restock 3 18 means that the inventory of snack 3 should be increased by 18. • return - a request to return all currently-deposited credit. The credit should be returned to the user in the same way that change is returned after a successful purchase (see Section 3.5 for detailed rules). • exit - exit the program. 3.5. Coin return rules. The specifications above include two situations in which coins need to be dispensed to the user: • After a purchase, to give change • In response to the return command, to return the current credit In each case, simulated coins are dispensed by printing lines such as RETURN: quarter RETURN: dime RETURN: nickel each of which corresponds to a single coin. The sequence of coin return lines must begin with quarters, followed by dimes, and lastly nickels. Change must be given using the largest coins possible, so for example it is never permissible to give two or more dimes and one or more nickel, because the same change could be made with the number of quarters increased by one. For the purposes of this assignment, the machine never runs out of coins. The following “greedy” approach will dispense coins meeting these requirements: (1) Dispense quarters until the remaining amount to return is less than $0.25. (2) Dispense dimes until the remaining amount to return is less than $0.10. (3) Dispense nickels until the remaining amount to return is zero. Note that unlike most real-world vending machines, these rules mean that the return command may give back a different set of coins than the user deposited. For example, after depositing five nickels, the return command would return a single quarter. 3.6. Efficiency. Your program must be able to complete 50 commands in less than 30 seconds, not counting the time a user takes to enter the commands. This is an extraordinarily generous time budget, as a typical solution will take at most 0.01 seconds to complete 50 commands. It is almost certain that you will not need to pay attention to the speed of any operation in your program. However, if you perform tens of millions of unnecessary calculations in the command loop, or do something else unusual that makes your program slow to respond to commands, then the autograder will run out of time in testing your program. In this case you will not receive credit.
In: Computer Science
FoodBox is an online business that serves many customers by allowing them to order food for delivery from local restaurants. The company has a web portal that has a listing of local restaurants for a zip code. The restaurants will be able to register with the portal and list their menus for an annual subscription fee of $190 or a monthly subscription fee of $25. Drivers, who are willing to pick up food from restaurants and deliver to customers will be able to register with the portal for an annual subscription fee of $95 or a monthly subscription fee of $15. Customers will be able to search for restaurants based on the zip code and view a list of all restaurants registered with FoodBox around that area. They will be able to view the menu for a particular restaurant and place an order. The payment is complete when the order is placed. Once an order is placed, the restaurant can either accept or reject the order. If an order is rejected, the customer must be refunded for the payment made. If an order is accepted by the restaurant, the restaurant provides an estimated time in the portal when the order will be ready for pickup. The application searches for drivers who are near the restaurant and available to deliver the food and notifies the selected driver to drive to the restaurant at the time when the order is expected to be ready for pickup. The driver is also provided with the address of the customer to whom the delivery needs to be made. The portal also provides a way for users to register for an account with the system, track their orders, view their order history and process a payment using credit card, paypal or zelle.
Assume the following Use Case Description:
|
Use Case Name: |
Create Order |
|
Primary Actor(s): |
Customer |
|
Brief Description: |
This use case describes how an order will be created using the system. |
|
Trigger: |
Customer accesses the portal and creates and order. |
|
Precondition: |
None |
|
Normal flow of events: |
|
|
Alternate/Exception flow: |
|
In: Computer Science