In one instruction scan register BX from left to right for the position of the first 1 bit and
put the result (the position of the first bit 1) in register CX (only one instruction).
{hint: use from the instructions bsf, bsr, bt, btc, btr}
In: Computer Science
In java, please
Create an ArrayListReview class with one data field of ArrayList with the generic type passed to the class. (1 point)
Create a constructor that populate an array list filled with the generic type through inserting new elements into the specified location index-i in the list. (1 point)
Implement mergeSort using a list and recursion. (2 points)
Write the main method to test your program and use System.nanoTime() to find out the speed of each step of your program. (1 point)
In: Computer Science
C++ -
De Morgan’s laws commonly apply to text searching using Boolean operators AND, OR, and NOT. Consider a set of documents containing the words “cars” and “trucks”. De Morgan’s laws hold that these two searches will return the same set of documents:
Search A: NOT (cars OR trucks)
Search B: (NOT cars) AND (NOT trucks)
The corpus of documents containing “cars” or “trucks” can be represented by four documents:
Document 1: Contains only the word “cars”.
Document 2: Contains only “trucks”.
Document 3: Contains both “cars” and “trucks”.
Document 4: Contains neither “cars” nor “trucks”.
To evaluate Search A, clearly the search “(cars OR trucks)” will hit on Documents 1, 2, and 3. So the negation of that search (which is Search A) will hit everything else, which is Document 4.
Evaluating Search B, the search “(NOT cars)” will hit on documents that do not contain “cars”, which is Documents 2 and 4. Similarly the search “(NOT trucks)” will hit on Documents 1 and 4. Applying the AND operator to these two searches (which is Search B) will hit on the documents that are common to these two searches, which is Document 4.
Please write a C++ program to De Morgan's Law via document search.
You can use four text files as document 1, 2 3 and 4.
Using this Assignment, read a document and create frequency map. Take the frequency map and display histogram for each word in the document.
Draw histogram in horizontal direction.
This (6) **********
my (4) ******
Truck (6) *********
In: Computer Science
I have to create a program that:
I have attached what I have so far. All I need to do is get help with the next two tables which will sort by last name, alphabetically and then sort by total sales in descending order. I need help adding the segments that will output two more tables of sorting by last name and descending total sales. If possible, can you add comments to show what you did and what it means.
#include <iostream> #include <string> #include <fstream> #include <sstream> #include <algorithm> // for std::sort using namespace std; class customer{ public: string first; string last; string state; double sHistory[3]; // Sales history for three years. double totalSales; // Total sales (adding all three years together) int purchaseUnits; }; void printcust(customer[], int); void sortname(customer[], int); void sortsales(customer[], int); int main () { fstream infile; customer cust; customer custarray[10]; infile.open("data.txt"); int i = 0; while(infile) { infile >> custarray[i].first; infile >> custarray[i].last; infile >> custarray[i].state; infile >> custarray[i].sHistory[0]; infile >> custarray[i].sHistory[1]; infile >> custarray[i].sHistory[2]; infile >> custarray[i].purchaseUnits; custarray[i].totalSales = custarray[i].sHistory[0] + custarray[i].sHistory[1] + custarray[i].sHistory[2]; i++; } i = i - 1; for(int a = 0; a < i; a++) { cout << custarray[a].first << '\t' << custarray[a].last << '\t' << custarray[a].state << '\t'; cout << custarray[a].sHistory[0] << " " << custarray[a].sHistory[1] << " " << custarray[a].sHistory[2]; cout << '\t' << custarray[a].purchaseUnits << '\t' << custarray[a].totalSales; cout << endl << endl; } }
In: Computer Science
Write a Python program that computes certain values such as sum, product, max, min and average of any 5 given numbers along with the following requirements.
Define a function that takes 5 numbers, calculates and returns the sum of the numbers.
Define a function that takes 5 numbers, calculates and returns the product of the numbers.
Define a function that takes 5 numbers, calculates and returns the average of the numbers. Must use the function you defined earlier to find the sum of the five numbers.
Define a function that takes 5 numbers, finds and returns the largest value among the numbers. Must use conditional statements and NOT use built-in max function.
Define a function that takes 5 numbers, finds and returns the smallest value among the numbers. Must use conditional statements and NOT use any built-in min function.
Define a function called main inside which Prompt users to enter 5 numbers. Call all the functions passing those 5 numbers entered by the user and display all the returned answers with proper descriptions.
Define a function called test For each of the functions you defined (6-10) write at least 2 automated test cases using assert statements to automatically test and verify that the functions are correctly implemented. make your program continue to run and calculate the same statistical values of as many sets of 5 numbers as a user wishes until they want to quit the program.
In: Computer Science
Write a program to convert a text-file containing expressions (one per line) into post-fix expressions outputted to a file of your choice using a stack with one space between operators and variables ( one letter variables) and/or constants (one digit constants).
In: Computer Science
Create a Java class with the name (identifier) MyProgram and place it in the Questions package. You will need to create a main method for this class and place all of your code inside of that method. Your program should complete the following steps: - Prompt the user to enter a name for a Student. - Use the Scanner class to read in the user input and store the result in a variable. - Use the Random class to generate a random number (1 – 99999) and store it in a variable. - Create 3 int variables and assign them values of your choosing in the range 0 – 100. - Use the variables you created in the previous steps to instantiate (construct) a Student object where the user input you read is the student’s name, the random number is the student’s ID, and the 3 int variables you created are the student’s exam scores. - Print out the student’s details. You can do this by using the Student object reference as an argument in a println method call. - Run your program to make sure it works correctly.
In: Computer Science
Description:
The purpose of this assignment is to write code that calculates the amount of interest accrued on a credit card on its expenses. You will create a C program that prompts the user for the total amount of purchases on the credit card, an annual percentage rate (APR), and the number of days the money is borrowed. The program will calculate the amount of the compound interest for the purchases, then print the original amount of purchases, the amount of the interest, and the total amount needed to be paid back.
Preparation:
For interest calculation, we will use the compound interest method,
in which, we consider not only the interest on the actual borrowed
amount, but also the interest of interest that has already accrued.
We will use the following simple formula to compute compound
interest:
P' = P(1 +
r/n)^(nt)
where:
P is the original
principal sum
P' is the new
principal sum
r is the annual
interest rate
n is the
compounding frequency (we assume it to be 12, like most US
banks)
t is the overall
length of time the interest is applied (expressed in years).
The total compound interest generated is the final value minus the
initial principal:
I = P' - P
In order to compute the power function, you need to include math.h
library and call the pow() function within it. See the man page of
pow() to find more information about it. Also note that, the number
of days money is borrowed needs to be converted to number of years.
If you simply try days/365 to express it in terms of years, the
result of the division is likely going to be incorrect.
Your program should check to ensure that negative values are not
input. If an improper value is entered, an error message should be
printed and the program will exit (do not re-prompt the user for a
correct value).
For input, you must use the fgets()/sscanf() combination of
Standard I/O functions. Do not use the scanf() or fscanf()
functions. Although using scanf() for retrieving numerical data is
convenient, it is problematic when used in conjunction with
character string input (as you may discover if you use it in later
labs). Therefore, it is best to get into the habit of avoiding
scanf() completely, and using the fgets()/sscanf() combination
exclusively.
Although you will learn more about this in later lectures and labs,
this is what you should typically do to read a number using the
fgets()/sscanf() combination:
// in main() or some function
char inBuf[20]; // A buffer to hold the input from the
keyboard
int someInt = 0; // A variable to hold the number from the
keyboard
fgets(inBuf, 20, stdin); // Read the input from the keyboard and
store it in inBuf
sscanf(inBuf, "%d", &someInt); // Extract the numerical value
from inBuf and store it in someInt
Note from the sscanf() manpage that when reading a floating point value, if the data type of the variable that will receive the value is of type double, you must use "%lf" (long float) instead of "%f" (float) for your format string.
In: Computer Science
Step 1: Capturing the input
The first step is to write a functionGetInput()that inputs the expression from the keyboard and returns the tokens---the operands and operators---in a queue. You must write this function.
To make the input easier to process, the operands and operators will be separated by one or more spaces, and the expression will be followed by #. For example, here’s a valid input to your program:
6 4 15 * – #
Back in Codio, modify “main.cpp” by defining the following function above main(). Note the additional #include statements, add those as well:
#include <iostream>
#include <stack>
#include <queue>
#include <string>
#include <sstream>
#include <cctype>
using namespace std;
queue<string> GetInput()
{
queue<string> Q;
stringtoken;
cin >> token;
.. // TODO: loop andinputrestof expression, adding to queue. // Do not add the sentinel # to the queue..
return Q;
}
Now modify the main() function to call GetInput, and change the cout statement to output the size of the queue returned by GetInput. This is a simple check to make sure the queue contains the elements of the expression. Build and run, and enter an expression such as
6 4 15 * – #
The output should be a size of 5---3 operands and 2 operators (the # should not be stored in the queue). If you want to be sure the queue is correct, write a quick loop to pop the contents of the queue one by one, and output. When you’re done, comment out these debug output statements.
Step 2: Evaluating the expression (assuming valid input)
Now that the input has been captured, step 2 is to evaluate the expression. The idea is simple: when you see an operand (an integer), push it on a stack. When you see an operator, pop off two operands, perform the operation, and push on the result. When the input has been processed, the answer is on top of the stack. Go ahead and draw out an example on paper and convince yourself it works: 6 4 15 * - should yield -54.
Write a function EvaluatePostfix that takes a queue containing the input, and returns two values: the integer result, and true / false(denoting valid input or not). Here’s the function definition:
bool EvaluatePostfix(queue<string> input, int& result)
{
stack<int> operands;
.. // evaluate expression:.
result = operands.top(); // answer is on top
return true; // successful evaluation
}
For now, assume valid input, and don’t bother with error checking.Loop until the queue is empty, popping one token at a time. Since the tokens are strings, and a string is an array of characters, you can access the first element of a string using[0]. This makes it easy to tell if a token is an integer operand:
string s = input.front();// next token in the queue:
input.pop();
if (isdigit(s[0]))// integer operand:
{
operands.push(stoi(s));// in C++, usestoito convert string to int
}
else // operator{
...
}
To determine the operator, compare s[0] to ‘+’, ‘*’, etc. Once you have the function written, modify main() to call the function and output the result. Build, run and test with a variety of expressions. Here’s a few:
6 4 15 * – # => -54
6 4 –5 * # => 10
21 10 30 * + 80 / # => 4
Step 3: Handling invalid input
The last step is to extend the program to handle invalid input. Modify the EvaluatePostfix function to handle the following:
1. What if the stack contains more than one value at the end (or is empty)? This can happen when the input is empty, or the expression doesn’t contain enough operators. Example: 1 2 3 + #. In this case EvaluatePostfix should return false.
2. What if the stack does not contain 2 operands when an operator is encountered? This can happen when the expression doesn’t contain enough operands. Example: 1 2 + + #. In this case EvaluatePostfix should return false.
3. What if the operator is something other than +,-, * or /. In that case, EvaluatePostfix should return false.
You’ll need to modify main() to check the value returned by EvaluatePostfix. If false is returned, output the word “invalid” followed by a newline. Build, run and test.
In: Computer Science
I am needing assistance figuring out how to write the code for this project in C# (C sharp)...
Create a new Project and name it - InClassParticipation3
Get up to 5 inputs from the user. The user must enter at least 1
number.
After the first input, ask them if they would like to input another
number if they say 'yes' get the provided input and multiply it to
the other inputs provided by the user.
If the user says 'no', do not prompt them to input any more numbers
and then figure out if the number is divisible by 3, 5, both 3 AND
5, or none of the provided options.
If the number is divisible by 3, output the number and then
'YAY'.
If the number is divisible by 5, output the number and then
'ME'.
If the number is divisible by both 3 and 5, output the number and
then 'YAYME!!'.
If it is not divisible by either 3 or 5, simply just output the
number.
In: Computer Science
How many times are we copying elements to the right while applying insertion sort on the input sequence 3 5 2 8 3?
How many times are we copying elements to the right while applying insertion sort on the input sequence 5 4 3 2 1?
In: Computer Science
Generate a sample of 1000 random floating numbers (from 0 to 1) using numpy. Then plot it and compare with a normal distribution plot close to that region (from 0 to 1) as well. Hint: Using Seaborn module
In: Computer Science
I'm having trouble getting a certain output with this code #include <stdio.h> //function prototypes void initializeArray(int size, int ids[]); void printArray(int size, int * idPointer); int main(void) { // 1. declare an array of 5 integers called ids int ids[5]; // 2. declare an integer pointer called arrayPointer and // initialize it to point to the array called ids int *arrayPointer = ids; // 3. call initializeArray() function sending to it // 5 for the size and the array called ids initializeArray(5,ids); // 4. add 3 to the value at where arrayPointer is pointing to *(arrayPointer) += 3; // 5. add 5 to the value at 2 locations past // where arrayPointer is pointing to *(arrayPointer+1) += 5; // 6. call printArray() function sending to it // 5 for the size and arrayPointer printArray(5, arrayPointer); return 0; } // This function initializes an array ids of size "size" void initializeArray(int size, int ids[]) { int i; for (i = 0; i < size; i++) { ids[i] = i * 100; } } // This function prints an array of size "size". The array is pointed at by idPointer void printArray(int size, int * idPointer) { int i; for (i = 0; i < size; i++) { // 7. finish the code for the printf() statement printf("Element at index %d is %d\n", i,*(idPointer+i)); } }
Element at index 0 is 3 | |
Element at index 1 is 100 | |
Element at index 2 is 205 | |
Element at index 3 is 300 | |
Element at index 4 is 400 |
In: Computer Science
Case Project 3-2 Setting Up DNS Security Your DNS servers have been hacked, and you’ve been asked to set up DNS security measures. Your supervisor wants to know the options for preventing attackers from tampering with your DNS servers. Write a memo to your supervisor discussing DNSSEC, a DNS socket pool, and DNS cache locking and how they can help secure DNS. Answer:
In: Computer Science
1. Convert the following pseudo code routine into MIPS assembler language:
- Set register $t0 = 1
- In four separate instructions add 2, then 3, then 4, then 5 into register $t0
$t0 = $t0 + 2 + 3 + 4 + 5
- Copy the result from register $t0 into register $t1
2. Convert the following into MIPS assembler language:
- Set register $t0 = 0
- Initialize the register $t1 = 10
- Use register $t2 as a counter, and create a loop that repeats 5 times
- Each time through the loop, add register $t1 to $t0
- And add 10 (decimal) to register $t1
- As a result, $t0 should have the sum of the equation: 10 + 20 + 30 + 40 + 50
3. Generate an instruction sequence that will result in an arithmetic overflow. Do not use an endless loop, but rather create a specific code sequence.
Please add comments!!
In: Computer Science