Write a program in C++ called RollDice.cpp that simulates rolling a pair of dice until the total on the dice comes up to be a given number. Ask the user for the number that you are rolling for.
To have your program roll two dice, use the rand() function this way:
die1 = rand() % 6 + 1; die2 = rand() % 6 + 1;
Your program then computes and prints the number of rolls it takes to get the given number. Valid numbers are 2 through 12.
If the user asked for a 2 your program should output:
It took 20 rolls to get a 2.
(your number of rolls will be different of course)
In: Computer Science
How can I use Python without Pandas to create a new.csv file with the headers "c1, c2, c3, c4, c5, c6" and the first line of data "8, 5, -9, 7, 2.1, 1.7" from the original.csv file?
In: Computer Science
Write in C programming using if and else statements only please!!!
Write a program that plays the following card game: The user starts out with a pot of $100. At each hand of the game, the dealer and the player are dealt a random number between 1 and 52. The player wins $20 if his/her number is greater than the dealer's number; otherwise they lose $20.
In: Computer Science
Reflect on your own professional interests – can you imagine yourself in the role of a Business Analyst? What aspects would you enjoy? What aspects would require some effort?
In: Computer Science
Shrink-wrap, box-top, and click-wrap agreements are inherent to e-commerce. How you feel about them often depends on whether you are the vendor or purchaser. What are the best practices to assure shrink-wrap, box-top, and click-wrap agreements are legal? What are the best ethical practices that the e-commerce industry should adopt?
In: Computer Science
use python
Although clumsy, the if statements and if-else statements can be used to achieve the same effects as if-elif-else statements. Rewrite the speed3 function:
def speed3():
kph=float(input('What is the speed in kph?'))
mph=0.621371*kph
print('The speed is',mph,'mph.')
if mph>80:
print('You are WAY over the speed limit. Your fine is $200!')
elif 65<mph<=80:
print('You are over the speed limit (65mph) . Slow down1').
elif 30<=mph<=65:
print('You are within the speed limit. Good job!')
else:
print('You are too slow. Exit highway and use local roads!')
(a) use only if statement
(b) use only if-else statement
In: Computer Science
How have embedded computers and the IoT impacted your daily life? What additional uses can you see yourself using? What security or other risks might you encounter with IoT?
In: Computer Science
How do you set up a Raspberry Pi 3 Model B as a master
in an I2C protocol?
Please explain this process thoroughly, as well as the code you
would use, if any
In: Computer Science
A. Open/create the file bank.txt for writing "w". Enter a character from the keyboard and write it to the file. Close the file. In the same program open the file for reading "r" and read the character from the file and print it on screen.
In: Computer Science
given an array, write code to scan the array for a particular purpose . use java
In: Computer Science
Give three examples of typical types of exceptions handled by CPU's.
In: Computer Science
Assignment 2 - Employee Hierarchy
In Chapter 9, we created the CommissionEmployee-BasePlusCommissionEmployee inheritance hierarchy to model the relationship between two types of employees and how to calculate the earnings for each. Another way to look at the problem is that CommissionEmployees and BasePlusCommissionEmployees are each Employees and that each has a different CompensationModel object.
A CompensationModel would provide an earnings method. Classes or subclasses of CompensationModel would contain the details of a particular Employee's compensation:
Each of these classes would contain a toString() method that displays the Compensation Model information as illustrated in the sample output.
This approach is more flexible than our original hierarchy. For example, consider an Employee who gets promoted. With the approach described here, you can simply change that Employee's CompensationModel by assigning the composed CompensationModel reference an appropriate subclass object. With the CommissionEmployee - BasePlusCommissionEmployee hierarchy, you'd need to change the Employee's type by creating a new object of the appropriate class and moving data from the old object to the new one.
Implement the Employee class and CompensationModel hierarchy discussed in this exercise. In addition to the firstName, lastName, socialSecurityNumber and CommisionCompensationModel instance variables, class Employee should provide:
Your code in the subclasses should call methods in the super classes whenever possible to reduce the amount of code in the subclasses and utilize the code already developed in the super classes as in the code demonstrated in Figures 9.10 and 9.11 in the book.
Use the following code in your main function to test your classes, just copy and paste it into your main method:
// Create the two
employees with their compensation models.
CommissionCompensationModel commissionModel = new
CommissionCompensationModel(2000.00, 0.04);
BasePlusCommissionCompensationModel basePlusCommissionModel = new
BasePlusCommissionCompensationModel(2000.00, 0.05, 600.00);
Employee employee1 = new
Employee("John", "Smith", "111-11-1111", commissionModel);
Employee employee2 = new
Employee("Sue", "Jones", "222-22-2222",
basePlusCommissionModel);
System.out.printf("%s%n%s%n", employee1, employee2);
System.out.printf("%s%s%s%s%s%8.2f%n%n", "Earnings for ",
employee1.getFirstName(), " ", employee1.getLastName(), ": ",
employee1.earnings());
// Change the
compensation model for the two employees.
CommissionCompensationModel commissionModelNew = new
CommissionCompensationModel(5000.00, 0.04);
BasePlusCommissionCompensationModel basePlusCommissionModelNew =
new BasePlusCommissionCompensationModel(4000.00, 0.05,
800.00);
// Set the new
compensation models for the employees.
employee1.setCompensation(basePlusCommissionModelNew);
employee2.setCompensation(commissionModelNew);
// Print out the new
information for the two employees.
System.out.printf("%s%n%s%n", employee1, employee2);
The output from your program should look like the following:
run:
John Smith
Social Security Number: 111-11-1111
Commission Compensation with:
Gross Sales of: 2000.00
Commission Rate of: 0.04
Earnings: 80.00
Sue Jones
Social Security Number: 222-22-2222
Base Plus Commission Compensation with:
Gross Sales of: 2000.00
Commission Rate of: 0.05
Base Salary of: 600.00
Earnings: 700.00
Earnings for John Smith: 80.00
John Smith
Social Security Number: 111-11-1111
Base Plus Commission Compensation with:
Gross Sales of: 4000.00
Commission Rate of: 0.05
Base Salary of: 800.00
Earnings: 1000.00
Sue Jones
Social Security Number: 222-22-2222
Commission Compensation with:
Gross Sales of: 5000.00
Commission Rate of: 0.04
Earnings: 200.00
In: Computer Science
Write a python program that implements a Brute Force attack on Shift Cipher. In this program there is only one input - ciphertext - is a sequence of UPPER CASE letters. To make it easy, the program will be interactive and will output all possible plaintexts and ask user which plaintext makes sense. As soon as user will decide YES, the program will stop searching and print the desired plaintext and the found SHIFT KEY.
In: Computer Science
How to write a method that performs matrix multiplication with three rectangle arrays along with their dimensions as parameters using Java programming?
In: Computer Science
1. Use the enum keyword or a C++ class to create a new type Boolean with the two values F and T defined. Use the C++ class/struct keyword and an array to create a list of pairs that cover all possible combinations of the 2 Boolean constants you defined.
2. Extend the same program and implement conjunction and disjunction functionality in a separate library (mylib.h/mylib.cpp). Use your implementation to print truth tables for both.
3. Further extend the same program by adding xdisjunction and negation functionality. Use your implementation to print truth table for both.
4. Use functions developed (conjunction, disjunction, negation ...) in above assignment and implement Example 1.8 (a) Construct the truth table of the proposition (p∧q)∨(∼ p∨∼ q). Determine if this proposition is a tautology. (b) Show that p∨∼ p is a tautology.
5. Use functions developed in mylib (mylib.h/mylib.cpp) separate library (conjunction, disjunction, negation ...) in previous assignments and implement Example 1.9
(a) Show that ∼ (p∨q) ≡∼ p∧∼ q.
(b) Show that ∼ (p∧q) ≡∼ p∨∼ q.
(c) Show that ∼ (∼ p) ≡ p.
Parts (a) and (b) are known as DeMorgan’s laws.
In: Computer Science