Please answer full question thoroughly (A- D) showing detailed work. SUBMIT ORIGINAL work and ensure it is correct for thumbs up.
a) Show that an n-element heap has height
b) Show that in any subtree of a max-heap, the root of the subtree contains the largest value occurring anywhere in that subtree.
c) Where in a max-heap might the smallest element reside, assuming that all elements are distinct?
d) Show that, with the array representation for storing an n-element heap, the leaves are the nodes indexed by
In: Computer Science
DROP TABLE registration;
DROP TABLE sections;
DROP TABLE courses;
DROP TABLE students;
DROP TABLE instructors;
CREATE TABLE courses (
cid varchar2(9) NOT NULL,
cname varchar2(50) NOT NULL,
credits number(1) DEFAULT 3,
prereq varchar2(9),
CONSTRAINT pk_courses PRIMARY KEY (cid)
);
INSERT INTO courses VALUES ('IS 201','Java
Programming',3,null);
INSERT INTO courses VALUES ('IS 202','C++ Programming',3,'IS
201');
INSERT INTO courses VALUES ('IS 301','Web Design',3,null);
INSERT INTO courses VALUES ('IS 331','Business
Applications',3,null);
INSERT INTO courses VALUES ('IS 401','Database Design',3,'IS
331');
INSERT INTO courses VALUES ('IS 413','SQL Programming',3,'IS
401');
CREATE TABLE students (
sid char(9) NOT NULL,
lname varchar(30) NOT NULL ,
fname varchar2(30) NOT NULL ,
gender char(1) NOT NULL ,
addr varchar2(50) NOT NULL ,
city varchar2(20) NOT NULL ,
state char(2) NOT NULL ,
zip varchar2(10) NOT NULL ,
phone varchar2(14) NULL ,
birthdate date NULL ,
tuitionRate number(7, 2) NOT NULL ,
creditsEarned number(3) NOT NULL ,
CONSTRAINT pk_students PRIMARY KEY (sid)
);
INSERT INTO students VALUES ('100000001','Lee','George','M','15
Merchant
Street','Honolulu','HI','96818','808-524-3333','01-MAY-1965',5000.00,47);
INSERT INTO students VALUES
('100000002','Yamamoto','Bill','M','3432 Birch
Street','Honolulu','HI','96814','808-522-2212','03-JUN-1958',5000.00,12);
INSERT INTO students VALUES ('100000003','Carver','Hillary','F','22
Aardvark
Avenue','Washington','DC','10101','800-212-3246','23-AUG-1991',5000.00,69);
INSERT INTO students VALUES ('100000004','King','Linda','F','341
Kaapahu
Road','Paauilo','HI','96776',NULL,'01-SEP-1998',4399.00,6);
INSERT INTO students VALUES
('100000005','Rollings','Willie','M','1221 Ala Moana
Blvd','Honolulu','HI','96814',NULL,NULL,4888.00,0);
INSERT INTO students VALUES
('100000006','Alexander','Wanda','F','93-123 Old Mill
Road','Honokaa','HI','96727','808-776-2313','02-OCT-1997',5000.00,99);
INSERT INTO students VALUES ('100000007','Carver','Bill','M','33
Richards
Street','Honolulu','HI','96813',NULL,'22-OCT-1990',5000.00,0);
INSERT INTO students VALUES ('100000008','DeLuz','Bob','M','102
Orleans Ave','San
Francisco','CA','97745','808-555-3324','01-MAR-1998',5000.00,14);
INSERT INTO students VALUES ('100000009','Lee','Lisa','F','45 Fong
Avenue','San
Francisco','CA','97767','808-333-3432','21-APR-1997',5000.00,26);
INSERT INTO students VALUES ('100000010','Garcia','Sherrie','F','2
S.
Beretania','Honolulu','HI','96817','808-663-4453','03-DEC-1997',5000.00,29);
INSERT INTO students VALUES ('100000011','Kamaka','Oscar','M','34
Kapolani
Blvd','Honolulu','HI','96813','808-533-3332','12-FEB-1998',5000.00,0);
CREATE TABLE instructors (
inId char(9) NOT NULL,
iLname varchar2(30) NOT NULL,
iFname varchar2(30) NOT NULL,
rank varchar2(10) NOT NULL,
office varchar2(10) NULL,
phone varchar2(20) NULL,
salary number(8,2) DEFAULT 0,
CONSTRAINT pk_instructors PRIMARY KEY (inID)
);
INSERT INTO instructors VALUES
('200000001','Souza','Edward','Lecturer','LM101','808-533-4241',5000.00);
INSERT INTO instructors VALUES
('200000002','Tenzer','Laurie','Associate','LM102','808-533-4244',5000.00);
INSERT INTO instructors VALUES
('200000003','Otake','Bill','Assistant','MR101','808-533-4247',5800.00);
CREATE TABLE sections (
crn char(4) NOT NULL,
cid varchar2(9) NOT NULL,
section char DEFAULT 'A',
inId char(9) NOT NULL,
days varchar2(10) DEFAULT 'TBA',
time varchar2(16) DEFAULT 'TBA',
room varchar2(10) NULL,
CONSTRAINT pk_sections PRIMARY KEY (crn),
CONSTRAINT fk_inid_sections FOREIGN KEY (inid) REFERENCES
instructors(inid),
CONSTRAINT fk_cid_sections FOREIGN KEY (cid) REFERENCES
courses(cid)
);
INSERT INTO sections VALUES ('1000','IS
201','A','200000003','MWF','08:00 - 08:50','CL100');
INSERT INTO sections VALUES ('1001','IS
201','B','200000003','MWF','09:00 - 09:50','CL100');
INSERT INTO sections VALUES ('1002','IS
201','C','200000001','TTh','08:00 - 09:15','CL102');
INSERT INTO sections VALUES ('1003','IS
301','A','200000002','TTh','09:30 - 10:45','CL340');
INSERT INTO sections VALUES ('1004','IS
301','B','200000002','MWF','09:00 - 09:50','CL340');
INSERT INTO sections VALUES ('1005','IS
413','A','200000001','MWF','09:00 - 09:50','CL230');
CREATE TABLE registration (
crn char(4) NOT NULL,
sid char(9) NOT NULL,
CONSTRAINT pk_registration PRIMARY KEY (crn,sid),
CONSTRAINT fk_crn_registration FOREIGN KEY (crn) references
sections(crn),
CONSTRAINT fk_sid_registration FOREIGN KEY (sid) references
students(sid)
);
INSERT INTO registration VALUES ('1000','100000001');
INSERT INTO registration VALUES ('1003','100000001');
INSERT INTO registration VALUES ('1005','100000001');
INSERT INTO registration VALUES ('1001','100000002');
INSERT INTO registration VALUES ('1004','100000002');
INSERT INTO registration VALUES ('1005','100000003');
INSERT INTO registration VALUES ('1002','100000004');
INSERT INTO registration VALUES ('1003','100000004');
INSERT INTO registration VALUES ('1005','100000004');
INSERT INTO registration VALUES ('1000','100000005');
INSERT INTO registration VALUES ('1003','100000005');
INSERT INTO registration VALUES ('1002','100000008');
INSERT INTO registration VALUES ('1004','100000008');
INSERT INTO registration VALUES ('1002','100000009');
INSERT INTO registration VALUES ('1005','100000009');
INSERT INTO registration VALUES ('1002','100000010');
INSERT INTO registration VALUES ('1005','100000010');
INSERT INTO registration VALUES ('1000','100000011');
INSERT INTO registration VALUES ('1003','100000011');
INSERT INTO registration VALUES ('1005','100000011');
commit;
In: Computer Science
Using Perl;
Part 1:
Allow the user to enter a full name in the “first last”
format
Print just the first name
Print just the last name
Print the name in “last, first” format
Print the entire name out in all capital letters
Use a single print statement to print out the first name on one
line and the last name on
the next line.
There should be 5 print statements generating 6 lines of
output.
Part 2:
Enter a three digit number (such as 316)
Print out the number from the hundreds place (for example, 3 in
316)
Print out the number from the ten’s place (for example, 1 in
316)
Print out the number from the one’s place (for example, 6 in
316)
Print out the original number
All output will be appropriately labeled and on a separate line,
such as “hundreds
place”, “tens place”, and so on.
ALL the numeric values MUST be right justified in the output using
formatted output
All work done for this part MUST treat the information as numeric
values – do not treat
the input as a string or as an array.
There should be 4 print statements generating 4 lines of
output.
In: Computer Science
You have to write a program that will read an array from a file and print if the numbers in the file are right truncatable primes. A right truncatable prime is a prime number, where if you truncate any numbers from the right, the resulting number is still prime. For example, 3797 is a truncatable prime number number because 3797, 379, 37, and 3 are all primes. Input-Output format: Your program will take the file name as input. The first line in the file provides the total number of values in the array. The subsequent lines will contain an integer value. For example a sample input file “file1.txt” is:
3
397
73
47
Your output will be a yes/no for each value in the input file.
$./first file1.txt
no
yes
no
In: Computer Science
Write a set of remote access policies to use computers at college?
In: Computer Science
Lumière: Supporting a Virtual Workspace on the Cloud
Q2: Which organizational factors led to successful cloud adoption at Lumière?
Please write at least 600 words. No plagiarism.
In: Computer Science
C++ code
Output Formatting.
Design and implement a complete C++ program that reads a customer record from the user such as the record has 4 fields (pieces of information) as shown below:
Account Number (integer)
Customer full name (string)
Customer email (string)
Account Balance (double)
The program is expected to print the record in the format shown below:
Account Number : 0000000
Name : full name
Email : customer email
Balance : 000000.00$
For example, if the user enters the following record
1201077
Jonathan I. Maletic
10,000.17
The program outputs:
Account Number : 1201077
Name : Jonathan I. Maletic
Email : [email protected]
Balance : 10,000.17$
In: Computer Science
C++ ONLY!
Implement the find function for the List class. It takes a string as an argument and returns an iterator to a matching node. If no matching node, it returns a null iterator.
#include <iostream>
#include <cstddef>
#include <string>
using Item = std::string;
class List {
private:
class ListNode {
public:
Item item;
ListNode * next;
ListNode(Item i, ListNode *n=nullptr) {
item = i;
next = n;
}
};
ListNode * head;
ListNode * tail;
public:
class iterator {
ListNode *node;
public:
iterator(ListNode *n = nullptr) {
node = n;
}
Item& getItem() { return node->item; }
void next() { node = node->next; }
bool end() { return node==nullptr; }
friend class List;
};
public:
List() {
// list is empty
head = nullptr;
tail = nullptr;
}
bool empty() {
return head==nullptr;
}
// Only declared, here, implemented
// in List.cpp
void append(Item a);
bool remove (Item ©);
void insertAfter(iterator, Item);
void removeAfter(iterator, Item&);
iterator begin() {
return iterator(head);
}
iterator find(Item);
};
void List::append(Item a) {
ListNode *node = new ListNode(a);
if ( head == nullptr ) {
// empty list
head = node;
tail = node;
} else {
tail->next = node;
tail = node;
}
}
bool List::remove(Item ©)
{
if (!empty()) {
copy = head->item;
ListNode *tmp = head->next;
delete head;
head = tmp;
if (head==nullptr)
tail = nullptr;
return true;
}
return false;
}
void List::insertAfter(iterator it, Item item)
{
if (it.node == nullptr)
{
// insert at head
ListNode *tmp = new ListNode(item,head);
// if list is empty, set tail to new node
if (tail==nullptr) {
tail = tmp;
}
// set head to new node
head = tmp;
}
else
{
ListNode *tmp = new
ListNode(item,it.node->next);
it.node->next = tmp;
// could be a new tail, if so update tail
if (tail==it.node) {
tail = tmp;
}
}
}
void List::removeAfter(iterator it, Item& item)
{
// emtpy list or at tail, just return
if (it.node == tail) return;
if (it.node == nullptr)
{
ListNode * tmp = head;
head = head->next;
delete tmp;
if (head==nullptr)
tail = nullptr;
}
else
{
ListNode *tmp = it.node->next;
it.node->next = tmp->next;
delete tmp;
// could be that it.node is the new nullptr
if (it.node->next == nullptr)
tail = it.node;
}
}
List::iterator List::find(Item item)
{
//YOUR CODE HERE
return iterator();
}
int main()
{
List l;
l.append("one");
l.append("two");
l.append("three");
l.append("four");
auto it = l.find("one");
if (!it.end())
std::cout << "Should be one: " << it.getItem() <<
std::endl;
else
std::cout << "Iterator should not have been null." <<
std::endl;
auto no_it = l.find("zero");
if (no_it.end())
std::cout << "As expected, zero not found." <<
std::endl;
else
std::cout << "Oops! should not have found zero." <<
std::endl;
return 0;
}
In: Computer Science
Check a number if the Database. Write MIPS assembly code for the following requirements.
Given the following code for the data segment.
.data
Database: .word 1,2,3,4,5,6,7,8,9,10
Ask user to type in a random integer number using syscall #5. Check if this number is within the database or not, print out "number found!" if the number was foudn in the database, print out "No such number found in database!" if not.
In: Computer Science
Please use Java language in an easy way with comments! Thanks!
Write a static method called "evaluate" that takes a string as a parameter. The string will contain a postfix expression, consisting only of integer operands and the arithmetic operators +, -, *, and / (representing addition, subtraction, multiplication, and division respectively). All operations should be performed as integer operations. You may assume that the input string contains a properly-formed postfix expression. The method should return the integer that the expression evaluates to. The method MUST use a stack to perform the evaluation. Specifically, you should use the Stack class from the java.util package (For this problem, you must write a static "evaluate" method).
Also, in the same file, write a program that prompts the user to enter a postfix expression. Your program should evaluate the expression and output the result. Your program should call the "evaluate" method described above. Here are some examples:
Postfix expression: 1 2 +
Result: 3
Postfix expression: 1 2 + 3 4 - *
Result: -3
Postfix expression: 3 4 5 + + 1 -
Result: 11In: Computer Science
You are going to make an advanced ATM program
When you run the program, it will ask you if you want to:
Either log in or make a new user
Exit
Once I have logged in, I will have 3 balances, credit, checking, and savings. From here it will ask which account to use.
Once the account is picked they can deposit, withdraw, check balance, or log out.
Each time the user performs one of these actions, it will loop back and ask them for another action, until the Logout
(Hint: Make sure they can’t withdraw too much money)
Submission name: Advanced_ATM.py
In: Computer Science
Draw the ER diagram for the following:
• Customer, with attributes Customer ID, Name, Address (Street, City, State, Zip Code), and Telephone
• Location, with attributes Location ID, Address (Street, City, State, Zip Code), and Type (values of Business or Residential)
• Rate, with attributes Rate Class and RatePerKWH After interviews with the owners, you have come up with the following business rules:
• Customers can have one or more locations.
• Each location can have one or more rates, depending on the time of day.
Draw an ERD for this situation and place minimum and maximum cardinalities on the diagram. State any assumptions that you have made.
In: Computer Science
Assignment 3 - Enhanced Employee Hierarchy
For this assignment, you are going to enhance the Employee Hierarchy that you created in Programming Assignment 2 by adding an interface called Compensation with the following two methods:
Create the abstract class CompensationModel which implements the Compensation interface. Create the following classes as subclasses of CompensationModel:
Each of these classes will also have a toString() method to display their compensation information as illustrated in the sample output below.
Modify the Employee class of Assignment 2 to have an instance variable of type CompensationModel instead of CommissionCompensationModel, Make any other necessary changes in the Employee class because of this. Also add the raise (double percent) method to the Employee class which simply calls the raise method of the CompensationModel.
Use the following code in your main function to test your classes, just copy and paste it into your main method:
// Create the four
employees with their compensation models.
CommissionCompensationModel commissionModel = new
CommissionCompensationModel(2000.00, 0.04);
BasePlusCommissionCompensationModel basePlusCommissionModel = new
BasePlusCommissionCompensationModel(2000.00, 0.05, 600.00);
SalariedCompensationModel salariedCompensationModel = new
SalariedCompensationModel(2500.00);
HourlyCompensationModel
hourlyCommissionModel = new HourlyCompensationModel(10.00,
35.0);
Employee employee1 = new
Employee("John", "Smith", "111-11-1111", commissionModel);
Employee employee2 = new
Employee("Sue", "Jones", "222-22-2222",
basePlusCommissionModel);
Employee employee3 = new
Employee("Jim", "Williams", "333-33-3333",
salariedCompensationModel);
Employee employee4 = new
Employee("Nancy", "Johnson", "444-44-4444",
hourlyCommissionModel);
// Print the information
about the four employees.
System.out.println("The
employee information initially.");
System.out.printf("%s%n%s%n%s%n%s%n", employee1, employee2,
employee3, employee4);
System.out.printf("%s%s%s%s%s%8.2f%n%n", "Earnings for ",
employee1.getFirstName(), " ", employee1.getLastName(), ": ",
employee1.earnings());
// Change the
compensation model for the four employees.
CommissionCompensationModel commissionModelNew = new
CommissionCompensationModel(5000.00, 0.04);
BasePlusCommissionCompensationModel basePlusCommissionModelNew =
new BasePlusCommissionCompensationModel(4000.00, 0.05,
800.00);
SalariedCompensationModel salariedCompensationModelNew = new
SalariedCompensationModel(3500.00);
HourlyCompensationModel
hourlyCommissionModeNewl = new HourlyCompensationModel(10.00,
50);
// Set the new
compensation models for the employees.
employee1.setCompensation(basePlusCommissionModelNew);
employee2.setCompensation(commissionModelNew);
employee3.setCompensation(hourlyCommissionModeNewl);
employee4.setCompensation(salariedCompensationModelNew);
// Print out the new
information for the four employees.
System.out.println("The
employee information after changing compensation models.");
System.out.printf("%s%n%s%n%s%n%s%n", employee1, employee2,
employee3, employee4);
// Declare an array of
employees and assign the four employees to it.
Employee[] employees =
new Employee[4];
employees[0] =
employee1;
employees[1] =
employee2;
employees[2] =
employee3;
employees[3] =
employee4;
// Loop thru the array
giving each employee a 2% raise polymorphically;
for (Employee employee :
employees)
{
employee.raise(.02);
}
// Print out their new
earnings.
System.out.println("The
employee information after raises of 2 percent.");
System.out.printf("%s%n%s%n%s%n%s%n", employee1, employee2,
employee3, employee4);
The output from your program should look like the following (there will be additional blank lines in the output which canvas removes for me, unwanted, in this display):
run:
The employee information initially.
John Smith
Social Security Number: 111-11-1111
Commission Compensation with:
Gross Sales of: 2000.00
Commission Rate of: 0.04
Earnings: 80.00
Sue Jones
Social Security Number: 222-22-2222
Base Plus Commission Compensation with:
Gross Sales of: 2000.00
Commission Rate of: 0.05
Base Salary of: 600.00
Earnings: 700.00
Jim Williams
Social Security Number: 333-33-3333
Salaried Compensation with:
Weekly Salary of: 2500.00
Earnings: 2500.00
Nancy Johnson
Social Security Number: 444-44-4444
Hourly Compensation with:
Wage of: 10.00
Hours Worked of:35.00
Earnings: 350.00
Earnings for John Smith: 80.00
The employee information after changing compensation
models.
John Smith
Social Security Number: 111-11-1111
Base Plus Commission Compensation with:
Gross Sales of: 4000.00
Commission Rate of: 0.05
Base Salary of: 800.00
Earnings: 1000.00
Sue Jones
Social Security Number: 222-22-2222
Commission Compensation with:
Gross Sales of: 5000.00
Commission Rate of: 0.04
Earnings: 200.00
Jim Williams
Social Security Number: 333-33-3333
Hourly Compensation with:
Wage of: 10.00
Hours Worked of:50.00
Earnings: 550.00
Nancy Johnson
Social Security Number: 444-44-4444
Salaried Compensation with:
Weekly Salary of: 3500.00
Earnings: 3500.00
The employee information after raises of 2 percent.
John Smith
Social Security Number: 111-11-1111
Base Plus Commission Compensation with:
Gross Sales of: 4000.00
Commission Rate of: 0.05
Base Salary of: 816.00
Earnings: 1016.00
Sue Jones
Social Security Number: 222-22-2222
Commission Compensation with:
Gross Sales of: 5000.00
Commission Rate of: 0.04
Earnings: 204.00
Jim Williams
Social Security Number: 333-33-3333
Hourly Compensation with:
Wage of: 10.20
Hours Worked of:50.00
Earnings: 561.00
Nancy Johnson
Social Security Number: 444-44-4444
Salaried Compensation with:
Weekly Salary of: 3570.00
Earnings: 3570.00
PreviousNext
In: Computer Science
what does this code do?
int encrypt(int character, int shift) {
if(character >= 'a' && character <= 'z') {
return 'a' + (((character-'a'+shift) % 26) + 26) % 26 ;
} else if (character >= 'A' && character <= 'Z')
{
return 'A' + (((character-'A'+shift) % 26) +26) % 26;
} else {
return character;
}
}
int main(int argc, char *argv[]) {
int ch;
int key = 3;
if(argc == 2) {
key = atoi(argv[1]);
}
while((ch = getchar()) != EOF) {
printf("%c", encrypt(ch, key));
}
return 0;
}
how does this work as I am confused about the % used.
In: Computer Science
IN PYTHON
Your task this week is to use loops to both validate user input as well as automate a test suite for your lab solution from last week.
Your program will prompt the user for the cost of their groceries.
Then you are to calculate the value of the coupon to be awarded based on the amount of the grocery bill. Use the table below to determine coupon amounts.
| Money Spent | Coupon Percentage |
| Less than $10 | 0% |
| From $10 to less than $60 | 8% |
| From $60 to less than $150 | 10% |
| From $150 to less than $210 | 12% |
| From $210 or more | 14% |
Display an appropriate result message to the user including both the coupon percentage awarded and the dollar amount of their discount coupon.
Last week we trusted the user to provide valid input. This week you will ensure that valid user input is obtained by implementing an input validation loop.
Last week the test requirement was to prove that your solutions worked for one of the coupon tiers. This week your solution will test each of the possible coupon tiers by using a loop to iterate through all the possible test cases in one program execution.
Testing Requirements
Input Error Checking: Validate user input. Test for both non-numeric, and negative values. If the user does not supply valid input, use a loop to keep the user from advancing until a correct value (a number >= 0) is entered. This technique of using a loop to repeat prompting until correct input is entered is sometimes referred to as 'pigeonholing' the user until he/she gets it right.
Testing Requirements: Using looping control structures, run your program through an entire suite of candidate test data. Include the following test cases: apple, -1, 0, 10, 70, 160, 222. Note: Your program needs to execute all 7 test cases in one one of your program.
Here are some other requirements (remaining from lab 3's spec):
Here are some requirements specific to this expanded lab 4 spec:
4. Run a test suite that validates user input. Do not allow the user to advance until a valid data entry is provided.
5. Your submitted test run should include all the specified test cases: apple, -1, 0, 10, 70, 160, 222. All test cases are to be executed in one program run by using a loop structure.
Here is an example run:
''' Please enter the cost of your groceries: apple Enter cost >= 0: -1 Enter cost >= 0: 0 You win a discount coupon of $0.00. (0% of your purchase) Please enter the cost of your groceries: 10 You win a discount coupon of $0.80. (8% of your purchase) Please enter the cost of your groceries: 70 You win a discount coupon of $7.00. (10% of your purchase) Please enter the cost of your groceries: 160 You win a discount coupon of $19.20. (12% of your purchase) Please enter the cost of your groceries: 222 You win a discount coupon of $31.08. (14% of your purchase) '''
Tips and requirements:
In: Computer Science