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
Draw a comparison between the traditional system development methodologies and the agile methodology on the basis of following factors:
1. Project Size
2. People Factor
3. Risk Factors
In: Computer Science
In: Computer Science
What is the relationship between Bluetooth and Wi-Fi? What security challenges do Wi-Fi and Bluetooth technology present for a company?
In: Computer Science
In: Computer Science
What is the maximum number of frames per second (round down to a whole number) that this system can display in 16,777,216 simultaneous colors at a resolution of 1920 x 1080?
In: Computer Science
Working with Python. I had to create a jackalope, with half an image of an antelope and half rabbit. Here is my code:
def animalCollage():
antelope = makePicture(pickAFile())
rabbit = makePicture(pickAFile())
antPixel = getPixels(antelope)
rabPixel = getPixels(rabbit)
for index in range(len(antPixel)/2,len(antPixel)):
newColor = getColor(rabPixel[index])
setColor(antPixel[index], newColor)
writePictureTo(antelope, "C:/Users/janin/OneDrive - Grand Canyon
University/Grand Canyon University/CST-111/Week
6/jackalope.jpg")
jackalope = pickAFile()
show(antelope)
My code worked fine, but my instructor said: "the python code to create the jackalope looks fine except I can't run it because you tried to write the picture out to your hard drive. You need to write the picture out to a pickAFile() location."
I am not sure how to correct this. Can anyone please help?
Thank you
In: Computer Science
First make the changes in P82.cpp and call the new program ex82.cpp. Compile and run the program and make sure it produces the correct results. Here is what you need to do for the exercise:
Overload the % operator such that every time
you use it, it takes two objects of type AltMoney as its arguments
and returns:
a) 5% of the difference between the income and expenditure, if
income is larger than the expenditure
b) -2% if the the expenditure is larger than the income.
c) 0 if the expenditure is the same as income
Note that, by doing this, you are required to overload the
greater than sign (>), the smaller than sign (<), and the ==
sign.
#include<iostream>
#include<cstdlib>
using namespace std;
class AltMoney
{
public:
AltMoney();
AltMoney(int d, int c);
friend AltMoney operator +(AltMoney m1, AltMoney m2);
void display_money();
private:
int dollars;
int cents;
};
void read_money(int& d, int& c);
int main()
{
int d, c;
AltMoney m1, m2, sum;
sum = AltMoney(0, 0);
read_money(d, c);
m1 = AltMoney(d, c);
cout << "The first money is:";
m1.display_money();
read_money(d, c);
m2 = AltMoney(d, c);
cout << "The second money is:";
m2.display_money();
sum = m1 + m2;
cout << "The sum is:";
sum.display_money();
return 0;
}
AltMoney::AltMoney()
{
}
AltMoney::AltMoney(int d, int c)
{
dollars = d;
cents = c;
}
void AltMoney::display_money()
{
cout << "$" << dollars << ".";
if (cents <= 9)
cout << "0"; //to display a 0 on the left for numbers less than 10
cout << cents << endl;
}
AltMoney operator +(AltMoney m1, AltMoney m2)
{
AltMoney temp;
int extra = 0;
temp.cents = m1.cents + m2.cents;
if (temp.cents >= 100) {
temp.cents = temp.cents - 100;
extra = 1;
}
temp.dollars = m1.dollars + m2.dollars + extra;
return temp;
}
void read_money(int& d, int& c)
{
cout << "Enter dollar \n";
cin >> d;
cout << "Enter cents \n";
cin >> c;
if (d < 0 || c < 0)
{
cout << "Invalid dollars and cents, negative values\n";
exit(1);
}
}
In: Computer Science
1. A company that wants to send data over the Internet will use an encryption program to ensure data security. All data will be transmitted as four-digit integers. The application should read a four-digit integer entered by the user and encrypt it as follows: Replace each digit with the remainder of the new value divided by 10 by adding 6 to the digit. Then replace the number in the first digit with the third, and the number in the second digit with the fourth. Print the encrypted integer on the screen. Write a separate application where an encrypted four-digit integer is entered and decrypted (reversing the encryption scheme) and finds the original number.
2. Create a class called Employee that contains three instance variables (First Name (String), Last Name (String), Monthly Salary (double)). Create a constructor that initializes these variables. Define set and get methods for each variable. If the monthly salary is not positive, do not set the salary. Create a separate test class called EmployeeTest that will use the Employee class. By running this class, create two employees (Employee object) and print the annual salary of each employee (object). Then set the new salary by giving each employee a 10% raise and display each employee's annual salary on the screen again.
Note: code should be written in Java language.
In: Computer Science
Q.3 Consider the function f(x) = x^2– 2x + 4 on the interval [-2, 2] with h = 0.25. Write the MATLAB function file to find the first derivatives in the entire interval by all three methods i.e., forward, backward, and centered finite difference approximations.
In: Computer Science
Discuss the Minimum System Requirements for Windows
In: Computer Science
Using Ubuntu SeedLab
For block ciphers, when the size of a plaintext is not a multiple of the block size, padding may be required. All the block ciphers normally use PKCS#5 padding, which is known as standard block padding. We will conduct the following experiments to understand how this type of padding works:
1. Use ECB, CBC, CFB, and OFB modes to encrypt a file (you can pick any cipher). Please report which modes have paddings and which ones do not. For those that do not need paddings, please explain why.
2. Let us create three files, which contain 5 bytes, 10 bytes, and 16 bytes, respectively. We can use the following "echo -n" command to create such files. The following example creates a file f1.txt with length 5 (without the -n option, the length will be 6, because a newline character will be added by echo): $ echo -n "12345" > f1.txt
We then use "openssl enc -aes-128-cbc -e" to encrypt these three files using 128-bit AES with CBC mode. Please describe the size of the encrypted files.
We would like to see what is added to the padding during the encryption. To achieve this goal, we will decrypt these files using "openssl enc -aes-128-cbc -d". Unfortunately, decryption by default will automatically remove the padding, making it impossible for us to see the padding. However, the command does have an option called "-nopad", which disables the padding, i.e., during the decryption, the command will not remove the padded data. Therefore, by looking at the decrypted data, we can see what data are used in the padding. Please use this technique to figure out what paddings are added to the three files.
It should be noted that padding data may not be printable, so you need to use a hex tool to display the content. The following example shows how to display a file in the hex format:
$ hexdump -C p1.txt 00000000 31 32 33 34 35 36 37 38 39 49 4a 4b 4c 0a |123456789IJKL.
$ xxd p1.txt 00000000: 3132 3334 3536 3738 3949 4a4b 4c0a
123456789IJKL.
In: Computer Science