/* Complete this javascript file according to the individual instructions given in the comments. */ //1) Create an Object using an Object Literal (the easiest way) // Name your object Breakfast // Your object should have 3 key:value pairs // The three keys should be: breakfast, lunch, dinner // Put your food choice for each as the value // 2) Display the keys of your Breakfast object in the // console. We have learned two ways to do this.. either // works here! // 3) With the object you created above, use dot notation to change // the value of the lunch property to "grilled cheese". // Add a method to your object named "digIn" that returns "Chomp!" // Call the method on the Breakfast object and send the output // to the console. // 4) Create an object constructor named Pizza. // Pizza should require a parameter called size. // size should be a property of Pizza. // // Create a new Pizza called LargePizza and // pass "large" as the parameter of the new Pizza. // Next, add a slices property to your LargePizza object. // Set the slices equal to 12. // // Finally, create a child object of LargePizza named // Hawaiian. Add a property called toppings to Hawaiian. // Set the toppings equal to an array with these values: // green peppers, pineapple, canadian bacon // // Send the slices property of Hawaiian to the console // Send Hawaiian's full array property of toppings to // the console also. // 5) With the objects created in Problem #4, // utilize prototype to add a method to the Pizza constructor. // Name the method bake and have it return "Ready in 10 minutes!" // // Create another child object of LargePizza named // TacoPizza. Call the bake method on TacoPizza and // log the result to the console.
In: Computer Science
Please see the java code below and amend it according
to these requirements:
* Do not remove any of the code within the public
interface to the class, only add code to test the additional
functionality
*Limit items in each instance
*Allow the last item entered to be deleted
The CashRegister class should be modified to limit the
number of items that can be added to an instance of the
CashRegister. The limit should be declared as a
constant in such a way that all instances of the
CashRegisterFixedSize have the same limit. The
CashRegisterFixedSize class should also have a new instance method,
undo(), that removes the last item entered into an
instance.
Hints: To implement the additional
functionality required, it is recommended that you use an
array to store each item’s price within the
CashRegisterFixedSize class.
You should adapt the count variable so it
can be used to set the index of the array – this will be used store
each entry, calculate the total price and when removing the last
entered item. The getTotal() method will need to be
modified to calculate the total of all values stored in
the array. A loop construct is ideal for this. When implementing
the undo()method, the value stored in the variable count should be
considered.
The code:
public class CashRegister
{
private int itemCount;
private double totalPrice;
public void addItem (double price)
{
itemCount ++;
totalPrice = totalPrice + price;
}
public void clear ()
{
itemCount = 0;
totalPrice = 0;
}
public double getTotal()
{
return totalPrice;
}
public int getCount()
{
return itemCount;
}
public CashRegister()
{
itemCount = 0;
totalPrice = 0;
}
}
In: Computer Science
In a language of your own choosing, write a computer program that takes as input a decimal (base 10) floating point number, and converts this number into a binary floating-point representation. The binary floating-point representation should consist of 1 bit for the sign of the significand; 8 bits for the biased exponent; and 23 bits for the significand. In addition to program source code, provide a screenshot showing the tasks identified below.
In: Computer Science
In c++, write a program that reads a string consisting of a positive integer or a positive decimal number and converts the number to the numeric format. If the string consists of a decimal number, the program must use a stack to convert the decimal number to the numeric format.
In: Computer Science
Remarks: In all algorithm, always explain how and why they work. If not by a proof, at least by a clear explanation. ALWAYS, analyze the running time complexity of your algorithms. In all algorithms, always try to get the fastest possible. A correct algorithm with slow running time may not get full credit. Do not write a program. Write pseudo codes or explain in words
Question 2: 1. Show how to implement a Queue by a Priority Queue. What is the run time per operation? 2. Show how to implement a Stack using Priority Queue. What is the run time per operation?
In: Computer Science
Remarks: In all algorithm, always explain how and why they work. If not by a proof, at least by a clear explanation. ALWAYS, analyze the running time complexity of your algorithms. In all algorithms, always try to get the fastest possible. A correct algorithm with slow running time may not get full credit. Do not write a program. Write pseudo codes or explain in words
Question 3: Give a data structure that implements a Min-Heap and the command M ax(S) that returns the maximum in the heap. Try and make the last operation as fast as possible.
In: Computer Science
Assume that aa = "11", bb = "22", m = 5 and n = 7. How do the following two statements differ?
System.out.println(aa + bb + m + n);
System.out.println(m + n + aa + bb);
Explain your answers in details. Only clear explanations will be given marks.
In: Computer Science
C++ OOP
•Write a program that evaluates a postfix expression (assume it’s valid) such as
6 2 + 5 * 8 4 / -
•The program should read a postfix expression consisting of digits and operators into a string.
•The algorithm is as follows:
1.While you have not reached the end of the string, read the expression from left to right.
–If the current character is a digit, Push its integer value onto the stack (the integer value of a digit character is its value in the computer’s character set minus the value of '0' in the computer’s character set).
–Otherwise, if the current character is an operator, Pop the two top elements of the stack into variables x and y.
–Calculate y operator x.
–Push the result of the calculation onto the stack.
2.When you reach the end of the string, pop the top value of the stack. This is the result of the postfix expression.
–[Example: In Step 2 above, if the operator is '/', the top of the stack is 2 and the next element in the stack is 8, then pop 2 into x, pop 8 into y, evaluate 8 / 2 and push the result, 4, back onto the stack. This note also applies to operator '–'.]
–The arithmetic operations allowed in an expression are
•+ addition
•– subtraction
•* multiplication
•/ division
•^ exponentiation
•% modulus
•[Note: We assume left-to-right associativity for all operators for the purpose of this exercise.] The stack should be maintained with stack nodes that contain an int data member and a pointer to the next stack node. You may want to provide the following functional capabilities:
a.function evaluatePostfixExpression that evaluates the postfix expression
b.function calculate that evaluates the expression (op1 operator op2)
c.function push that pushes a value onto the stack
d.function pop that pops a value off the stack
e.function isEmpty that determines if the stack is empty
f.function printStack that prints the stack
SAMPLE OUTPUT:
INPUT POSTFIX NOTATION: 23+2*
INFIX NOTATION: (2+3)*2
RESULT: 10
In: Computer Science
Write a python code that calculates π using numpy rand function.
In: Computer Science
The ( ) method will be called if a method is called from within a subclass that overrides a super class method.
In Java the ( ) keyword is used to prevent changes being made to a variable.
The property of ( ) refers to the ability of an object to take on many forms.
In Java, a character constant’s value is its integer value in the ( ) character set.
An interface requires each of the interface’s methods to be ( ) or declared abstract.
The ( ) statement forces an exception object to be generated.
Through the process of ( ) , a programmer hides all but the relevant data about an object in order to reduce complexity and increase efficiency.
Re-implementing an inherited method in a subclass to perform a different task from the parent class is called ( ) .
In a class definition, the special method that is called to create an instance of that class is known as a/an ( ) .
In Java, objects are passed as ( ) addresses.
List of words to choose from
Double, literal, overriding, bytecode, implemented, polymorphism, subclass, catch, protected, throws, constructor, interface, unicode, inheritance, int, overloading, memory, class, string, private, throw, main, extends, final, string literal, runtime, abstraction, prublic, jvm
In: Computer Science
Modify the bellow program by using only system calls to perform the task. These
system calls are open,read,write, and exit .Use text and binary files to test your programs.
#include <stdio.h>
void main(int argc,char **argv)
{
FILE *fp1, *fp2;
char ch, buf[20], *pos;
int n;
pos = buf;
if ((fp1 = fopen(argv[1],"r")) == NULL)
{
puts("File cannot be opened");
exit(1);
}
fp2 = fopen(argv[2], "w");
while ((n = fread(pos, sizeof(char), 20, fp1)) == 20)
{
fwrite(pos, sizeof(char), 20, fp2);
}
fwrite(pos, sizeof(char), n, fp2);
fclose(fp1);
fclose(fp2);
exit(0);
}
In: Computer Science
Convert the simple algebra below into Chomsky Normal Form (CNF), and then create a parse tree showing how the converted grammar could derive: x + y * z
E → E + T | T
T → T * F | F
F → (E) | x | y | z
In: Computer Science
What is an enumerated type in C? Define such a type (called chess_value) to store the
possible values of a chess piece – pawn, rook, knight, bishop, queen and king.
Create a structure called struct piece to store a chess piece. This structure should have two fields, one of which is the value of the piece, and should be of the enumerated type
defined in Q4. The second field is colour, which should be either 1 (white) or 0 (black).
Define an 8x8 array of "struct piece" pointers that can be used to model a chessboard. Each element of the array is pointer to a piece structure, that is either NULL if the square is empty or points to a relevant piece structure if it isn’t. Use malloc to allocate and setup both King pieces on the board. The white king should be placed in row 1, column 5, and the black king in row 8, column 5. You should leave all other squares as NULL.
In: Computer Science
In: Computer Science
Write a C++ program to play the dice game "Craps". Craps is one of the most popular games of chance and is played in casinos and back alleys throughout the world. The rules of the game are straightforward:
A player rolls two dice. Each die has six faces. These faces contain 1, 2, 3, 4, 5, and 6 spots. After the dice have come to rest, the sum of the spots on the two upward faces is calculated. If the sum is 7 or 11 on the first throw, the player wins. If the sum is 2, 3, or 12 on the first throw (called "craps"), the player loses (i.e. the "house" wins). If the sum is 4, 5, 6, 8, 9, or 10 on the first throw, then the sum becomes the player's "point." To win, you must continue rolling the dice until you "make your point." The player loses by rolling a 7 before making the point.
At a minimum, your solution must contain the functions below.
void displayGameRules()
int rollOneDice()
int rollTwoDice()
Write a program that implements craps according to the above rules. Additionally:
In: Computer Science