Latest Posts in Software Development

Re: in C++
 
0
 

Not exactly; as was explained above, in the old Borland C++ compilers, there was a macro actually called randomize() that was basically a shortcut for both initializing the randomizer and returning a random value. While I don't know the actual implementation, I'm guessing it was something along the lines of

#define randomize(n) srand(time(NULL)); n = rand();

If anyone could give more details, it would be... oh, who am I kidding? It wouldn't be worth much of anything to know exactly, since it is basically a dead issue for anyone using a standards-compliant compiler and library.

Re: in C++
 
0
 

deleted for duplicate post

Re: in C++
 
0
 

rose_2: While your enthusiasm for answering the question is commendable, it is generally considered a poor practice to provide outright answers to problems when the OP hasn't demonstrated that they had already made a good-faith effort to solve the problem before posting here - it encourages cheating, or at least a lack of effort, and does little to actually help the students learn to program.

This can be a fine line at times - one I and most of the other regulars have inadvertently crossed at one time or another - but this particular instance is clear-cut: the OP basically posted their problem set without any indication that they had done any work on it themselves, for an assignment that shouldn't have required more than a token effort to solve.

gencc: Seriously, you needed to even consider this? You probably could have done it yourself in less time than it took to post the question, and yet you felt you needed to beg for a hand-out? This is a sign of a student who belongs in a different major, or maybe out of college entirely. If I knew who your professor was, I would e-mail them a link to this thread straight away and let the consequences fall on you for your lack of academic honesty.

in Java
 
0
 

my code is as follows:

class pottertr_Point{
private String name;
private double x;
private double y;
public pottertr_Point(){
name="Org";
x=(0);
y=(0);
}
public pottertr_Point getPoint(){
    pottertr_Point p= new pottertr_Point();
    p.name=this.name;
    p.x=this.x;
    p.y=this.y;
    return p ;

}
public void setPoint(pottertr_Point p){
    this.name=p.name;
    this.x=p.x;
    this.y=p.y;

}
public void setName(String name){
    this.name=name;

}
public void setX(double x){
    this.x=x;
}
public void setY(double y){
    this.y=y;

}
public String getName(){
    return name;
}
public double getX(){
    return x;
}
public double getY(){
    return y;
}

public double distance(pottertr_Point p){
    double distance;
    distance= Math.sqrt((this.x-p.x)*(this.x-p.x)+(this.y-p.y)*(this.y-p.y));
    return distance;

}

}

public class Program5{
    public static void main(String[] args){
    pottertr_Point [] p =new pottertr_Point[3];
    //pottertr_Point pp=new pottertr_Point();
    String s=new String ("");
    //p[0].setName(pp);

        for (int i=0; i<3;i++){
        s="p"+i;
        p[i].setName(s);
        p[i].setX(getCoordinate());
        p[i].setY(getCoordinate());
        System.out.println(p[i].getName()+", coordinate: (" + p[i].getX() + "," + p[i].getY());

    }
        for (int i=0;i<3;i++){
        for (int j=i+1;j<3;j++){
            System.out.println(p[i].getName()+ p[j].getName()+"distance"+p[i].distance(p[j])); 
        }
    }

    }   

    public static double getCoordinate(){
    double r;
        r=((int)(Math.random()*1.1))*10;
    return r;   
    }

}

the error is at line 66 which is p[i].setName(s);
the error is java.lang.NullPointerException
any help will be useful. thank you.

Re: in C++
 
0
 

do u mean that ???

#include<iostream>
#include<iomanip>
#include<cstdlib> //contains function prototype for rand
using namespace std;
int main()
{
    //example for loop 20 times
    for(int count=0;count<20;count++){
        cout<<setw(10)<<1+rand() %6;
        if(count%5==0)
            cout<<endl;
    }
    return 0;
}   
Re: in C++
 
-2
 
#include<iostream>
using namespace std;
double power(int x,int n)
{
    int power=1;
    for(int count=1;count<=n;count++)
        power=power*x;
    return power;
}
int main()
{
    int a; int b;
    cout<<"enter the base :";
    cin>>a;
    cout<<"enter the exp :";
    cin>>b;
    cout<<a<<"^"<<b<<"="<<power(a,b)
    return 0;
}   
in C#
 
0
 

How to repeat the column header on each page on Microsoft report? I have a report on which I have to group results by the project and I want to repeat the column header on each page I searched the internet and all the people are saying there by setting the KeepWithGroup to after, RepeatOnNewPage to ture, and FixedData to true does not work with me and a compliation error occured informing me to return all these properties to their default again!!! I tried all the people say but nothing working with me can any one how to repeat the column header on each page

in C++
 
-1
 

who can help me on solvin this problem in c++ by not using math.h only a function;
problem:x^n

Re: in Java
 
0
 

By now your probably snug in bed, but it did work and I've got it working, thank you again.

Re: in Java
 
0
 

The usual way to read a text file is to try to read the line and test for null/EOF at the same time, ie

String line;
while ((line=br.readLine()) != null) {
  // do something with line
}

anyway, I'm off to bed now. Nighty night. J

Re: in Java
 
0
 
public static void main(String[] args) {
        int index = 0;
        int oldIndex;
        int language;
        int play = 1;
        int score;
        int lineCount = 0;
        ArrayList engList = new ArrayList();
        ArrayList deuList = new ArrayList();
        String answer;
        String line = "";
        Scanner sc = new Scanner(System.in);
        BufferedReader br;
        try{
            br = new BufferedReader(new FileReader("C:\\Users\\Patrick\\Desktop\\Java Workspace\\germanTool\\src\\germanTool\\lesson1.txt"));
            while (line != null){
                lineCount++;
                line = br.readLine();
                engList.add((line.split(";")[0]));
                deuList.add((line.split(";")[1]));
            }
        }catch(IOException e1){
            System.out.println("NO");
        }

Here is more of my code. I don't understand what I have to do to make it work.

Re: in VB.NET
 
0
 

No,just the columns(cell and the name of the column i selected from combobox)
add to datagrid
datasource is variable because any time i select from the combobox, the column will be added to datagrid

Re: in Java
 
0
 

You still need to create those lists - just declaring the variables isn't enough. (Maybe you just didnlt post that part of the code.)
Also
watch out for your readLines...
starting from the beginning of your loop...
line 2 reads the first line, and discards it
line 4 reads the second line (if there is one) and uses it
line 2 reads the third line, and discards it
line reads the fourth line (if there is one) and uses it
(etc)
ie every call to readLine() reads another line (until you reach EOF, when it reurns null - which may then cause a NullPointerException)

Re: in VB.NET
 
0
 

when i select a column from combobox it will be added to datagrid
this 2 column of this worksheet which named the name of the column i select :

What do you mean by this. Do you only want to select data from the second column? For example, do a Max on the second column? If so, you could do SELECT MAX ([2]) As MaxOf2 FROM [KPI2$], is that what you mean, or did you mean something else.

Re: in Java
 
0
 
br = new BufferedReader(new FileReader("C:\\Users\\Patrick\\Desktop\\Java Workspace\\germanTool\\src\\germanTool\\lesson1.txt"));
            while (br.readLine() != null){
                lineCount++;
                line = br.readLine();
                engList.add((line.split(";")[0]));
                deuList.add((line.split(";")[1]));

I've altered the code, as well as making the file itself use semi-colons for seperation. Now the code gets unhappy and gives me this:
java.lang.NullPointerException

Re: in Java
 
0
 

It's a class in the standard Java API that holds a list of values, like an array, but it grows automatically to fit whatever data you put in it. In this case you don't know in advance how many lines there will be in the file, so it's hard to guess how big your arrays need to be. With an ArrayList you don't need to worry about that.
https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html

Re: in C++
 
1
 

I would add that the Travelling Salesman Problem (which this could be, depending on you interpret the traversal requirement) is known to be an NP-Hard problem, so even if you succeed in getting it to work, it may have quite a long run time depending on how many nodes the graph has to cover. Of course, you could just try proving P=NP and thus showing that a shorter run time may be possible, but that's rather a tall order to fill...

Comments
As in a PhD thesis problem? :-)
Re: in Java
 
0
 

That code is mostly OK.
If you use i to index into the arrays to add the words (lines 8,9) then you need to increment it after processing each line (like lineCount).
Lines 2 and 3 create two variables that can refer to String arrays, but you haven't actually created any arrays. To create an array you need the new keyword, as in (eg)

String[] engList = new String[100]; // creates array with 100 elements

The problem is that you have to guess how big to make the array - which is why people tend to use classes like ArrayList rather than simple arrays.

Software Development Tag Cloud