c++
LINEAR SEARCH ARRAYS OF OBJECTS
Use the Item class defined in question #12.
1. (3 pts) Declare an array of 1024 Item objects. Assuming the array is now sorted by Value (price per item * quantity).
2. Write a function (with both declaration/prototype (3 pts) and definition (6 pts) ) that takes an array of Item objects, an integer as array size and two references to integers that represents the start_index and end_index of Item object elements whose Values are 50.0.
The function's implementation should be:
An example of such array of Items will be the below:
index 0 1 2 3 4 5 6 7 8 9 ........
Value 21.4 23.3 50.0 50.0 50.0 67.5 88.0 88.3 95.2 141.5 ....... (Note that the array is sorted)
In this example your function must assign 2 to start_index and 4 to end_index.
#12
This question has two parts:
Part 1: Define an Item class with the following specifications:
NOTE: you must declare and define the class separately. Include the definitions of constructors/destructor and member functions in class declaration will result in 50% point deduction.
NOTE: The class definition must follow Google naming convention for class name, member data names and member function names (do not use camelCase convention)
Part 2: (5 pts)
Instantiate two Item objects: one using the default constructor and the other using the non-default constructor (description: "Toys", quantity: 100, price per item: 29.95).
Invoke the company name (static data).
Set the price per item of the default object to the non-default object's price per item.
Output the Value of the non-default object.
Increment the default-object's quantity to 9999.
In: Computer Science
Hey, how do I create a function which receives one argument (string). The function would count and return the number of alphanumeric characters found in that string. function('abc 5} =+;d 9') // returns 6 in JavaScript?
In: Computer Science
(python please)
The Cache Directory (Hash Table):The class Cache()is the data structure you will use to store the three other caches (L1, L2, L3). It stores anarray of 3 CacheLists, which are the linked list implementations of the cache (which will be explained later). Each CacheList has been already initialized to a size of 200. Do not change this. There are 3 functions you must implement yourself:
•def hashFunc(self, contentHeader)oThis function determines which cache level your content should go in. Create a hash function that sums the ASCII values of each content header, takes the modulus of that sum with the size of the Cache hash table, and accordingly assigns an index for that content –corresponding to the L1, L2, or L3 cache. So, for example, let’sassume the header “Content-Type: 2”sumsto an ASCII value of 1334. 1334% 3 = 2. So, that content would go in the L3cache. You should notice a very obvious pattern in which contentheaders correspond to which caches. The hash function should be used by your insert and retrieveContent functions.
•def insert(self, content, evictionPolicy)oOnce a content object is created, call the cache directory’s insert function to insert it into the proper cache. This function should call the linked list’s implementation of the insert function to actually insert into the cache itself. The eviction policywill be a string –either ‘lru’or ‘mru’. These eviction policies will be explained later. oThis function should return a message including the attributes of the content object inserted into the cache. This is shown in the doctests.
•def retrieveContent(self, content)oThis function should take a content object, determine which level it is in, and then return the object if it is in the cache at that level. If not, it should return a message indicating that it was not found. This is known as a “cache miss”. Accordingly, finding content in a cache is known as a “cache hit”. The doctests show the format of the return statements.
In: Computer Science
Alice and Bob are experimenting with CSMA using a W2 Walsh table. Alice uses the code [+1, +1] and Bob uses the code [+1, −1]. Assume that they simultaneously send a hexadecimal digit to each other. Alice sends (6)16 and Bob sends (B)16. Show how they can detect what the other person has sent.
In: Computer Science
I am tasked with creating a Java application that used 2 synchronized threads to calculate monthly interest and update the account balance
This is the parameters for reference to the code. Create a class
AccountSavings. The class has two instance variables: a double
variable to keep annual interest rate and a double variable to keep
savings balance. The annual interest rate is 5.3 and savings
balance is $100.
• Create a method to calculate monthly interest. • Create a method
to run two threads. Use anonymous classes to create these threads.
The first thread calls the monthly interest calculation method 12
times, and then displays the savings balance (the balance in 12th
month). After that, this thread sleeps 5 seconds. The second thread
calls the monthly interest calculation method 12 times, and then
displays the savings balance (the balance in 12th month). Before
the main thread ends, these two threads must be completed. • Add
your main method into the same class and test your threads. After
these two threads are executed, the savings balance must remain
same
I am getting an error when calling monthlyInterest method inside my runThread method. non-static method monthlyInterest() cannot be referenced from a static context and I cant seem to figure out how to fix the issue.
import static java.lang.Thread.sleep;
class AccountSavings {
double annualInterest=5.3;
double savings=100.00;
public void monthlyInterest(){
double monthlyRate;
monthlyRate = annualInterest/12;
double balance = 0;
balance+=savings*monthlyRate;
}
public synchronized static void
runThread(){
Thread t1;
t1 = new Thread(){
AccountSavings accountSavings= new AccountSavings();
@Override
public void run(){
for(int i=1;i<13;i++){
System.out.println("Balance after " + i + "month: " +
monthlyInterest());
}
try{sleep(5000);}
catch(InterruptedException e){e.printStackTrace();}
}
};
Thread t2= new Thread(){
AccountSavings accountSavings=new
AccountSavings();
@Override
public void run(){
for(int
i=1;i<13;i++){
System.out.println("Balance after " + i + " month: " +
monthlyInterest(balance));
}
try{sleep(5000);}
catch(InterruptedException
e){e.printStackTrace();}
}
};
t1.start();
t2.start();
}
public static void main(String[] args){
runThread();
}
}
In: Computer Science
Using MATLAB to plot a communication system using PAM (binary) through AWGN discrete-time channel . PLZ show your code and plot.
In: Computer Science
modify the program to cast vptr as a float and as a double
build and run your program
THIS IS THE PROGRAM CODE:
#include <stdio.h>
void main (void)
{
int intval = 255958283;
void *vptr = &intval;
printf ("The value at vptr as an int is %d\n", *((int *) vptr));
printf ("The value at vptr as a char is %d\n", *((char *) vptr));
}
In: Computer Science
Write a Java program implementing a Binary Tree which stores a set of integer numbers. (Not have duplicate nodes) (100 points)
1) Define the BinaryTree interface.
2) Define the Node class.
3) Define the class LinkedBinaryTree which implements BinaryTree Interface.
4) Define the class TestLinkedBinaryTree which tests all function of
LinkedBinaryTree.
5) Operations
Add/Remove/Update integer members.
Display(three traversal algorithms), Search.
In: Computer Science
please code in c language and follow all instructions and sample run.
Simone works for a group that wants to register more people to
vote. She knows her team can only ask a
certain number of people at any given time since they have other
obligations. She has asked you to create a
program for her team that allows the user to type in how many
people they want to ask at one time (the
duration of the current program run). The program will then ask
that many people (see sample run). If a
person answers y, his or her name is added to a registration list
(a file) and the current registration list is
output to screen. If they answer n, Ok is output to screen and the
program continues. Once at least 10 people
have been registered, whenever the program is opened the phrase
Target Reached! Exiting… should be
output to screen.
Step 1: You will be defining the following two functions (DO NOT
MODIFY THE DECLARATIONS):
/*This function takes a file pointer, goes through the file and
prints the file contents to screen. It returns the
number of lines in the file*/
int registered(FILE *fp)
/*This function takes a file pointer and adds a new line to the
file*/
void new_register(FILE *fp)
Step 2: Use the functions you defined to make a working
program.
Sample Run:
computer$ gcc –o vote vote.c
computer$ ./vote register.txt
***Registered so far:***
How many people to ask right now?
3
-Person 1: Would you like to register to vote?
n
Ok.
-Person 2: Would you like to register to vote?
y
Enter name: Bill Gates
Adding: Bill Gates
***Registered so far:***
1. Bill Gates
-Person 3: Would you like to register to vote?
y
Enter name: Mark Zuckerberg
Adding: Mark Zuckerberg
***Registered so far:***
1. Bill Gates
2. Mark Zuckerberg
3 people asked! Taking a break.
computer$ ./vote register.txt
***Registered so far:***
1. Bill Gates
2. Mark Zuckerberg
How many people to ask right now?
4
-Person 1: Would you like to register to vote?
n
Ok.
-Person 2: Would you like to register to vote?
n
Ok.
-Person 3: Would you like to register to vote?
y
Enter name: Jeff Bezos
Adding: Jeff Bezos
***Registered so far:***
1. Bill Gates
2. Mark Zuckerberg
3. Jeff Bezos
-Person 4: Would you like to register to vote?
y
Enter name: Susan Wojcicki
Adding: Susan Wojcicki
***Registered so far:***
1. Bill Gates
2. Mark Zuckerberg
3. Jeff Bezos
4. Susan Wojcicki
4 people asked! Taking a break.
In: Computer Science
The programming language has to be C
The user is going to provide you with a map of rivers and grassland. Each cell on the map will be either grassland or river. Your job is to decorate this map with forks, 4 way forks, and river bends when a river bends. You will process the user's map and modify the river cells if they depict a river bend.
You will use enums to model the river, its bends, and forks. You will pattern match to replace parts of the river with bends and forks. Out of bounds regions will be considered grasslands for pattern matching simplicity.
You will use enums in this program.
You will print the integers with 1 space padding and rows will be terminated by new lines:
10 10 10 1 2 3 4 5 6 7 8 9 10 10 10
Input and Output
The tiles that we use in the map are:
The user will input maps usually of 0 and 1 but they can include other tiles as well. Typically it will 0 and 1.
The user will input a map of
P2 6 7 10 0 0 0 0 0 0 0 1 1 1 1 0 0 1 0 0 1 0 0 1 1 1 1 1 0 1 0 0 1 0 0 1 1 1 1 0 0 0 0 0 1 0
Where 0 is grassland and 1 is river
The program will look for corners and replace them with the RiverBend pieces.
P2 6 7 10 0 0 0 0 0 0 0 5 1 1 3 0 0 1 0 0 1 0 0 6 1 1 10 1 0 1 0 0 1 0 0 4 1 1 7 0 0 0 0 0 1 0
The header format is described below. $WIDTH is the number of cells wide and $HEIGHT is the number of cells tall.
P2 $WIDTH $HEIGHT 10
The individual cells are whitespace seperated for input. Ignore whitespace and newlines for the cells.
The output format is strict, each row ends in a newline and there is 1 space padding for all integers cells printed.
Please review the q1a-test?-input.txt files for more examples
Patterns
0 0 0 0 0 0 0 0 0 -> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -> 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 -> 0 0 0 1 1 1 1 1 1
These examples are in cross form, this means that the corners can be anything (river or grassland). This is only 1 cell being changed, you are expected to apply these patterns to all cells.
1 1
1 1 0 -> 1 2 0
0 0
For example:
0 1 0 0 1 0
1 1 0 -> 1 2 0
0 0 0 0 0 0
0 0
1 1 0 -> 1 3 0
1 1
For example:
1 0 1 1 0 1
1 1 0 -> 1 3 0
1 1 1 1 1 1
1 1
0 1 1 -> 0 4 1
0 0
0 0
0 1 1 -> 0 5 1
1 1
1 1
0 1 1 -> 0 6 1
1 1
1 1
1 1 0 -> 1 7 0
1 1
1 1
1 1 1 -> 1 8 1
0 0
0 0
1 1 1 -> 1 9 1
1 1
1 1
1 1 1 -> 1 10 1
1 1
More details
Maximum supported dimension in width or height is 16000
The format you input and output is called plain PGM. PGM is portable grey map format so you can use some image programs to view it.
Invalid input (including unexpected EOF) should be aborted immediately with the message:
Invalid input!
Hints
In: Computer Science
The basic pipeline for DLX has five stages IF, ID, MEM, and WB. Assuming all memory access takes 1 clock cycle
What is the control hazard of an instruction pipeline? Provide three branches of prediction alternatives to reduce branch hazard
What is the data forwarding scheme used to reduce the data hazard?
In: Computer Science
In C Language. build a singly linked list where each node stores a randomly generated value on [0,1]. Keep the list sorted. Generate some number of nodes at startup. Print out the list formatted as e.g. → 0.04,0.19,0.27,0.33,0.54,0.66,0.75,0.99
In: Computer Science
discuss on the benefits that Data Dictionaries can bring in the health sector and give an example
In: Computer Science
Question 2:
Write a Java console application that will allow a user to add contacts to a contact list and view their current contact list sorted alphabetically. Your program should prompt the user to select an action (add or view). If the user chooses to add a contact, the contact information should be entered using the following format: Firstname Lastname, PhoneNumber If the user chooses to view their contact list, your program should display each contact on a separate line using the following format: Firstname Lastname: PhoneNumber Assume that both contact names and phone numbers will be unique (no two contacts can have the same name or phone number. A contact can only have one phone number, and a phone number can only belong to one contact). Create the appropriate objects based on the application description. Select the most suitable data structure(s) for this application.
In: Computer Science
(Global Positioning System) and GIS (Geographic Information Systems) both utilize location- based services. What are location- based services and what are some of the exciting new applications of LBS in your opinion? Give an example of how you personally have used related services.
In: Computer Science