C++
Assume you need to test a function named inOrder. The function inOrder receives three int arguments and returns true if and only if the arguments are in non-decreasing order: that is, the second argument is not less than the first and the third is not less than the second. Write the definition of driver function testInOrder whose job it is to determine whether inOrder is correct. So testInOrder returns true if inOrder is correct and returns false otherwise.
. For the purposes of this exercise, assume inOrder is an expensive function call, so call it as few times as possible!
In: Computer Science
What makes a good tool for analyzing and interpreting data? And why? Give an example.
In: Computer Science
C# Programming
1. Create an Employee class with two fields: idNum and hourlyWage. The Employee constructor requires values for both fields. Upon construction, thrown an ArgumentException if the hourlyWage is less than 7.50 or more than 50.00. Write a program that establishes, one at a time, at least three Employees with hourlyWages that are above, below, and within the allowed range. Immediately after each instantiation attempt, handle any thrown Exceptions by displaying an error message. Save the file as EmployeeExceptionDemo.cs.
2. Write an application that creates an array of five Employees. Prompt the user for values for each field for each Employee. If the user enters improper or invalid data, handle any exceptions that are thrown by setting the Employee’s ID number to 999 and the Employee’s pay rate to the $7.50. At the end of the program, display all the entered, and possible corrected, records. Save the file as EmployeeExceptionDemo2.cs.
In: Computer Science
Read the following pseudocode class definitions:
Class Plant
Public Module message()
Display "I'm a plant."
End Module
End Class
Class Tree Extends Plant
Public Module message()
Display "I'm a tree."
End Module
End Class
Given these class definitions, determine what the following pseudocode will display:
Declare Plant p
Set p = New Tree()
Call p.message()
Discuss how algorithms address object-oriented classes and objects.
In: Computer Science
This is the question about the java problem, please give the detail comment and code of each class.
Please write tests for all the code of all the classes
Thank you
Create a class Mammal with the following UML
diagrams:
+---------------------------------+
| Mammal |
+---------------------------------+
| - name: String |
+---------------------------------+
| + Mammal(String name) |
| + getName(): String |
| + isCookable(): boolean |
| + testMammal(): void | (this method is static
)
+---------------------------------+
The isCookable method of the
Mammal class returns a boolean indicating whether
the mammal can be cooked or not: some mammals can be cooked and
some mammals cannot be cooked so for safety reasons the
isCookable method just prints a message
"Do not cook this!" and returns false (because the
isCookablemethod must return a boolean).
Add a class Human to your program. A human is a
mammal. The constructor for the Human class takes
no argument. All humans are named "Alice" and
humans cannot be cooked (the isCookable method
must not print any message though, it simply returns
false).
Add a class Rabbit to your program. A rabbit is a
mammal. The Rabbit class has a private instance
variable weight of type double
that describes the weight of the rabbit, and a
getWeight method. The constructor for the
Rabbit class takes the rabbit’s name and the
rabbit’s weight as arguments. A rabbit can be cooked.
Add a class EuropeanRabbit to your program.
European rabbit is a species of rabbit. The
EuropeanRabbitclass has two constructors: the
first constructor takes the European rabbit’s name and the European
rabbit’s weight as arguments; the second constructor only takes the
European rabbit’s name as argument and always uses
2.0 as the European rabbit’s weight. The second
constructor must use the first constructor.
Add a class LapinSautéChasseur to your program.
Lapin sauté chasseur is a kind of European rabbit. The constructor
for the LapinSautéChasseur class takes no
argument. Lapin sauté chasseur is always named
"Delicious" and has a weight of 0.5.
Add a class FrankTheRabbit to your program. Frank
The Rabbit is a kind of rabbit. The constructor for
theFrankTheRabbit class takes no argument. Frank
The Rabbit is always named "Frank", has a weight
of 100.0, and cannot be cooked.
Add a class Start to your program to test all your
classes.
Question 2
Add a class CastIronPot to your program with the
following UML diagram:
+---------------------------------+
| CastIronPot |
+---------------------------------+
| - rabbit: Rabbit |
+---------------------------------+
| + CastIronPot(Rabbit rabbit) |
| + getRabbit(): Rabbit |
| + testCastIronPot(): void |(this method is
static)
+---------------------------------+
In the testCastIronPot method, create a lapin
sauté chasseur called lsc1, then create a cast
iron pot with this lapin sauté chasseur in it. Then get the lapin
sauté chasseur from the cast iron pot and store it into a local
variable called lsc2 of type
LapinSautéChasseur. Use the == operator to check
that lsc1 and lsc2 are the same
lapin sauté chasseur.
In: Computer Science
A javafx gui that's meant to work like a shopping cart, which has 3 books how did this happen 12.99, will benelli, 14.99, and where do I go, 10.99, you can remove from cart, clear cart, or checkout, and it should have a receipt of what you purchased. I am using eclipse, thanks.
In: Computer Science
What is the difference between a comma-delimited text file and a fixed-width text file? Why is it important that you understand the difference before you import data from a text file?
In: Computer Science
What are the advantages and disadvantages of saving a workbook template to a folder other than the Templates folder?
In: Computer Science
The following code is for a class named Box. The class Box includes a constructor method Box, and a method getVolume().
For your assignment you are to develop a java class named MatchBox. Your class MatchBox must extend the class Box and in addition to the attributes width, height, and depth that are defined in the class Box, MatchBox must add a new attribute weight. The getVolume method must both report the values of width, height, depth, and weight, but must also calculate and report the volume by multiplying height by width by depth. The class MatchBox must also add the method calculateWeight() that will calculate weight based upon the volume assuming that the volume is a quantity of water which weighs .03611 pounds per cubic inch. Also method calculateWeight should show the result like this: weight of MatchBox is X.
For example a car class can inherit some properties from a General vehicle class. Here we find that the base class is the vehicle class and the subclass is the more specific car class. A subclass must use the extends clause to derive from a super class which must be written in the header of the subclass definition. The subclass inherits members of the superclass and hence promotes code reuse. The subclass itself can add its own new behavior and properties.
Your new class must include a main method that creates a new MatchBox object, calls the getVolume method and reports the results by printing the following items to the screen (where the X is replaced by the calculated value) For your assignment, assume that the value of width is 5, height is 10, and the depth is 3. The output should look like the following with X replaced with the appropriate calculated value.
width of MatchBox is X
height of MatchBox is X
depth of MatchBox is X
weight of MatchBox is X
Volume is: X
Helpful Hints
When creating this assignment you should assume a java file for each component. First create a Box.java to hold the box class, a MatchBox.java for the MatchBox class and a main.java for the main routine. All three files, when using Netbeans must belong to the same package so make sure you use the package statement at the beginning of each file.
Keep in mind that in the new class MatchBox, you can either use the methods and variables in the Box class, redefine methods or variables for the MatchBox class that exist in Box or create new methods and variables.
======
The class Box is as follows:
class Box { double width; double height; double depth; // This is an empty constructor Box() { ; } Box(double w, double h, double d) { width = w; height = h; depth = d; } void getVolume() { System.out.println("Volume is : " + width * height * depth); }
In: Computer Science
Using Object Oriented Programming method, make a simple game program with C++. Please include fully explanation/diagram(if any) about which parts implement the object oriented programming.
In: Computer Science
Write a function that will have a list as an input, the task of the function is to check if all the elements in the list are unique,( i.e. no repetition of any value has occurred in the list), then the function returns true otherwise it returns false. Your program should include a main method that call the method to test it.
For the function you implemented in part 1, please calculate T(n), which represents the running time of your algorithm in terms of n. Where n is the length of the list. Then find the order of magnitude of your algorithm (Big O).
Please find another algorithm that solves part 1, write the code, calculate T(n) and find Big O. Then compare the efficiency with the algorithm from part1 to determine the more efficient one.
In: Computer Science
In: Computer Science
C Program: How do I write a Greedy function for 0-1 knapsack, to find total value only( replace struct Knapsack)
# include
#include
#include
struct Knapsack {
int value;
int weight;
};
// returns maximum of two integers
int max(int a, int b) { return (a > b)? a : b;
}
// Returns the maximum value that can be put in a
knapsack of capacity W
struct Knapsack knapSackExhaustive(int W, int wt[],
int val[], int n){
int i, w;
int K[n+1][W+1];
int totalWeight=0;
// Build table K[][] in bottom up manner
for (i = 0; i <= n; i++){
for (w = 0; w <= W; w++){
if (i==0 || w==0)
K[i][w] = 0;
else if (wt[i-1] <= w){
K[i][w] = max(val[i-1] +
K[i-1][w-wt[i-1]], K[i-1][w]);
}
else
K[i][w] = K[i-1][w];
}
}
//For calculation of totalweight;
int res = K[n][W];
w = W;
for (i = n; i > 0 && res > 0; i--)
{
// either the result comes from the top
// (K[i-1][w]) or from (val[i-1] + K[i-1]
// [w-wt[i-1]]) as in Knapsack table. If
// it comes from the latter one/ it means
// the item is included.
if (res == K[i - 1][w])
continue;
else {
// This item is included.
//printf("%d ", wt[i - 1]);
totalWeight=totalWeight+wt[i-1];
// Since this weight is included its
// value is deducted
res = res - val[i - 1];
w = w - wt[i - 1];
}
}
struct Knapsack knap;
knap.value=K[n][W];
knap.weight=totalWeight;
return knap;
}// end struct knapSackExhaustive
int main(void) {
struct Knapsack aSack;
int i;
time_t t;
int val[5];
int wt[5];
//Intializes random number generator
srand((unsigned) time(&t));
// Print 5 random values from 3 to 15
printf("Five Random Values:\n");
for( i = 0 ; i < 5 ; i++ ) {
val[i]=rand()%15+3;
printf("%d\n",val[i]);
}
int j;
//Print 5 random weights from 1 and 10000
printf("Five Random Weights:\n");
for( j = 0 ; j < 5 ; j++ ) {
wt[j]=rand() % 10000;
printf(" %d\n", wt[j]);
}
int W = 10000;
int n = sizeof(val)/sizeof(val[0]);
aSack = knapSackExhaustive(W, wt, val, n);
printf("Total Value: %d\t\n", aSack.value);
printf("Total Weight:%d\t",aSack.weight);
return 0;
}
In: Computer Science
Rewrite the attached mycat.c program in 3 using read, write, open and close (System I/O functions) instead of the standard I/O functions.
#include<stdio.h> int main(int argc, char* argv[]) { FILE *fp; void filecopy(FILE *, FILE *); if (argc == 1) { filecopy(stdin, stdout); } else { while(--argc >0) { if ((fp = fopen(*++argv, "r")) == NULL) { printf("cat: can not open %s\n", *argv); return 1; } else { filecopy(fp, stdout); fclose(fp); } } } return 0; } void filecopy(FILE *ifp, FILE *ofp) { int c; while ((c = getc(ifp)) != EOF) { putc(c, ofp); } }
In: Computer Science
You will have to experiment with using chmod on the
folder and the file to come up with the following:
Find the chmod commands for both the folder and the file that you
would use to give the minimum permissions for You (the owner) to be
able to edit and change the file (and I don’t want to see 777! ? )
:
___________________________________________________________
___________________________________________________________
___________________________________________________________
In: Computer Science