Write code to reverse the order of elements on a stack S.c++
ii. Using one additional queue.
iii. using an additional stack and a non array variable
c++ .
In: Computer Science
Suppose we are given two skip lists, one storing a set A of m keys, and the other storing a set B of n keys. Describe and analyze an algorithm to merge these into a single skip list storing the set A ∪ B in O(n + m) expected time. Do not assume that every key in A is smaller than every key in B; the two sets could be arbitrarily intermixed.
In: Computer Science
Write a program that uses a loop to read 10 integers from the user. Each integer will be in the range from -100 to 100. After all 10 integers have been read, output the largest and smallest values that were entered, each on its own line in that order.
Avoiding using the max or min functions from Python, and definitely use a loop to read the integers instead of 10 input statements.
In: Computer Science
Given a BST and a sum, write pseudo code to determine if the tree has a root- to-leaf path such that adding up all the values along the path equals the given sum. Given the below BST and sum = 49, the array is (8, 4, 10, 1, 0, 3, 9, 15, 16). Return true, as there exist a root-to-leaf path 8− > 10− > 15− > 16 which sum is 49.
In: Computer Science
Write a class Store which includes the attributes: store name and sales tax rate. Write another class encapsulating a Book Store, which inherits from Store. A Book Store has the following additional attributes: how many books are sold every year and the average price per book.
Code the constructor, accessors, mutators, toString and equals method of the super class Store and the subclass Book Store; In the Book Store class, also code a method returning the average taxes per year.
You should create a test class which creates 1 Store object and 2 Book Store objects, then calls your set methods, get methods, toString and equals methods and average taxes per year for the Book Store objects..
In: Computer Science
What are software requirement tools? What are the two major categories of these requirement tools? Write some key features that must be considered while choosing the requirement tools? Also, give some real-world examples for some of these tools.
NO HANDWRITING PLEASE... THANK YOU.
In: Computer Science
Python - You are given a sorted (from smallest to largest) array A of n distinct integers which can be positive, negative or zero. Design the fastest algorithm you can for deciding if there is an index i such that A[i] = i.
In: Computer Science
• P8.2 Simulate a tally counter that can be used to admit a limited number of people. First, the limit is set with a call public void setLimit(int maximum) If the count button was clicked more often than the limit, simulate an alarm by printing out a message “Limit exceeded”.
In: Computer Science
This much like the single linked list assignment. I am giving you the majority of the code and left a couple of functions for you to complete. I had intended to try to do some video clips of my own lecture but I am not going to have time to get those completed (at least not at a quality I want). You might take a look at these sites for more help outside just zyBooks.
#include <stdio.h>
#include <stdlib.h>
struct node
{
struct node *prev;
int info;
struct node *next;
};
struct node *createList(struct node *start);
void displayList(struct node *start);
struct node *insertInEmptyList(struct node *start, int data);
struct node *insertInBeginning(struct node *start, int data);
void insertAtEnd(struct node *start, int data);
void insertAfter(struct node *start, int data, int x);
struct node *insertBefore(struct node *start, int data, int x);
struct node *deleteNode(struct node *start, int data);
struct node *reverseList(struct node *start);
main()
{
int choice, data, x;
struct node *start=NULL;
start=createList(start);
while(1)
{
printf("\n");
printf("1.Display List\n");
printf("2.Insert in empty list\n");
printf("3.Insert a node in beginning of the list\n");
printf("4.Insert a node at the end of the list\n");
printf("5.Insert a node after a specified node\n");
printf("6.Insert a node before a specified node\n");
printf("7.Delete a node\n");
printf("8.Reverse the list\n");
printf("9.Quit\n");
printf("Enter your choice : ");
scanf("%d", &choice);
if (choice == 9)
break;
switch(choice)
{
case 1:
displayList(start);
break;
case 2:
printf("Enter the element to be inserted : ");
scanf("%d", &data);
start=insertInEmptyList(start,data);
break;
case 3:
printf("Enter the element to be inserted : ");
scanf("%d", &data);
start=insertInBeginning(start, data);
break;
case 4:
printf("Enter the element to be inserted : ");
scanf("%d", &data);
insertAtEnd(start, data);
break;
case 5:
printf("Enter the element to be insert : ");
scanf("%d", &data);
printf("Enter the element after which to insert : ");
scanf("%d", &x);
insertAfter(start, data, x);
break;
case 6:
printf("Enter the element to be inserted : ");
scanf("%d", &data);
printf("Enter the element before which to insrt : ");
scanf("%d", &x);
start=insertBefore(start, data, x);
break;
case 7:
printf("Enter the element to be deleted : ");
scanf("%d", &data);
start=deleteNode(start, data);
break;
case 8:
start=reverseList(start);
break;
default:
printf("Wrong choice\n");
} //end of switch
} //end of while
} //end of main
struct node *createList(struct node *start)
{
int i, n, data;
printf("Enter the number of nodes : ");
scanf("%d", &n);
start=NULL;
if (n==0)
return start;
printf("Enter the first element to be inserted : ");
scanf("%d", &data);
start=insertInEmptyList(start, data);
for (i=2; i<=n; i++)
{
printf("Enter the next element to be inserted : ");
scanf("%d", &data);
insertAtEnd(start, data);
}
return start;
}//End of createList()
void displayList(struct node *start)
{
struct node *p;
if (start==NULL)
{
printf("List is empty\n");
return;
}
p=start;
printf("List is :\n");
while(p!=NULL)
{
printf("%d ", p->info);
p=p->next;
}
printf("\n");
} //End of displayList()
struct node *insertInEmptyList(struct node *start, int data)
{
**********************************
*** COMPLETE THE REQUIRED CODE ***
**********************************
}//End of insertInEmptyList()
struct node *insertInBeginning(struct node *start, int data)
{
struct node *temp;
temp = (struct node *)malloc(sizeof(struct node));
temp->info=data;
temp->prev=NULL;
temp->next=start;
start->prev=temp;
start=temp;
}//End of insertInBeginng()
void insertAtEnd(struct node *start, int data)
{
**********************************
*** COMPLETE THE REQUIRED CODE ***
**********************************
}//End of insertAtEnd()
void insertAfter(struct node *start, int data, int x)
{
struct node *temp, *p;
temp=(struct node*)malloc(sizeof(struct node));
temp->info=data;
p=start;
while(p!=NULL)
{
if(p->info==x)
break;
p=p->next;
}
if(p==NULL)
printf("%d not present in the list\n", x);
else
{
temp->prev=p;
temp->next=p->next;
if(p->next!=NULL)
p->next->prev=temp; //should not be done when p points to last node
p->next=temp;
}
}//End of insertAfter()
struct node *insertBefore(struct node *start, int data, int x)
{
struct node *temp, *p;
if(start==NULL)
{
printf("List is empty\n");
return start;
}
if(start->info==x)
{
temp = (struct node *)malloc(sizeof(struct node));
temp->info=data;
temp->prev=NULL;
temp->next=start;
start->prev=temp;
start=temp;
return start;
}
p=start;
while(p!=NULL)
{
if(p->info==x)
break;
p=p->next;
}
if(p==NULL)
printf("%d not present in the list\n", x);
else
{
temp=(struct node *)malloc(sizeof(struct node));
temp->info=data;
temp->prev=p->prev;
temp->next = p;
p->prev->next=temp;
p->prev=temp;
}
return start;
}//End of insertBefore()
struct node *deleteNode(struct node *start, int x)
{
struct node *temp;
if(start==NULL)
{
printf("List is empty\n");
return start;
}
if(start->next==NULL) //only one node in the list
{
if(start->info==x)
{
temp=start;
start=NULL;
free(temp);
}
else
printf("Element %d not found\n", x);
return start;
}
//Deletion of first node
if(start->info==x)
{
temp=start;
start=start->next;
start->prev=NULL;
free(temp);
return start;
}
temp=start->next;
while(temp->next!=NULL)
{
if(temp->info==x)
break;
temp=temp->next;
}
if(temp->next!=NULL) //node to be deleted is in between
{
temp->prev->next=temp->next;
temp->next->prev=temp->next;
free(temp);
}
else //temp points to last node
{
if(temp->info==x) //node to be deleted is last node
{
temp->prev->next=NULL;
free(temp);
}
else
printf("Element %d not fount\n", x);
}
return start;
}
struct node *reverseList(struct node*start)
{
struct node *p1, *p2;
if(start==NULL)
return;
p1=start;
p2=p1->next;
p1->next=NULL;
p1->prev=p2;
while(p2!=NULL)
{
p2->prev=p2->next;
p2->next=p1;
p1=p2;
p2=p2->prev;
}
start=p1;
return start;
} //End of reverseList()
In: Computer Science
Critical Thinking 4-6: Digital Certificate Costs
Use the Internet to research the costs of the different types of digital certificates: domain validation, EV, wildcard, SAM, machine, code signing, and email. Look up at least three different providers of each, and create a table listing the type of certificate, the costs, and the length of time the certificate is valid.
In: Computer Science
convert the binary number(base 2) To Octal (base 8) to
decimal (base 10)
a. 101
b. 1001
c. 101010
d.1101101
convert the number to the other base
a. 253 base 10 to base 8
b. 98 base 10 to base 3
C. 1340 base 10 to base 16
D. AB Base 16 to base 8
E. 111010 base 2 to base 16
F. 1010101 base 2 to base 6
g. 69 base 10 to base 2
h . 1023 base 10 to base 2
add and show work
a. 11001(base 2)
+ 10101(base 2)
b. 743(base 8)
+ 635(base 8)
c. 98(base 16)
+ 46(base 16)
In: Computer Science
Hadoop decided to abandon Java serialization, instead decided to implement their own serialization mechanism using Writable and WritableComparable interface. If you were the lead architect of Hadoop, would you have taken the same approach? Why? Why not?
In: Computer Science
C++ Program - Arrays-
Include the following
header files in your program: string,
iomanip, iostream
Suggestion: code steps 1 thru 4 then test then add
requirement 5, then test, then add 6, then test etc.
Add comments to display assignment //step 1., //step 2. etc. This program is to have no programmer created functions. Just do everything in main and make sure you comment each step so I can grade more easily. Also, this program will be expanded in Chapter 9 to use pointers.
Create a program which
has:
1. The following arrays created:
a. an array of double with 5 elements, dArr
b. an array of long, lArr, with 7 elements and
initialized at the time of creation with the values
100000, 134567, 123456, 9, -234567, -1, 123489
c. a 2 dimensional array of integer, with 3 rows and 5
columns, iArr.
d. an array of char with your name initialized in it. Big enough
for 30 typable characters, sName.
2. define 3 variables, , cnt1 and
cnt2 (short data types) as general purpose
counters and a long double total
3. define 1 long variable called highest
4. a for loop to put a random number into each of
the elements of the array of double, dArr. Use rand() and seed a
random starting point with srand(). Use a for loop to display all
of the values in dArr.
5. another for loop to add up the array of double,
dArr, into the variable
total
6. one cout to print the total and another cout to
print the average of the double array,
dArr.
7. a for loop similar to the following for the long array,
lArr:
for ( cnt1 = 1, highest = lArr[0] ; cnt1 < 7 ; cnt1++ )
{
//logic to compare each array element, starting with lArr[1], with
highest
//replace highest if the value in lArr[cnt] is higher than the
value in variable highest
}
8. a cout to print
highest as derived in the above
code
9. a for loop to put a random number, each with a value no lower
than 1 and no higher than 53, into each element of
iArr, the array of integer, seed the random
generator with srand( (unsigned) time(NULL)). Only have to run
srand once…. Use the modulo operator similar to the way you did
with dice rolls in Project 2.
10. a separate loop to print iArr with 3 rows on
your screen. Each row has 5 numbers. Use setw to control the width
of each column. See Chapter 3 for an example of a program using
setw. Print row by row.
11. a loop to print the 2 dimensional array, iArr,
so that all 3 numbers in column 0 are printed and then on the next
line all 3 numbers in column 1, etc. thru column 4. Print column by
column.
12. Use cin.getline( ...... ) to type another name into the
variable sName.
13. Print the ascii value of each character in the char array, 1
per line. Use a while loop and look for the '\0'
as a signal to end.
14. make the array of char, sName, have the name
"Albert Einstein" in it. You must use strcpy_s function.
15. print the ascii value of the 12th character of the string
sName
In: Computer Science
Create a class Employee. Your Employee class should include the following attributes:
First name (string)
Last name (string)
Employee id (string)
Employee home street address (string)
Employee home city (string)
Employee home state (string)
Write a constructor to initialize the above Employee attributes.
Create another class HourlyEmployee that inherits from the Employee class. HourEmployee must use the inherited parent class variables and add in HourlyRate and HoursWorked. Your HourEmployee class should contain a constructor that calls the constructor from the Employee class to initialize the common instance variables but also initializes the HourlyRate and HoursWorked. Add an earnings method to HourlyEmployee to calculate the earnings for a week. Note that earnings is hourly rate * hours worked.
Create a test class that prompts the user for the information for two hourly employees, creates the 2 two hourly employees objects, calls the earnings method then displays the attributes and earnings for each of the two hourly.
In: Computer Science
In Java
The Order class should have: Seven instance variables: the
order number (an int), the Customer who made the order, the
Restaurant that receives the order, the FoodApp through which the
order was placed, a list of food items ordered (stored as an array
of FoodItem), the total number of items ordered (an int), and the
total price of the order (a double). A class constant to set the
maximum number of items that can be ordered (an int). Set it to 10.
A constructor that accepts three parameters, the Customer, the
Restaurant and the FoodApp, and initializes the corresponding
instances variables. The array of FoodItems will be a partially
filled array. It should be initialized according to the maximum
number of items that can be ordered, and be empty at the beginning.
The total number of items ordered should be initialized
accordingly. The total price shall be initialized to 0. The order
number shall have 6 digits, and start with a 9. Every order should
have a distinct order number, starting from 900001, then 900002,
then 900003 and so on. You will need to add either an instance
variable or a class variable to accomplish this (choose wisely).
An addToOrder(FoodItem) method that adds the FoodItem received as a
parameter to the FoodItem array, only if it is available (i.e. not
sold out) and if there is space left in the array. If the FoodItem
was added, the method returns true (it returns false otherwise).
You can assume that the FoodItem belongs to the restaurant’s menu
(no need to check if it’s on the menu). Don’t forget to update
here: the amount in stock for the FoodItem (decrement by 1), the
total price of the order, and the total number of items ordered.
A toString method that returns a String containing the FoodApp
name, the order #, the customer name, the Restaurant name, the list
of items ordered and the total price (formatting it exactly as
shown in the example below). You will need to add some accessors in
the previous classes (aka get methods) to get only the name of the
Customer, FoodApp and Restaurant, instead of the full String
representation of those.
=============================================
public class FoodItem {
/*Four instance variables: a name (a String), a cost (a double), a selling price (a double), and the number of
items available in stock for selling (an int)*/
String name;
double cost;
double price;
int numberOfItem;
/* A constructor that takes four parameters, in the above order, which are used to initialize the four instance
variables.*/
public FoodItem(String name, double cost, double price, int numberOfItem){
this.name = name;
this.cost = cost;
this.price = price;
this.numberOfItem = numberOfItem;
}
/* A method isAvailable that checks if there are items available for selling (returns false is no items are available,
true otherwise)*/
public boolean isAvailable(int numberOfItem){
if ( numberOfItem <= 0)
return false;
else
return true;
}
/* A toString method which returns a String containing the name of the food item and the selling price. If the
item is not available, add “(SOLD OUT)” next to the price, making use of the isAvailable method. Follow the
format shown in the example output below.*/
@Override
public String toString(){
String update ="";
if ( this.numberOfItem <= 0)
update =" (SOLD OUT)";
return"- "+this.name +"\n$ "+ this.price + update;
}
// A method setSellingPrice that takes a new price as a parameter, and updates the selling price instance variable.
public void setSellingPrice( double TheSellingPrice){
price = TheSellingPrice;
}
// A method decrementStock that decrements the number of items in stock by 1.
public int decrementStock(int x){
return numberOfItem -= x;
}
// A method increaseStock that takes an amount of additional stock as a parameter, and adds it to the existing stock available for selling. */
public int increaseStock(int x){
return numberOfItem += x;
}
}//FoodItem
In: Computer Science