samedi 29 novembre 2014

Integer getch() -'0'


Vote count:

0




I've created a sudoku game in which you will enter the row number then the column number. I set an if else condition that only numbers 1-9 will be entered. I used getch function instead of cin after entering a number to avoid using the enter button.


But when I enter 1 in row, it won't accept it and it prints the number 49. I've researched about it and learned that getch function is for get character and if you enter 1, it will translate to '1' which is equivalent of 49 in integer. I've found a solution by using getch() -'0' instead of only getch();


It works but I can't seem to understand the explanation about how it works. Can someone explain it how the getch() -'0' works?


Here's where I used the getch() -'0':



cout << "Enter row: "; row = getch() -'0';
if(row > 9 || row < 1) {
cout << "Rows 1 to 9 only!" << endl;
Sleep(1000);
system("cls");
loop -= 1;
} else {
cout << row << "\nEnter column: "; column = getch() -'0';
if(column > 9 || column < 1) {
cout << "Columns 1 to 9 only!" << endl;
Sleep(1000);
system("cls");
loop -= 1;
}


asked 36 secs ago







Integer getch() -'0'

C - Semaphore Rights Issue


Vote count:

0




I tried to allow other user's program to modify my semaphore ( Basically remove it) , but It is failing.


Below is my semaphore creation command:



if ((semID = semget(key, 2, IPC_CREAT | 0777)) == -1) {
perror("Sem Creation:");
exit(2);
}


Still programs which are run by other's users are unable to delete semaphore with error that " Not owner"



asked 38 secs ago







C - Semaphore Rights Issue

I can't load Plupload 2.1.2 in my ColdFusion page


Vote count:

0




I'm seeing a Javascript error that's preventing PlUpload from working in my ColdFusion page. I've reduced the code down to the simplest example that shows the error. As you can see there isn't actually any ColdFusion in the code in this stripped down example. This is Plupload 2.1.2 that I'm using.


The html code below in a test.htm page loads without error. But if I change the file name to test.cfm it causes this javascript error:


"SyntaxError: missing } after property list" @ line 1056 column 14 in the jquery.ui.plupload.js file.


Firebug shows the live example as being "width: Â self.options.thumb_width,". It looks like "Â " is being inserted somehow in front of the "self.options.thumb_width" variable so it isn't being handled correctly.


I'm stymied; can anyone help?



<!doctype html>
<html>
<head>
<title>Test</title>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/base/jquery-ui.css" type="text/css" />
<link rel="stylesheet" href="js/jquery.ui.plupload/css/jquery.ui.plupload.css" type="text/css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
<script type="text/javascript" src="js/plupload.full.min.js"></script>
<script type="text/javascript" src="js/jquery.ui.plupload/jquery.ui.plupload.js"></script>
</head>
<body>
</body>
</html>


asked 20 secs ago







I can't load Plupload 2.1.2 in my ColdFusion page

Take a string and use it as pure HTML?


Vote count:

0




This might be REALLY stupid to ask, but who cares?


Lets say I have a string called Test, and its value is:





<img src=test.gif></img>

<p> Testing 123 </p>



Is it possible somehow to use it as code since HTML isn't compiled?



asked 1 min ago







Take a string and use it as pure HTML?

Getting paintComponent elements of a JPanel to work with another JPanel inside of it


Vote count:

0




I have a JPanel with a simple animated snow particle effect inside of a JFrame, and it works from on its own. But when I try and add another JPanel to it, it makes the effect of the snow stop. Can anyone help me with this? Is it a problem with layering, or something? Or is it an issue with my Layout Managers?


My Code: package christmasfinal;



import java.awt.*;
import javax.swing.*;

public class ChristmasFinal extends JApplet {

public static void main(String[] args) {
JFrame frame = new JFrame();
TreePanel treePanel = new TreePanel();
frame.setSize(550, 420);
SnowBackgroundPanel snowPanel = new SnowBackgroundPanel(frame.getWidth(), frame.getHeight());
treePanel.setSize(200, 320);
snowPanel.setSize(frame.getWidth(), frame.getHeight());
snowPanel.setLayout(new BorderLayout());
frame.setLayout(new BorderLayout());
frame.add(snowPanel, BorderLayout.CENTER);
snowPanel.add(treePanel, BorderLayout.CENTER);
System.out.println(treePanel.getWidth() + " " + treePanel.getHeight());

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setTitle("Christmas Final");
}

}


package christmasfinal;

import javax.swing.*;
import java.awt.*;

public class TreePanel extends JPanel{

@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
int[] treeX = {getWidth()/2, getWidth()/2-20, getWidth()/2-60, getWidth()/2-20,
getWidth()/2-40, getWidth()/2-80, getWidth()/2-20, getWidth()/2-60, getWidth()/2-100,
getWidth()/2+100,getWidth()/2+60, getWidth()/2+20, getWidth()/2+80,
getWidth()/2+40, getWidth()/2+20, getWidth()/2+60, getWidth()/2+20, getWidth()/2};

int[] treeY = {getHeight()/2-120, getHeight()/2-80, getHeight()/2-40, getHeight()/2-40,
getHeight()/2-20, getHeight()/2, getHeight()/2, getHeight()/2+40, getHeight()/2+60,
getHeight()/2+60, getHeight()/2+40, getHeight()/2, getHeight()/2, getHeight()/2-20,
getHeight()/2-40, getHeight()/2-40, getHeight()/2-80, getHeight()/2-120};

g.setColor(Color.GREEN);
g.fillPolygon(treeX, treeY, treeX.length);
g.setColor(new Color(102, 51, 0));
g.fillRect(getWidth()/2-20, getHeight()/2+60, 40, 40);
}
}

package christmasfinal;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Random;
import java.math.*;

public class SnowBackgroundPanel extends JPanel{
Random rand = new Random();

//Create ArrayList for SnowParticles
ArrayList<SnowParticle> snow = new ArrayList();

//Create animation timer
Timer timer = new Timer(7, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
repaint();
}
});



public SnowBackgroundPanel(int width, int height){
setSize(width, height);
System.out.println(getHeight() + " " + getWidth());
for(int i=0; i<50; i++){
snow.add(new SnowParticle());
snow.get(i).x = rand.nextInt(getWidth()+1);
snow.get(i).y = 0-rand.nextInt(getHeight()+1);
}
timer.start();

}
@Override
public void paintComponent(Graphics g){
super.paintComponent(g);
g.setColor(Color.WHITE);

//Set, paint, and move snow particles
for(int i=0; i<50; i++){
g.fillOval(snow.get(i).x, snow.get(i).y, 10, 10);
snow.get(i).y += 1;
if(snow.get(i).y > getHeight()){
snow.get(i).x = rand.nextInt(getWidth()+1);
snow.get(i).y = 0-rand.nextInt(getHeight()+1);
}
}
}
}


asked 53 secs ago







Getting paintComponent elements of a JPanel to work with another JPanel inside of it

Class inherits from interface with extra property causes error


Vote count:

0




I understand that interfaces don't allow fields. But why can't the class that implements the interface have a property/field. I have tried researching the cause of this, but to no avail. Could someone point me to a resource that can help me.


Can classes only implement the method they inherit from the interface and nothing else?


Here is my code:



using System;

interface IDog
{
void Bark();
}

class Dog : IDog
{
public int numberOfLegs = 24;
public void Bark()
{
Console.WriteLine("Woof!");
}
}

class Program
{
static void Main()
{
IDog Fido = new Dog();
Fido.Bark();
Console.WriteLine("Fido has {0} legs", Fido.numberOfLegs);
}
}


I get the error:


'IDog' does not contain a definition for 'numberOfLegs' and no extension method 'numberOfLegs' accepting a first argument of type 'IDog' could be found (are you missing a using directive or an assembly reference?)



asked 45 secs ago







Class inherits from interface with extra property causes error

Can anyone please help me with these python program


Vote count:

0




printResults1('sandwich', 54)


The number of tweets containing sandwich is 54


printResults2('tea', 12, 'coffee', 14) #uses two print statements


The number of tweets containing tea is 12


The number of tweets containing coffee is 14


printResults3('tea', 12, 'coffee', 14) #uses two function calls to printResults1


The number of tweets containing tea is 12


The number of tweets containing coffee is 14


printResults4(['sandwich', 'tea', 'coffee'] ,[14, 56, 9]) #uses indexing and calls printResults1 three times


The number of tweets containing sandwich is 14


The number of tweets containing tea is 56


The number of tweets containing coffee is 9


printResults5(['sandwich', 'tea', 'coffee'] ,[14, 56, 9]) #uses indexing and a for loop, and has a single function call to printResults1


The number of tweets containing sandwich is 14


The number of tweets containing tea is 56


The number of tweets containing coffee is 9


What to Submit:


For this assignment, you should submit a single Python file (e.g. hw1.py) which contains


Header: comment lines on top (comments start with #) with your name and the homework number. Function Definitions: the definition of each of the above functions, and Function Calls: to test these functions with some parameter values (see the above for examples).



asked 16 secs ago







Can anyone please help me with these python program