I have written JUnit tests for my class, and would like it to tell me if there is any part of my code that is not unit tested. Is there a way to do this?
This is probably really easy, but I'm lost on how to "make sure" it is in this range..
So basically we have class Color and many functions to implement from it.
this function I need is:
Effects: corrects a color value to be within 0-255 inclusive. If value is outside this range, adjusts to either 0 or 255, whichever is closer.
This is what I have so far:
static int correctValue(int value)
{
if(value<0)
value=0;
if(value>255)
value=255;
}
Sorry for such a simple question ;/
this is what i have to do:
write a program that determines the grade dispersal for 100 students
You are to read the exam scores into three arrays, one array for each exam. You must then calculate how many students scored A’s (90 or above), B’s (80 or above), C’s (70 or above), D’s (60 or above), and F’s (less than 60). Do this for each exam and write the distribution to the screen.
// basic file operations
#include <iostream>
#include <fstream>
using namespace std;
int read_file_in_array(double exam[100][3]);
double calculate_total(double exam1[], double exam2[], double exam3[]); // function that calcualates grades to see how many 90,80,70,60
//void display_totals();
double exam[100][3];
int main()
{
double go,go2,go3;
double exam[100][3],exam1[100],exam2[100],exam3[100];
go=read_file_in_array(exam);
go2=calculate_total(exam1,exam2,exam3);
//go3=display_totals();
cout << go,go2,go3;
return 0;
}
/*
int display_totals()
{
int grade_total;
grade_total=calculate_total(exam1,exam2,exam3);
return 0;
} */
double calculate_total(double exam1[],double exam2[],double exam3[])
{
int calc_tot,above90=0, above80=0, above70=0, above60=0,i,j, fail=0;
double exam[100][3];
calc_tot=read_file_in_array(exam);
for(i=0;i<100;i++)
{
for (j=0; j<3; j++)
{
exam1[i]=exam[100][0];
exam2[i]=exam[100][1];
exam3[i]=exam[100][2];
if(exam[i][j] <=90 && exam[i][j] >=100)
{
above90++;
{
if(exam[i][j] <=80 && exam[i][j] >=89)
{
above80++;
{
if(exam[i][j] <=70 && exam[i][j] >=79)
{
above70++;
{
if(exam[i][j] <=60 && exam[i][j] >=69)
{
above60++;
{
if(exam[i][j] >=59)
{
fail++;
}
}
}
}
}
}
}
}
}
}
}
return 0;
}
int read_file_in_array(double exam[100][3])
{
ifstream infile;
int exam1[100];
int exam2[100];
int exam3[100];
infile.open("grades.txt");// file containing numbers in 3 columns
if(infile.fail()) // checks to see if file opended
{
cout << "error" << endl;
}
int num, i=0,j=0;
while(!infile.eof()) // reads file to end of line
{
for(i=0;i<100;i++) // array numbers less than 100
{
for(j=0;j<3;j++) // while reading get 1st array or element
infile >> exam[i][j];
infile >> exam[i][j];
infile >> exam[i][j];
cout << exam[i][j] << endl;
{
if (! (infile >> exam[i][j]) )
cout << exam[i][j] << endl;
}
exam[i][j]=exam1[i];
exam[i][j]=exam2[i];
exam[i][j]=exam3[i];
}
infile.close();
}
return 0;
}
hello people!! i have a problem with this code can you fix it for me?
int anagram(char* word, int cur, int len){
int i, b = cur+1;
char temp=0;
char arrA[len];
printf("//%d**%d//", b, cur);
for (i = 0 ; i < len ; i++) {
arrA[i] = word[i];
}
for (i = cur ; i < len ; i++) {
if (b < len) {
printf("%s\n", arrA);
temp = arrA[cur];
arrA[cur] = arrA[b];
arrA[b] = temp;
b++;
}
else if (b == len)
anagram(arrA, b, len);
}
return 0;
}
Design patterns aren't necessarily a programming style but rather a template for a number of problems.
But how do they differ from other programming styles?
Thanks
/* substitute(X,Y,Xs,Ys) is true if the list Ys is the result of substituting Y for all occurrences of X in the list Xs.
This is what I have so far:
subs(_,_,[],[]).
subs(X,Y,[X|L1],[Y|L2]):- subs(X,Y,L1,L2).
subs(X,Y,[H|L1],[H|L2]):- X\=H, not(H=[_|_]), subs(X,Y,L1,L2).
subs(X,Y,[H|_],[L2]):- X\=H, H=[_|_], subs(X,Y,H,L2).
My code works except it omits the elements following the nested list. For example:
?- subs(a,b,[a,[a,c],a],Z).
Z = [b, [b, c]] .
What should I add to this program?
Write a program using a do while loop to check if the number entered by a user is a palindrome?
Hint: A number is a palindrome if it is the same when it read in forward or backward direction
e.g.
if the number entered is 121 - it is palindrome
if the number entered is 323 - it is palindrome
if the number entered is 132 - it is not palindrome
in c++
I am relatively new to multi-threading and want to execute a background task using a Swingworker thread - the method that is called does not actually return anything but I would like to be notified when it has completed.
The code I have so far doesn't appear to be working:
private void crawl(ActionEvent evt)
{
try
{
SwingWorker<Void, Void> crawler = new SwingWorker<Void, Void>()
{
@Override
protected Void doInBackground() throws Exception
{
Discoverer discover = new Discoverer();
discover.crawl();
return null;
}
@Override
protected void done()
{
JOptionPane.showMessageDialog(jfThis, "Finished Crawling", "Success", JOptionPane.INFORMATION_MESSAGE);
}
};
crawler.execute();
}
catch (Exception ex)
{
JOptionPane.showMessageDialog(this, ex.getMessage(), "Exception", JOptionPane.ERROR_MESSAGE);
}
}
Any feedback/advice would be greatly appreciated as multi-threading is a big area of programming that I am weak in.
Hello there, I have a string which looks like this "a 3e,6s,1d,3g,22r,7c 3g,5r,9c 19.3", how do I go through it and extract the integers and assign them to its corresponding letter variable?. (i have integer variables d,r,e,g,s and c). The first letter in the string represents a function, "3e,6s,1d,3g,22r,7c" and "3g,5r,9c" are two separate containers . And the last decimal value represents a number which needs to be broken down into those variable numbers.
my problem is extracting those integers with the letters after it and assigning them into there corresponding letter. and any number with a negative sign or a space in between the number and the letter is invalid. How on earth do i do this?
Okay, I spent all this time making this for class but I have one thing that I can't quite get: I need this to sentinel loop continuously (exiting upon entering x) so that the
System.out.println("What type of Employee? Enter 'o' for Office " +
"Clerical, 'f' for Factory, or 's' for Saleperson. Enter 'x' to exit." );
line comes back up after they enter the first round of information. Also, I can't leave this up long on the (very) off chance a classmate might see this and steal the code. Full code following:
import java.util.Scanner;
public class Project1 {
public static void main (String args[]){
Scanner inp = new Scanner( System.in );
double totalPay;
System.out.println("What type of Employee? Enter 'o' for Office " +
"Clerical, 'f' for Factory, or 's' for Saleperson. Enter 'x' to exit." );
String response= inp.nextLine();
while (!response.toLowerCase().equals("o")&&!response.toLowerCase().equals("f")
&&!response.toLowerCase().equals("s")&&!response.toLowerCase().equals("x")){
System.out.print("\nInvalid selection,please enter your choice again:\n");
response=inp.nextLine();
}
char choice = response.toLowerCase().charAt( 0 );
switch (choice){
case 'o':
System.out.println("Enter your hourly rate:");
double officeRate=inp.nextDouble();
System.out.println("Enter the number of hours worked:");
double officeHours=inp.nextDouble();
totalPay = officeCalc(officeRate,officeHours);
taxCalc(totalPay);
break;
case 'f':
System.out.println("How many Widgets did you produce during the week?");
double widgets=inp.nextDouble();
totalPay=factoryCalc(widgets);
taxCalc(totalPay);
break;
case 's':
System.out.println("What were your total sales for the week?");
double totalSales=inp.nextDouble();
totalPay=salesCalc(totalSales);
taxCalc(totalPay);
break;
}
}
public static double taxCalc(double totalPay){
double federal=totalPay*.22;
double state =totalPay*.055;
double netPay = totalPay - federal - state;
federal =federal*Math.pow(10,2);
federal =Math.round(federal);
federal= federal/Math.pow(10,2);
state =state*Math.pow(10,2);
state =Math.round(state);
state= state/Math.pow(10,2);
totalPay =totalPay*Math.pow(10,2);
totalPay =Math.round(totalPay);
totalPay= totalPay/Math.pow(10,2);
netPay =netPay*Math.pow(10,2);
netPay =Math.round(netPay);
netPay= netPay/Math.pow(10,2);
System.out.printf("\nTotal Pay \t: %1$.2f.\n", totalPay);
System.out.printf("State W/H \t: %1$.2f.\n", state);
System.out.printf("Federal W/H : %1$.2f.\n", federal);
System.out.printf("Net Pay \t: %1$.2f.\n", netPay);
return totalPay;
}
public static double officeCalc(double officeRate,double officeHours){
double overtime=0;
if (officeHours>=40)
overtime = officeHours-40;
else
overtime = 0;
if (officeHours >= 40)
officeHours = 40;
double otRate = officeRate * 1.5;
double totalPay= (officeRate * officeHours) + (otRate*overtime);
return totalPay;
}
public static double factoryCalc(double widgets){
double totalPay=widgets*.35 +300;
return totalPay;
}
public static double salesCalc(double totalSales){
double totalPay = totalSales * .05 + 500;
return totalPay;
}
}
Write an Assembly Language program named “count letters” that counts the occurrences of all small and capital letters in given below string and then prints the result in the format (Caps, count:: Small, count). String is “bcAdBDeCEad” and it should print this result (Caps, 5:: Small, 6). The program should take address of the source string as a parameter via stack.
Hi all:
I am sending info to target email via PHP native mail() method right now. Everything else works fine but the table part troubles me the most. See sample output :
Dear Michael Mao :
Thank you for purchasing flight tickets with us, here is your receipt :
Your tickets will be delivered by mail to the following address :
Street Address 1 : sdfsdafsadf sdf
Street Address 2 : N/A
City : Sydney State : nsw Postcode : 2
Country : Australia
Credit Card Number : *************1234
Your purchase details are recorded as :
<table><tr><th class="delete">del?</th><th class="from_city">from</th><th class="to_city">to</th><th class="quantity">qty</th><th class="price">unit price</th><th class="price">total price</th></tr><tr class="evenrow" id="Sydney-Lima"><td><input name="isDeleting" type="checkbox"></td><td>Sydney</td><td>Lima</td><td>1</td><td>1030.00</td><td>1030</td></tr><tr class="oddrow" id="Sydney-Perth"><td><input name="isDeleting" type="checkbox"></td><td>Sydney</td><td>Perth</td><td>3</td><td>340.00</td><td>1020</td></tr><tr class="totalprice"><td colspan="5">Grand Total Price</td><td id="grandtotal">2050</td></tr></table>
The source of table is directly taken from a webpage, exactly as the same. However, Gmail, Hotmail and most of other emails will ignore to render this as a table.
So I am wondering, without using Outlook or other email sending agent software, how could I craft a embedded table for the PHP mail() method to send?
Current code snippet corresponds to table generation :
$purchaseinfo = $_POST["purchaseinfo"];
//if html tags are not to be filtered in the body of email
$stringBuilder .= "<table>" .stripslashes($purchaseinfo) ."</table>";
//must send json response back to caller ajax request
if(mail($email, 'Your purchase information on www.hardlyworldtravel.com', $emailbody, $headers))
echo json_encode(array("feedback"=>"successful"));
else echo json_encode(array("feedback"=>"error"));
Any hints and suggestions are welcomed, thanks a lot in advance.
Hi people,
I have three projects written with VB.NET (2005) and have to convert them to C# code. (I know that i don't need to convert codes of .net languages at all). I have no time to rewrite them, need a tool or script to convert.
Note: they are console applications.
I have a struct, with a Name and a single Node called nextName
It's a Singly Linked list, and my task is to create the list, based on alphabetical order of the strings.
So iff i enter Joe Zolt and Arthur i should get my list structured as
Joe
Than
Joe Zolt
Than
Arthur Joe Zolt
I'm having trouble implementing the correct Algorithm, which would put the pointers in the right order.
This is What I have as of Now.
Temp would be the name the user just entered and is trying to put into the list,
namebox is just a copy of my root, being the whole list
if(temp != NULL)
{
struct node* namebox = root;
while (namebox!=NULL && (strcmp((namebox)->name,temp->name) <= 0))
{
namebox = namebox->nextName;
printf("here");
}
temp->nextName = namebox;
namebox = temp;
root = namebox;
This Works right now, if i enter names like CCC BBB than AAA
I Get Back AAA BBB CCC when i print
But if i put AAA BBB CCC , When i print i only get CCC, it cuts the previous off.
I know this isn't directly related to programming, but I was wondering if anyone know how to apply the pumping lemma to the following proof:
Show that L={(a^n)(b^n)(c^m) : n!=m} is not a context free language
I'm pretty confident with applying pumping lemmas, but this one is really irking me. What do you think?
I'm having a bit of difficulty converting the following java code into Intel IA-32 Assembly:
class Person() {
char name [8];
int age;
void printName() {...}
static void printAdults(Person [] list) {
for(int k = 0; k < 100; k++){
if (list[k].age >= 18) {
list[k].printName();
}
}
}
}
My attempt is:
Person:
push ebp; save callers ebp
mov ebp, esp; setup new ebp
push esi; esi will hold name
push ebx; ebx will hold list
push ecx; ecx will hold k
init:
mov esi, [ebp + 8];
mov ebx, [ebp + 12];
mov ecx, 0; k=0
forloop:
cmp ecx, 100;
jge end; if k>= 100 then break forloop
cmp [ebx + 4 * ecx], 18 ;
jl auxloop; if list[k].age < 18 then go to auxloop
jmp printName;
printName:
auxloop:
inc ecx;
jmp forloop;
end:
pop ecx;
pop ebx;
pop esi;
pop ebp;
Is my code correct?
NOTE:
I'm not allowed to use global variables.
You are a super-hero in the year 2222 and you are faced with this great challenge: starting from your home planet Ilop you must try to reach Acinhet or else your planet will be destroyed by evil green little monsters.
To do this you are given a map of the universe: there are N planets and M inter-planetary connections ( bidirectional ) that bind these planets. Each connection requires a certain time and a certain amount of fuel in order for you to cover the connection from one planet to another.
The total time spent going from one planet to another is obtained by multiplying the time past to cover each connection between all the planets you go through.
There are some "key planets", that allow you to refuel if you arrive on those certain "key planets". A "key planet" is the planet with the property that if it disappears the road between at least two planets would be lost.(In the example posted below with the input/output files such a "key planet" is 2 because without it the road to 7 would be lost)
When you start your mission you are given the possibility of choosing between K ships each with its own maximum fuel capacity.
The goal is to find the SHORTEST TIME CONSUMING path but also choose the ship with the minimum fuel capacity that can cover that shortest path(this means that if more ships can cover the shortest path you choose the one with the minimum fuel capacity). Because the minimum time can be a rather large number (over long long int) you are asked to provide only the last 6 digits of the number.
For a better understanding of the task, here is an example of input/output files:
INPUT: mission.in
7 8 6
1 4
6 5 9 8 7 10
1 2 7 8
1 4 14 9
1 5 3 1
2 3 1 2
2 7 7 1
3 4 2 2
4 6 4 1
5 6 3 7
On the first line (in order): N M K
On the second line :the number for the starting planet and the finishing planet
On the third line :K numbers that represent the capacities of the ships you can choose from
Then you have M lines, all of them have the same structure: Xi Yi Ti Fi-which means that there is a connection between Xi and Yi and you can cover the distance from Xi to Yi in Ti time and with a Fi fuel consumption.
OUTPUT:mission.out
000014 8
1 2 3 4
On the first line:the minimum time and fuel consumption;
On the second line :the path
Restrictions:
2 = N = 1 000
1 = M = 30 000
1 = K = 10 000
Any suggestions or ideas of how this problem might be solved would be most welcomed.
Does anyone know how to convert a list to a string in Oz? I have a list of characters I need to convert to a string and I didn't see any concatenation operator in the Oz documentation.
thanks
So I have a Tree<E> class where E is the datatype held and organized by the tree. I'd like to iterate through the Tree like this, or in a way similar to this:
1. Tree<String> tree=new Tree<String>();
2. ...add some nodes...
3. for (String s : tree)
4. System.out.println(s);
It gives me an error on line 3 though.
Incompatible types
required: java.lang.String
found: java.lang.Object
The following works fine and as expected though, performing a proper in-order traversal of the tree and printing each node out as it should:
for (TreeIterator<String> i = tree.iterator(); i.hasNext(); )
System.out.println(i.next());
Any idea what I'm doing wrong? Do you need to see more of the code?
I'm working on a class assignment that involves reading an XML document and inserting the contents into a database. Language choice is wide open - so I figure, why not consider all my options!
What languages are able and appropriate for working with databases?
I'm trying to construct a binary tree (unbalanced), given its traversals. I'm currently doing preorder + inorder but when I figure this out postorder will be no issue at all.
I realize there are some question on the topic already but none of them seemed to answer my question. I've got a recursive method that takes the Preorder and the Inorder of a binary tree to reconstruct it, but is for some reason failing to link the root node with the subsequent children.
Note: I don't want a solution. I've been trying to figure this out for a few hours now and even jotted down the recursion on paper and everything seems fine... so I must be missing something subtle. Here's the code:
public static <T> BinaryNode<T> prePlusIn( T[] pre, T[] in)
{
if(pre.length != in.length)
throw new IllegalArgumentException();
BinaryNode<T> base = new BinaryNode();
base.element = pre[0]; // * Get root from the preorder traversal.
int indexOfRoot = 0;
if(pre.length == 0 && in.length == 0)
return null;
if(pre.length == 1 && in.length == 1 && pre[0].equals(in[0]))
return base; // * If both arrays are of size 1, element is a leaf.
for(int i = 0; i < in.length -1; i++){
if(in[i].equals(base.element)){ // * Get the index of the root
indexOfRoot = i; // in the inorder traversal.
break;
} // * If we cannot, the tree cannot be constructed as the traversals differ.
else throw new IllegalArgumentException();
}
// * Now, we recursively set the left and right subtrees of
// the above "base" root node to whatever the new preorder
// and inorder traversals end up constructing.
T[] preleft = Arrays.copyOfRange(pre, 1, indexOfRoot + 1);
T[] preright = Arrays.copyOfRange(pre, indexOfRoot + 1, pre.length);
T[] inleft = Arrays.copyOfRange(in, 0, indexOfRoot);
T[] inright = Arrays.copyOfRange(in, indexOfRoot + 1, in.length);
base.left = prePlusIn( preleft, inleft); // * Construct left subtree.
base.right = prePlusIn( preright, inright); // * Construc right subtree.
return base; // * Return fully constructed tree
}
Basically, I construct additional arrays that house the pre- and inorder traversals of the left and right subtree (this seems terribly inefficient but I could not think of a better way with no helpers methods).
Any ideas would be quite appreciated.
Side note: While debugging it seems that the root note never receives the connections to the additional nodes (they remain null). From what I can see though, that should not happen...
EDIT: To clarify, the method is throwing the IllegalArgumentException @ line 21 (else branch of the for loop, which should only be thrown if the traversals contain different elements.
A is an Array of n positive int numbers
k given int
Algorithm should find if there is a pair of numbers which product gives the result
a. A[i] * A[j] = k
b. A[i] = A[j] + k
if there is such a couple the algorithm should return thier index.
thanks in advance.
One last question for the evening, I'm building the main input function of my Haskell program and I have to check for the args that are brought in
so I use
args <- getArgs
case length args of
0 -> putStrLn "No Arguments, exiting"
otherwise -> { other methods here}
Is there an intelligent way of setting up other methods, or is it in my best interest to write a function that the other case is thrown to within the main?
Or is there an even better solution to the issue of cases. I've just got to take in one name.
Hi,
In my academic assignment, I want make a regular expression to match a word with the following specifications:
word length greater than or equal 1 and less than or equal 8
contains letters, digits, and underscore
first digit is a letter only
word is not A,X,S,T or PC,SW
I tried for this regex but can't continue (My big problem is to make the word not equal to PC and SW)
([a-zA-Z&&[^AXST]])|([a-zA-Z][\w]{0,7})
But in the previous regex I didn't handle the that it is not PC and SW
Thanks,