Search Results

Search found 1552 results on 63 pages for 'homework'.

Page 19/63 | < Previous Page | 15 16 17 18 19 20 21 22 23 24 25 26  | Next Page >

  • regular expression of 0's and 1's

    - by Lopa
    Hello all I got this question which asks me to figure out why is it foolish to write a regular expression for the language that consists of strings of 0's and 1's that are palindromes( they read the same backwards and forwards). part 2 of the question says using any formal mechanism of your choice, show how it is possible to express the language that consists of strings of 0's and 1's that are palindromes?

    Read the article

  • Floating point mantissa bias

    - by user69514
    Does anybody know how to go out solving this problem? * a = 1.0 × 2^9 * b = -1.0 × 2^9 * c = 1.0 × 2^1 Using the floating-point (the representation uses a 14-bit format, 5 bits for the exponent with a bias of 16, a normalized mantissa of 8 bits, and a single sign bit for the number), perform the following two calculations, paying close attention to the order of operations. * b + (a + c) = ? * (b + a) + c = ?

    Read the article

  • SQL where clause to work with Group by clause after performing a count()

    - by Matt
    Tried my usual references at w3schools and google. No luck I'm trying to produce the following results. QTY is a derived column | Position | QTY -------------------- 1 Clerk 2 2 Mgr 2 Here's what I'm not having luck with: SELECT Position, Count(position) AS 'QTY' FROM tblemployee Where ('QTY' != 1) GROUP BY Position I know that my Position is set up as varchar(255) Count produces a integer data and my where clasue is accurate so that leads me to believe that that Count() is jamming me up. Please throw up an example so I can reference later. Thanks for the help!

    Read the article

  • NSString stringWithFormat: with C array?

    - by Chris Long
    Hi, I'm writing a program that calculates the Jacobi algorithm. It's written in Objective-C since it runs on a Mac, but the majority is written in standard C. I'm using a two-dimensional C array and an NSArray containing 5 NSTextField labels. The following code yields an EXC_BAD_ACCESS error: for ( int i = 0; i < 5; i++ ) { NSString *resultString = [NSString stringWithFormat:@"%g", matrix[i][i] ]; [[resultLabels objectAtIndex:i] setStringValue:resultString]; // error line } Any help?

    Read the article

  • How to get predecessor and successors from an adjacency matrix

    - by NickTFried
    Hi I am am trying to complete an assignment, where it is ok to consult the online community. I have to create a graph class that ultimately can do Breadth First Search and Depth First Search. I have been able to implement those algorithms successfully however another requirement is to be able to get the successors and predecessors and detect if two vertices are either predecessors or successors for each other. I'm having trouble thinking of a way to do this. I will post my code below, if anyone has any suggestions it would be greatly appreciated. import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedList; import java.util.Queue; import java.util.Stack; public class Graph<T> { public Vertex<T> root; public ArrayList<Vertex<T>> vertices=new ArrayList<Vertex<T>>(); public int[][] adjMatrix; int size; private ArrayList<Vertex<T>> dfsArrList; private ArrayList<Vertex<T>> bfsArrList; public void setRootVertex(Vertex<T> n) { this.root=n; } public Vertex<T> getRootVertex() { return this.root; } public void addVertex(Vertex<T> n) { vertices.add(n); } public void removeVertex(int loc){ vertices.remove(loc); } public void addEdge(Vertex<T> start,Vertex<T> end) { if(adjMatrix==null) { size=vertices.size(); adjMatrix=new int[size][size]; } int startIndex=vertices.indexOf(start); int endIndex=vertices.indexOf(end); adjMatrix[startIndex][endIndex]=1; adjMatrix[endIndex][startIndex]=1; } public void removeEdge(Vertex<T> v1, Vertex<T> v2){ int startIndex=vertices.indexOf(v1); int endIndex=vertices.indexOf(v2); adjMatrix[startIndex][endIndex]=1; adjMatrix[endIndex][startIndex]=1; } public int countVertices(){ int ver = vertices.size(); return ver; } /* public boolean isPredecessor( Vertex<T> a, Vertex<T> b){ for() return true; }*/ /* public boolean isSuccessor( Vertex<T> a, Vertex<T> b){ for() return true; }*/ public void getSuccessors(Vertex<T> v1){ } public void getPredessors(Vertex<T> v1){ } private Vertex<T> getUnvisitedChildNode(Vertex<T> n) { int index=vertices.indexOf(n); int j=0; while(j<size) { if(adjMatrix[index][j]==1 && vertices.get(j).visited==false) { return vertices.get(j); } j++; } return null; } public Iterator<Vertex<T>> bfs() { Queue<Vertex<T>> q=new LinkedList<Vertex<T>>(); q.add(this.root); printVertex(this.root); root.visited=true; while(!q.isEmpty()) { Vertex<T> n=q.remove(); Vertex<T> child=null; while((child=getUnvisitedChildNode(n))!=null) { child.visited=true; bfsArrList.add(child); q.add(child); } } clearVertices(); return bfsArrList.iterator(); } public Iterator<Vertex<T>> dfs() { Stack<Vertex<T>> s=new Stack<Vertex<T>>(); s.push(this.root); root.visited=true; printVertex(root); while(!s.isEmpty()) { Vertex<T> n=s.peek(); Vertex<T> child=getUnvisitedChildNode(n); if(child!=null) { child.visited=true; dfsArrList.add(child); s.push(child); } else { s.pop(); } } clearVertices(); return dfsArrList.iterator(); } private void clearVertices() { int i=0; while(i<size) { Vertex<T> n=vertices.get(i); n.visited=false; i++; } } private void printVertex(Vertex<T> n) { System.out.print(n.label+" "); } }

    Read the article

  • Which method should I use ?

    - by Ivan
    I want to do this exercise but I don't know exactly which method should I use for an exercise like this and what data will I use to test the algorithm. The driving distance between Perth and Adelaide is 1996 miles. On the average, the fuel consumption of a 2.0 litre 4 cylinder car is 8 litres per 100 kilometres. The fuel tank capacity of such a car is 60 litres. Design and implement a JAVA program that prompts for the fuel consumption and fuel tank capacity of the aforementioned car. The program then displays the minimum number of times the car’s fuel tank has to be filled up to drive from Perth to Adelaide. Note that 62 miles is equal to 100 kilometres. What data will you use to test that your algorithm works correctly?

    Read the article

  • Error codes for C++

    - by billy
    #include <iostream> #include <iomanip> using namespace std; //Global constant variable declaration const int MaxRows = 8, MaxCols = 10, SEED = 10325; //Functions Declaration void PrintNameHeader(ostream& out); void Fill2DArray(double ary[][MaxCols]); void Print2DArray(const double ary[][MaxCols]); double GetTotal(const double ary[][MaxCols]); double GetAverage(const double ary[][MaxCols]); double GetRowTotal(const double ary[][MaxCols], int theRow); double GetColumnTotal(const double ary[][MaxCols], int theRow); double GetHighestInRow(const double ary[][MaxCols], int theRow); double GetLowestInRow(const double ary[][MaxCols], int theRow); double GetHighestInCol(const double ary[][MaxCols], int theCol); double GetLowestInCol(const double ary[][MaxCols], int theCol); double GetHighest(const double ary[][MaxCols], int& theRow, int& theCol); double GetLowest(const double ary[][MaxCols], int& theRow, int& theCol); int main() { int theRow; int theCol; PrintNameHeader(cout); cout << fixed << showpoint << setprecision(1); srand(static_cast<unsigned int>(SEED)); double ary[MaxRows][MaxCols]; cout << "The seed value for random number generator is: " << SEED << endl; cout << endl; Fill2DArray(ary); Print2DArray(ary); cout << " The Total for all the elements in this array is: " << setw(7) << GetTotal(ary) << endl; cout << "The Average of all the elements in this array is: " << setw(7) << GetAverage(ary) << endl; cout << endl; cout << "The sum of each row is:" << endl; for(int index = 0; index < MaxRows; index++) { cout << "Row " << (index + 1) << ": " << GetRowTotal(ary, theRow) << endl; } cout << "The highest and lowest of each row is: " << endl; for(int index = 0; index < MaxCols; index++) { cout << "Row " << (index + 1) << ": " << GetHighestInRow(ary, theRow) << " " << GetLowestInRow(ary, theRow) << endl; } cout << "The highest and lowest of each column is: " << endl; for(int index = 0; index < MaxCols; index++) { cout << "Col " << (index + 1) << ": " << GetHighestInCol(ary, theRow) << " " << GetLowestInCol(ary, theRow) << endl; } cout << "The highest value in all the elements in this array is: " << endl; cout << GetHighest(ary, theRow, theCol) << "[" << theRow << "]" << "[" << theCol << "]" << endl; cout << "The lowest value in all the elements in this array is: " << endl; cout << GetLowest(ary, theRow, theCol) << "[" << theRow << "]" << "[" << theCol << "]" << endl; return 0; } //Define Functions void PrintNameHeader(ostream& out) { out << "*******************************" << endl; out << "* *" << endl; out << "* C.S M10A Spring 2010 *" << endl; out << "* Programming Assignment 10 *" << endl; out << "* Due Date: Thurs. Mar. 25 *" << endl; out << "*******************************" << endl; out << endl; } void Fill2DArray(double ary[][MaxCols]) { for(int index1 = 0; index1 < MaxRows; index1++) { for(int index2= 0; index2 < MaxCols; index2++) { ary[index1][index2] = (rand()%1000)/10; } } } void Print2DArray(const double ary[][MaxCols]) { cout << " Column "; for(int index = 0; index < MaxCols; index++) { int column = index + 1; cout << " " << column << " "; } cout << endl; cout << " "; for(int index = 0; index < MaxCols; index++) { int column = index +1; cout << "----- "; } cout << endl; for(int index1 = 0; index1 < MaxRows; index1++) { cout << "Row " << (index1 + 1) << ":"; for(int index2= 0; index2 < MaxCols; index2++) { cout << setw(6) << ary[index1][index2]; } } } double GetTotal(const double ary[][MaxCols]) { double total = 0; for(int theRow = 0; theRow < MaxRows; theRow++) { total = total + GetRowTotal(ary, theRow); } return total; } double GetAverage(const double ary[][MaxCols]) { double total = 0, average = 0; total = GetTotal(ary); average = total / (MaxRows * MaxCols); return average; } double GetRowTotal(const double ary[][MaxCols], int theRow) { double sum = 0; for(int index = 0; index < MaxCols; index++) { sum = sum + ary[theRow][index]; } return sum; } double GetColumTotal(const double ary[][MaxCols], int theCol) { double sum = 0; for(int index = 0; index < theCol; index++) { sum = sum + ary[index][theCol]; } return sum; } double GetHighestInRow(const double ary[][MaxCols], int theRow) { double highest = 0; for(int index = 0; index < MaxCols; index++) { if(ary[theRow][index] > highest) highest = ary[theRow][index]; } return highest; } double GetLowestInRow(const double ary[][MaxCols], int theRow) { double lowest = 0; for(int index = 0; index < MaxCols; index++) { if(ary[theRow][index] < lowest) lowest = ary[theRow][index]; } return lowest; } double GetHighestInCol(const double ary[][MaxCols], int theCol) { double highest = 0; for(int index = 0; index < MaxRows; index++) { if(ary[index][theCol] > highest) highest = ary[index][theCol]; } return highest; } double GetLowestInCol(const double ary[][MaxCols], int theCol) { double lowest = 0; for(int index = 0; index < MaxRows; index++) { if(ary[index][theCol] < lowest) lowest = ary[index][theCol]; } return lowest; } double GetHighest(const double ary[][MaxCols], int& theRow, int& theCol) { theRow = 0; theCol = 0; double highest = ary[theRow][theCol]; for(int index = 0; index < MaxRows; index++) { for(int index1 = 0; index1 < MaxCols; index1++) { double highest = 0; if(ary[index1][theCol] > highest) { highest = ary[index][index1]; theRow = index; theCol = index1; } } } return highest; } double Getlowest(const double ary[][MaxCols], int& theRow, int& theCol) { theRow = 0; theCol = 0; double lowest = ary[theRow][theCol]; for(int index = 0; index < MaxRows; index++) { for(int index1 = 0; index1 < MaxCols; index1++) { double lowest = 0; if(ary[index1][theCol] < lowest) { lowest = ary[index][index1]; theRow = index; theCol = index1; } } } return lowest; } . 1>------ Build started: Project: teddy lab 10, Configuration: Debug Win32 ------ 1>Compiling... 1>lab 10.cpp 1>c:\users\owner\documents\visual studio 2008\projects\teddy lab 10\teddy lab 10\ lab 10.cpp(46) : warning C4700: uninitialized local variable 'theRow' used 1>c:\users\owner\documents\visual studio 2008\projects\teddy lab 10\teddy lab 10\ lab 10.cpp(62) : warning C4700: uninitialized local variable 'theCol' used 1>Linking... 1> lab 10.obj : error LNK2028: unresolved token (0A0002E0) "double __cdecl GetLowest(double const (* const)[10],int &,int &)" (?GetLowest@@$$FYANQAY09$$CBNAAH1@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ) 1> lab 10.obj : error LNK2019: unresolved external symbol "double __cdecl GetLowest(double const (* const)[10],int &,int &)" (?GetLowest@@$$FYANQAY09$$CBNAAH1@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ) 1>C:\Users\owner\Documents\Visual Studio 2008\Projects\ lab 10\Debug\ lab 10.exe : fatal error LNK1120: 2 unresolved externals 1>Build log was saved at "file://c:\Users\owner\Documents\Visual Studio 2008\Projects\ lab 10\teddy lab 10\Debug\BuildLog.htm" 1>teddy lab 10 - 3 error(s), 2 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    Read the article

  • JOptionPane opening another JFrame

    - by mike_hornbeck
    So I'm continuing my fight with this : http://stackoverflow.com/questions/2923545/creating-java-dialogs/2926126 task. Now my JOptionPane opens new window with envelope overfiew, but I can't change size of this window. Also I wanted to have sender's data in upper left corner, and receiver's data in bottom right. How can I achieve that ? There is also issue with OptionPane itself. After I click 'OK' it opens small window in the upper left corner of the screen. What is this and why it's appearing ? My code: import java.awt.*; import java.awt.Font; import javax.swing.*; public class Main extends JFrame { private static JTextField nameField = new JTextField(20); private static JTextField surnameField = new JTextField(); private static JTextField addr1Field = new JTextField(); private static JTextField addr2Field = new JTextField(); private static JComboBox sizes = new JComboBox(new String[] { "small", "medium", "large", "extra-large" }); public Main(){ JPanel mainPanel = new JPanel(); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); getContentPane().add(mainPanel); JPanel addrPanel = new JPanel(new GridLayout(0, 1)); addrPanel.setBorder(BorderFactory.createTitledBorder("Receiver")); addrPanel.add(new JLabel("Name")); addrPanel.add(nameField); addrPanel.add(new JLabel("Surname")); addrPanel.add(surnameField); addrPanel.add(new JLabel("Address 1")); addrPanel.add(addr1Field); addrPanel.add(new JLabel("Address 2")); addrPanel.add(addr2Field); mainPanel.add(addrPanel); mainPanel.add(new JLabel(" ")); mainPanel.add(sizes); String[] buttons = { "OK", "Cancel"}; int c = JOptionPane.showOptionDialog( null, mainPanel, "My Panel", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, buttons, buttons[0] ); if(c ==0){ new Envelope(nameField.getText(), surnameField.getText(), addr1Field.getText() , addr2Field.getText(), sizes.getSelectedIndex()); } setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); pack(); setVisible(true); } public static void main(String[] args) { new Main(); } } class Envelope extends JFrame { private final int SMALL=0; private final int MEDIUM=1; private final int LARGE=2; private final int XLARGE=3; public Envelope(String n, String s, String a1, String a2, int i){ Container content = getContentPane(); JPanel mainPanel = new JPanel(); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); mainPanel.add(new JLabel("John Doe")); mainPanel.add(new JLabel("FooBar str 14")); mainPanel.add(new JLabel("Newark, 45-99")); JPanel dataPanel = new JPanel(); dataPanel.setFont(new Font("sansserif", Font.PLAIN, 32)); //set size from i mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); mainPanel.setBackground(Color.ORANGE); mainPanel.add(new JLabel("Mr "+n+" "+s)); mainPanel.add(new JLabel(a1)); mainPanel.add(new JLabel(a2)); content.setSize(450, 600); content.setBackground(Color.ORANGE); content.add(mainPanel, BorderLayout.NORTH); content.add(dataPanel, BorderLayout.SOUTH); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); pack(); setVisible(true); } }

    Read the article

  • Tricky Big-O complexity

    - by timeNomad
    public void foo (int n, int m) { int i = m; while (i > 100) i = i/3; for (int k=i ; k>=0; k--) { for (int j=1; j<n; j*=2) System.out.print(k + "\t" + j); System.out.println(); } } I figured the complexity would be O(logn). That is as a product of the inner loop, the outer loop -- will never be executed more than 100 times, so it can be omitted. What I'm not sure about is the while clause, should it be incorporated into the Big-O complexity? For very large i values it could make an impact, or arithmetic operations, doesn't matter on what scale, count as basic operations and can be omitted?

    Read the article

  • Java Iterators - Trying to get a for each loop to work

    - by CS Student
    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?

    Read the article

  • Having trouble with a small example from school

    - by Kalec
    The example is from a course, it's for comparing two objects in java: public class Complex { ... public boolean equals (Object obj) { if (obj instanceof Complex) { // if obj is "Complex" (complex number) Complex c = (Complex) obj // No idea return (real == c.real) && (imag == c.imag); // I'm guessing real means [this].real } return false; } } So, my question is: "what does this: Complex c = (Complex) obj actually mean" ? Also I've worked with python and c++, java is new for me.

    Read the article

  • Detecting what changed in an HTML Textfield

    - by teehoo
    For a major school project I am implementing a real-time collaborative editor. For a little background, basically what this means is that two(or more) users can type into a document at the same time, and their changes are automatically propagated to one another (similar to Etherpad). Now my problem is as follows: I want to be able to detect what changes a user carried out onto an HTML textfield. They could: Insert a character Delete a character Paste a string of characters Cut a string of characters I want to be able to detect which of these changes happened and then notify other clients similar to "insert character 'c' at position 2" etc. Anyway I was hoping to get some advice on how I would go about implementing the detection of these changes? My first attempt was to consider the carot position before and after a change occurred, but this failed miserably. For my second attempt I was thinking about doing a diff on the entire contents of the textfields old and new value. Am I missing anything obvious with this solution? Is there something simpler?

    Read the article

  • Convert VB.NET code to C#

    - by Sorush Rabiee
    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.

    Read the article

  • AccessControlException: access denied - caller function failed to load properties file

    - by Michael Mao
    Hi all: I am having a jar archive environment which is gonna call my class in a folder like this: java -jar "emarket.jar" ../tournament 100 My compiled class is deployed into the ../tournament folder, this command runs well. After I changed my code to load a properties file, it gets the following exception message: Exception in thread "main" java.security.AccessControlException: access denied (java.io.FilePermission agent.properties read) at java.security.AccessControlContext.checkPermission(Unknown Source) at java.security.AccessController.checkPermission(Unknown Source) at java.lang.SecurityManager.checkPermission(Unknown Source) at java.lang.SecurityManager.checkRead(Unknown Source) at java.io.FileInputStream.<init>(Unknown Source) at java.io.FileInputStream.<init>(Unknown Source) at Agent10479475.getPropertiesFromConfigFile(Agent10479475.java:110) at Agent10479475.<init>(Agent10479475.java:100) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at java.lang.Class.newInstance0(Unknown Source) at java.lang.Class.newInstance(Unknown Source) at emarket.client.EmarketSandbox.instantiateClientObjects(EmarketSandbox.java:92) at emarket.client.EmarketSandbox.<init>(EmarketSandbox.java:27) at emarket.client.EmarketSandbox.main(EmarketSandbox.java:166) I am wondering why this security checking will fail. I issue the getPropertitiesFromConfigFile() function inside my class's default constructor, like this: public class Agent10479475 extends AbstractClientAgent { //default constructor public Agent10479475() { //set all properties to their default values in constructor FT_THRESHOLD = 400; FT_THRESHOLD_MARGIN = 50; printOut("Now loading properties from a config file...", ""); getPropertiesFromConfigFile(); printOut("Finished loading",""); } private void getPropertiesFromConfigFile() { Properties props = new Properties(); try { props.load(new FileInputStream("agent.properties")); FT_THRESHOLD = Long.parseLong(props.getProperty("FT_THRESHOLD")); FT_THRESHOLD_MARGIN = Long.parseLong(props.getProperty("FT_THRESHOLD_MARGIN ")); } catch(java.io.FileNotFoundException fnfex) { printOut("CANNOT FIND PROPERTIES FILE :", fnfex); } catch(java.io.IOException ioex) { printOut("IOEXCEPTION OCCURED :", ioex); } } } My class is loading its own .properties file under the same folder. why would the Java environment complains about such a denial of access? Must I config the emarket.client.EmarketSandbox class, which is not written by me and stored inside the emarket.jar, to access my agent.properties file? Any hints or suggestions is much appreciated. Many thanks in advance.

    Read the article

  • A[i] * A[j] = k in O(nlog(n))

    - by gleb-pendler
    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.

    Read the article

  • Intel IA-32 Assembly

    - by Kay
    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.

    Read the article

  • Using pipes in Linux with C

    - by Dave
    Hi, I'm doing a course in Operating Systems and we're supposed to learn how to use pipes to transfer data between processes. We were given this simple piece of code which demonstrates how to use pipes,but I'm having difficulty understanding it. #include <stdio.h> #include <stdlib.h> #include <unistd.h> main() { int pipefd [2], n; char buff[100] ; if( pipe( pipefd) < 0) { printf("can not create pipe \n"); } printf("read fd = %d, write fd = %d \n", pipefd[0], pipefd[1]); if ( write (pipefd[1],"hello world\n", 12)!= 12) { printf("pipe write error \n"); } if( ( n = read ( pipefd[0] , buff, sizeof ( buff) ) ) <= 0 ) { printf("pipe read error \n"); } write ( 1, buff, n ) ; exit (0); } What does the write function do? It seems to send data to the pipe and also print it to the screen (at least it seems like the second time the write function is called it does this). Does anyone have any suggestions of good websites for learning about topics such as this, FIFO, signals, other basic linux commands used in C?

    Read the article

  • Trying to sentinel loop this program.

    - by roger34
    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; } }

    Read the article

  • Checking a set of listbox items against a text box vb.net

    - by Shane Fagan
    Hi all I have this code to check if an item from a textbox is in a listbox and its giving me the error at the bottom. Any ideas what im doing wrong? I copied it from another part of my project and it was working for that part so I cant see whats wrong. If LocationsSearchTextBox.Text <> "" And LocationListBox.Items.Count > 0 Then tempInt = 0 While (tempInt < ClientListBox.Items.Count) If LocationListBox.Items(tempInt).ToString.Contains(LocationsSearchTextBox.Text) = False Then LocationListBox.Items.RemoveAt(tempInt) End If tempInt += 1 End While End If System.ArgumentOutOfRangeException was unhandled Message="InvalidArgument=Value of '2' is not valid for 'index'. Parameter name: index" ParamName="index" Source="System.Windows.Forms" StackTrace: at System.Windows.Forms.ListBox.ObjectCollection.get_Item(Int32 index) at AuctioneerProject.Viewing.LocationsSearchTextBox_KeyPress(Object sender, KeyPressEventArgs e) in C:\Users\admin\Desktop\Auctioneers\AuctioneerProject\AuctioneerProject\Viewing.vb:line 301 at System.Windows.Forms.Control.OnKeyPress(KeyPressEventArgs e) at System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m) at System.Windows.Forms.Control.ProcessKeyMessage(Message& m) at System.Windows.Forms.Control.WmKeyChar(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.TextBoxBase.WndProc(Message& m) at System.Windows.Forms.TextBox.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(ApplicationContext context) at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine) at AuctioneerProject.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81 at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException:

    Read the article

  • CSS precedence order? My lecture slides are correct or not?

    - by Michael Mao
    Hi all: I've noticed that there are a couple of similar questions and answers at SO already, but let me clarify my specific question here first: I've got lecture slides which states like this: To be frank, I haven't heard of this rule of css precedence myself, and I googled to find something with similar topic but not quite like that : here To have a test myself, I've made a test page on my own server here After running it on FireFox 3.6.3, I am sure it does not show the way as it should be, according to the statement in lecture slides: imported stylesheet ? am I doing it wrong? I cannot see its effect using FireBug it says that embedded stylesheet has a higher precedence over linked/imported stylesheets, however, it doesn't work, if I put the linked/imported tag AFTER that. inline style vs html attributes ? I've got an image where I firstly set its inline style to control the width and height, then use direct html attributes width/height to try modifying that, but failed... Below is the source code : <html> <head> <style type="text/css"> #target { border : 2px solid green; color : green; } </style> <link rel="stylesheet" href="./linked.css" type="text/css" media="screen" /> </head> <body> <div id="target">A targeted div tag on page.</div> <img src="cat.jpg" alt="" style="width : 102px; height : 110px;" width="204px" height="220px" /> </body> </html> Can any experienced CSS guys help me figure out if the slide is correct or not? Frankly speaking, I am puzzled myself, as I can clearly see some other "incorrect" statements here and there amongst the slides, such as JavaScript is on client-side (how about server-side JavaScript?) and "Embedded styles are in the head section of a web page "(what the heck? I am not allowed to put it inside the body tag?) Sorry about this silly question, the exam is on TOMORROW, and I now see a lot of things to think about :)

    Read the article

< Previous Page | 15 16 17 18 19 20 21 22 23 24 25 26  | Next Page >