Question 12: Please provide tilde (~) for the following expressions:
A) 300N + (3N^5) + (4N^5)*logN
B) (N)^(1/2) + 6 ( NlogN / logN^2 )
C) N^100/ 2^N
D) 1 + 1/N
In: Computer Science
How to compile this code on Visual Studio?
Because it keeps getting me an error when i compile it.
#include<iostream.h>
#include<cio.h>
class Array
{
public:
Array(int=0)//initalise the array with 0 value
Array(const Array &);
~Array();
private:
int size;
int *arr;
bool setvalue(int index,int value);
bool getvalue(int index,int &value);
Array & increment();
int getsize();
void print();
Array &Add(const Array arr);
bool Equal(const Array *arr)const;
Array &removeAt(int index);
Array &insertAt(int index,int value);
}; //End of Array class
void Array::setvalue(int index,int value) //set value for
array
{
i=index;
x=value;
}
void Array::getvalue(int index,int value) //get array element
{
i=index;
x=&value;
}
void Array::getsize() //return the size of the array
{
cout<<arr.size();
}
void Array::print() //display array element
{
cout << x<endl;
}
void Array::Add(int arr[])
{
int i;
for (i = 0; i < 5; i++)
arr[i]++; // this alters values in array in main()
}
void main()
{
Array A;
int arr[5];
cout << "Please Enter " << A.getSize() << " elements for A1 :";
int x;
for (int i = 0; i < A.getSize(); i++)
{
cin >> x;
A.setValue(i, x);
}
Array B(5);
cout << "Please Enter " << B.getSize() << " elements for B : ";
for (int i = 0; i < B.getSize(); i++)
{
cin >> x;
B.setValue(i, x);
}
cout << "Testing copy constrcutor : Array X(A); D = ";
Array X(A);
X.print();
cout << endl;
cout << "I am printing A using getValue assuming that I don't know the size,\nA = ";
int i = 0;
while (A.getValue(i, x))
{
cout << x << " ";
i++;
}
cout << "\nArray C = A.increment(), printing (using A.print()) A and C after the function call\nA = ";
Array C = A.increment();
A.print();
cout << "\nC = ";
C.print();
cout << "\nA.Equal(C) = " << A.Equal(&C) << endl;
cout << "A.Equal(B) = " << A.Equal(&B) << endl;
cout << "Array D = A.Add(B) = ";
Array D = A.Add(B);
D.print();
cout << "\nA is ";
A.print();
cout << "\nB is ";
B.print();
cout << endl;
cout << "Inserting 99 at index 99999 in A, the result is :\n";
A.insertAt(99999, 99);
A.print();
cout << endl;
cout << "Inserting -99 at index -99999 in A, the result is :\n";
A.insertAt(-99999, -99);
A.print();
cout << endl;
cout << "Inserting 7 at index 3 in A, the result is :\n";
A.insertAt(3, 7);
A.print();
cout << endl;
cout << "Deleting the element at index 2 from A, the result is :\n";
A.removeAt(2);
A.print();
cout << endl;
getch();
}
In: Computer Science
Create a program that reports whether each word in a set of words appears in a paragraph. Here are the requirements: a. Ask the user to enter a set of words, one at a time. Use an appropriate prompt to keep asking for words until a blank line is entered. The set of words should be in a dictionary, where the word is the key, and “yes” or “no” is the value. The value represents whether the word appears in the paragraph. As the words are entered, the value should initially be “no”. b. Ask the user to enter a paragraph. Use an appropriate prompt to keep asking for lines/sentences of the paragraph. The lines/sentences should be in a list (of strings). When the user enters a blank line, the paragraph is complete. c. Once the paragraph is entered, check to see if each word in the dictionary is in the paragraph. If it is, then set the value of that key (word) to “yes”. It is sufficient to determine if the word is in the paragraph. You do not need to find all instances, nor count the number of instances. d. Present the results by writing the results of the dictionary using a loop. (Do not simply print the dictionary as a whole.) This should appear as two columns of data, with the key in the first column, and the corresponding value of “yes” or “no” in the second column.
In: Computer Science
In two paragraph, explain the hierarchical structure of a system that you have worked on and how emergence affects the levels in the systems hierarchy. Provide details and apply what you learned here to discuss what (if any) changes you would have done, if you have to do it all over again.
In: Computer Science
Describe how DDoS attacks may be mounted against TCP and UDP services. In what way will being connection oriented be different for TCP and UDP?
In: Computer Science
Using the below given ASCII table (lowercase letters) convert the sentence “welcome to cci college” into binary values.
a - 97 |
b - 98 |
c - 99 |
d - 100 |
e - 101 |
f - 102 |
g - 103 |
h - 104 |
i - 105 |
j - 106 |
k - 107 |
l - 108 |
m - 109 |
n - 110 |
o - 111 |
p - 112 |
q - 113 |
r -114 |
s -115 |
t - 116 |
u - 117 |
v - 118 |
w - 119 |
x - 120 |
y - 121 |
z - 122 |
Space - 32 |
In: Computer Science
Write LMC assembly code that prints the minimum of two numbers.
HINT: use and extend the table below for your solution.
Mailbox |
Mnemonic |
Code |
Instruction description |
In: Computer Science
Add The following methods to the LinkedQueue class and create a test driver for each to show they work correctly. In order to practice your linked list coding skills, code each of these methods by accessing the internal variables of the LinkedQueue, not by calling the previously defined public methods of the class. a. String toString () creates and returns a string that correctly represents the current queue. Such a method could prove useful for testing and debugging the class and for testing and debugging applications tha
t use the class. Assue each queued element already provides its own reasonable toString method. b. void remove (int count) removes the front count elements from the queue; throws QueueUnderflowException if less than count elements are in the queue. c. boolean swapStart () returns false if less than two elements are in the queue, otherwise reverse the order of the front two elements in the queue and returns true. d. boolean swapEnds() returns false if there are less than two elements in the queue, otherwise swaps the first and last elements of the queue and returns true.
LinkedQueue.java:
package ch04.queues;
import support.LLNode;
public class LinkedQueue<T> implements QueueInterface<T> {
protected LLNode<T> front;
protected LLNode<T> rear;
protected int numElements = 0;
public LinkedQueue(){
front = null; rear = null;
}
public void enqueue(T element){
LLNode<T> newNode = new LLNode<T>(element);
if (rear == null)
front = newNode;
else
rear.setLink(newNode);
rear = newNode;
numElements++;
}
public T dequeue(){
if (isEmpty())
throw new QueueUnderflowException("Dequeue attempted on empty queue.");
else{
T element;
element = front.getInfo();
front = front.getLink();
if (front == null)
rear = null;
numElements--;
return element;
}
}
}
LLNode.java:
//----------------------------------------------------------------------------
// LLNode.java by Dale/Joyce/Weems Chapter 2
//
// Implements <T> nodes for a Linked List.
//----------------------------------------------------------------------------
package support;
public class LLNode<T>{
private LLNode<T> link;
private T info;
public LLNode(T info)
{
this.info = info;
link = null;
}
public void setInfo(T info){
// Sets info of this LLNode.
this.info = info;
}
public T getInfo()
// Returns info of this LLONode.
{
return info;
}
public void setLink(LLNode<T> link)
// Sets link of this LLNode.
{
this.link = link;
}
public LLNode<T> getLink()
// Returns link of this LLNode.
{
return link;
}
}
QueueInterface.java
package ch04.queues;
public interface QueueInterface<T> {
void enqueue(T element) throws QueueOverflowException1;
T dequeue() throws QueueUnderflowException;
boolean isFull();
boolean isEmpty();
int size();
}
In: Computer Science
use c++
Parking charge application: A parking garage charges a $20.00 minimum fee to park for up to 3 hours. The garage charges an additional $5.00 per hour for hour or part thereof in excess of 3 hours. The maximum charge for any given 24-hour period is $50.00. Assume that no car parks for longer than 24 hours at a time. Write a program that calculates and prints the parking charge for each of 3 customers who parked their cars in this garage yesterday. You should enter the hours parked for each customer. Your program should save the result in a array of Customer. The class customer is the following:
class customer{ string plate; float hour; float fee; }
Your program should use the function calculateCharges to determine the fee for each customer. You should print the result for the 3 customers in the following format:
Plate Hours Charge
132AAC 1.5 20.00
236URT 4.0 25.00
390ROP 24.0 50.00
TOTAL 29.5 95.00
In doing this question make sure to keep the array of customer as global variable.
In: Computer Science
You must implement the delete method. Below are the requirements:
• The delete method takes a Price as an argument and removes the Price from the queue if it is present. (If the Price was not present, the method does nothing).
• The method returns true if the Price was deleted and false otherwise.
• The method must run in logarithmic time. This is a key requirement. Solutions that are linear or worse will not receive credit. (You may assume that the running time for TreeMap’s operations are similar to the LLRB class in the book. You can also read the API for TreeMap to see what the running times for the various methods are.)
• You may not modify the function headers of any of the functions already present.
• The only field you may add to the PriceQueue class is a single TreeMap. (See Java’s API for the TreeMap class. It is basically the same as the book’s RedBlackBST class)
• You may not change or remove the package declaration at the top of the files.
• The rest of the queue should continue to behave as expected. In particular, the remaining Prices should still come out of the queue in FIFO order.
• The enqueue and dequeue methods should also run in logarithmic time while the size, peek, and isEmpty methods continue to run in constant time. Note, the enqueue method given to you runs in linear time because it scans the list to see if the price being added is already in the queue. You will need to replace this with a different way of checking that doesn’t take linear time. (Hint: Use the map!) • You will need to make changes to the Price class as well, but you can only add new functionality. You may not make any changes to the functions that are already there and they must continue to behave as before.
//// PRICE JAVA /////
public class Price {
private int dollars;
private int cents;
public Price(int dollars, int cents) {
if (dollars < 0 || cents < 0 || cents > 99)
throw new IllegalArgumentException();
this.dollars = dollars;
this.cents = cents;
}
public String toString() {
String answer = "$" + dollars + ".";
if (cents < 10)
answer = answer + "0" + cents;
else
answer = answer + cents;
return answer;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Price other = (Price) obj;
if (cents != other.cents)
return false;
if (dollars != other.dollars)
return false;
return true;
}
}
/////// PRICE QUEUE //////
import java.util.Iterator;
import java.util.NoSuchElementException;
public class PriceQueue implements Iterable<Price> {
private Node first; // beginning of queue
private Node last; // end of queue
private int n; // number of elements on queue
// TODO - Add a TreeMap that maps prices to the node before that
price in the queue
// and maps the first price (nothing before it) to null
//
// NOTE: You will need to modify preexisting methods to maintain
the invariant on the TreeMap
// helper linked list class
private static class Node {
private Price price;
private Node next;
}
/**
* Initializes an empty queue.
*/
public PriceQueue() {
first = null;
last = null;
n = 0;
}
/**
* Returns true if this queue is empty.
*
* @return {@code true} if this queue is empty; {@code false}
otherwise
*/
public boolean isEmpty() {
return first == null;
}
/**
* Returns the number of Prices in this queue.
*
* @return the number of Prices in this queue
*/
public int size() {
return n;
}
/**
* Returns the Price least recently added to this queue.
*
* @return the Price least recently added to this queue
* @throws NoSuchElementException if this queue is empty
*/
public Price peek() {
if (isEmpty()) throw new NoSuchElementException("Queue
underflow");
return first.price;
}
/**
* Adds the Price to this queue if it is not already present,
* otherwise it throws an IllegalArugmentException.
*
* @param price the Price to add
*
* @throws IllegalArgumentException if price is already in the
queue.
*/
public void enqueue(Price price) {
for(Price p : this)
if (p.equals(price))
throw new
IllegalArgumentException();
Node oldlast = last;
last = new Node();
last.price = price;
last.next = null;
if (isEmpty()) first = last;
else oldlast.next = last;
n++;
}
/**
* Removes and returns the Price on this queue that was least
recently added.
*
* @return the Price on this queue that was least recently
added
* @throws NoSuchElementException if this queue is empty
*/
public Price dequeue() {
if (isEmpty()) throw new NoSuchElementException("Queue
underflow");
Price price = first.price;
first = first.next;
n--;
if (isEmpty()) last = null; // to avoid loitering
return price;
}
/**
* Deletes a Price from the queue if it was present.
* @param price the Price to be deleted.
* @return {@code true} if the Price was deleted and {@code false}
otherwise
*/
public boolean delete(Price price) {
// TODO implelment me!!!
// Make sure the running time is no worse than
logrithmic!!!
// You will want to use Java's TreeMap class to map
Prices to the node
// that precedes the Price in the queue
throw new RuntimeException("Not
Implemented!!!");
}
/**
* Returns a string representation of this queue.
*
* @return the sequence of Prices in FIFO order, separated by
spaces
*/
public String toString() {
StringBuilder s = new StringBuilder();
for (Price price : this) {
s.append(price);
s.append(' ');
}
return s.toString();
}
/**
* Returns an iterator that iterates over the Prices in this queue
in FIFO order.
*
* @return an iterator that iterates over the Prices in this queue
in FIFO order
*/
public Iterator<Price> iterator() {
return new PriceListIterator(first);
}
// an iterator, doesn't implement remove() since it's
optional
private class PriceListIterator implements Iterator<Price>
{
private Node current;
public PriceListIterator(Node first) {
current = first;
}
public boolean hasNext() { return current != null; }
public void remove() { throw new UnsupportedOperationException();
}
public Price next() {
if (!hasNext()) throw new NoSuchElementException();
Price price = current.price;
current = current.next;
return price;
}
}
}
In: Computer Science
Define a class Product to hold the name and price of items in a grocery store. Encapsulate the fields and provide getters and setters. Create an application for a grocery store to calculate the total bill for each customer. Such program will read a list of products purchased and the quantity of each item. Each line in the bill consists of: ProductName ProductPrice Quantity/Weight
The list of items will be terminated by the “end” keyword. The data will look like this: Juice 10 7 Apples 3 3.5 Cereal 5 3 Gum 1 15 Pears 3.5 5 ends The program should read the data from the console, calculate the total price of the items purchased and print it out. For each line create an object of class Product and initialize its fields in the constructor. Then calculate the price for given quantity using the getter of the object.
In: Computer Science
use c++
Every programmer must grapple with certain classic
problems,
and the Towers problem is one of the most famous of these. Legend
has it that
in a temple in the Far East, priests are attempting to move a stack
of disks from one peg to another.
The initial stack had 64 disks threaded onto one peg and arranged
from bottom to top by decreasing
size. The priests are attempting to move the stack from this peg to
a second peg under the constraints
that exactly one disk is moved at a time, and at no time may a
larger disk be placed above a smaller
disk. A third peg is available for temporarily holding the disks.
Supposedly the world will end when
the priests complete their task, so there is little incentive for
us to facilitate their efforts.
Let’s assume that the priests are attempting to move the disks from
peg 1 to peg 3. We wish to
develop an algorithm that will print the precise sequence of
disk-to-disk peg transfers.
If we were to approach this problem with conventional methods, we’d
rapidly find ourselves
hopelessly knotted up in managing the disks. Instead, if we attack
the problem with recursion in
mind, it immediately becomes tractable. Moving n disks can be
viewed in terms of moving only
n – 1 disks (and hence the recursion) as follows:
a) Move n – 1 disks from peg 1 to peg 2, using peg 3 as a temporary
holding area.
b) Move the last disk (the largest) from peg 1 to peg 3.
c) Move the n – 1 disks from peg 2 to peg 3, using peg 1 as a
temporary holding area.
The process ends when the last task involves moving n = 1 disk,
i.e., the base case. This is
accomplished by trivially moving the disk without the need for a
temporary holding area.
Write a program to solve the Towers of Hanoi problem. Use a
recursive function with four
parameters:
a) The number of disks to be moved
b) The peg on which these disks are initially threaded
c) The peg to which this stack of disks is to be moved
d) The peg to be used as a temporary holding area
Your program should print the precise instructions it will take to
move the disks from the
starting peg to the destination peg. For example, to move a stack
of three disks from peg 1 to peg 3,
your program should print the following series of moves:
1 → 3 (This means move one disk from peg 1 to peg 3.)
1 → 2
3 → 2
1 → 3
2 → 1
2 → 3
1 → 3*/
In: Computer Science
Fundamentals of Big Data Analytics
• Critical Success Factors for Big Data Analytics.
• Enablers of Big Data Analytics
• Challenges of Big Data Analytics
• Business Problems Addressed by Big Data Analytics
Top 5 Investment Bank Achieves Single Source of the Truth
Questions for Discussion
4. How can Big Data benefit large-scale trading banks?
5. How did MarkLogic’s infrastructure help ease the leveraging of
Big Data?
6. What were the challenges, the proposed solution, and the
obtained results?
In: Computer Science
Binary Search Trees with Lazy Deletion
Implement binary search tree class with lazy deletion that has TreeNode as nested class in Java.
Design the class, TreeNode to have following class variables:
int key; // All Keys are in the range 1 to 99
TreeNode leftChild;
TreeNode rightChild;
boolean deleted;
Your program method must have routines to do the following operations.
1. insert
//Should insert a new element to a leaf node. If new element is aduplicatethen do nothing. If the new element is previously deleted one, then do not add other copy just mark the previous deleted as valid now
2. delete
//Should not remove the element from the tree. It should just mark the element as deleted.
Lazy deletion, meaning you will not be deleting the node but only mark it for deletion. It is ok to display the deleted node put an * before it to indicate it is deleted.
3. findMin
//Should return the minimum element, butif it is marked deleted return appropriate minimum
4. findMax
//Should return the maximumelement, butif it is marked deleted return appropriate maximum
5. contains
//Should return true if a particular element is in the tree and is not marked as deleted
6. In order tree Traversal
//Should print the in order traversal of the tree. Indicating with * symbol for elements that are marked deleted
7. Height ( returns the height of the tree)
//Return the height of the tree, count all the elements even the ones that are marked as deleted
8. No Of nodes ( returns number of nodes + number of deleted nodes)
//Return and print size of the tree, count all the elements even the ones that are marked as deleted. And also return the number of deleted elements.
The Java program should prompt user with options to do one of the above routines.
In: Computer Science
A programmer that you work with, Peter, is a jerk. He is responsible for an array that is a key part of an important program and he maintains a sum of the array value.He won't give you access to this array; however, your boss has told you that you need to get input from the user and then place it into the array.Each evening Peter will scan the code and remove any illegal references to his array.
Using pointers, access Peter's array without him knowing it and place three values that you got from the user ONLY AT POSITIONS 3, 6, and 9. Recalculate the sum value and update it.
STARTER CODE BELOW:
#include <stdio.h>
#include
<stdlib.h>
int main(){
int petersArray[10] = {100,200,300,400,500,600,700,800,900,1000}; i
int petersArraySum = 0;
printf("Peter's Array:\n");
for (int loop = 0; loop < 10; loop++) {
printf("%d ",petersArray[loop]);
petersArraySum += petersArray[loop];
}
printf("\n");
printf("Peter's Array Sum: %d\n\n",petersArraySum);
return 0;
In: Computer Science