highflyer8 Light Poster

Hi,

I recently placed about 3 GB worth of my university files on a USB drive. After a few days, I tried to access the files on the USB. So, I opened the 'My computer' folder, which is when I noticed that the removable drive showed '164 MB of 3.93 GB free' but there was a red bar (instead of blue) that signified the amount of space covered. I found that a little puzzling.

Anyway, I opened the USB drive to find that all my folders had become files. There was no symbol (i.e. it was empty) beside the names to indicate the program which would open the file. And each of them had 4.00 kB of space. I was in panic. And I was also surprised because although the USB had more than 3.00 GB covered, each of the folders(/files) was only 4.00 kB.

So, I clicked on Properties. Then I went to Tools to check the drive for errors. After the analysis, I found a hidden folder called FOUND.000. I found more than 5000 CHK files in it. I copied them to my Desktop, ran the Disk Defragmenter program on Windows and used Unchk to recover the data. The program recovered only the first 1192 files and a lot of them were in Winrar format (even though the original files were not). I could not recover the rest of the files.

I checked the USB drive for errors several time afterwards. After the first such analysis, FOUND.000 became ...

highflyer8

What is Dubya?

highflyer8 Light Poster

I don't quite understand the motivations behind the different forms of examination systems. For instance, in the UK, the GCSE and A level exams are held nationally by a set of examination boards. However, things are different here in the US. Exams till 12th grade are done locally.

What is this the case?

highflyer8 Light Poster

I'm wondering why lecturers at university select the problems they select in the problem sets? I don't understand why those problems have to be selected and not any others.

highflyer8 Light Poster

Let's say you have made a class called threevector which takes stores three doubles.

Then you define another class, a fourvector, which stores four doubles.

I have seen this syntax used for the constructor of the fourvector:

[CODE]fourvector(double fourth, threevector one_two_three): threevector (one_two_three)
{
fourth = 0.0;
}[/CODE]

I understand that the fourvector object takes in a double and a threevector as its arguments. But I haven't defined any constructor called threevector (one_two_three) in the threevector class. So what does the compiler do?

highflyer8 Light Poster

Hi, I don't understand the need for the while statement. Any help would be greatly appreciated.

[CODE]double michel()
{
double x, y;
do // The loop computes points on the graph of y against x.
{
x = 53.0rand()/RAND_MAX; // x is the momentum. x is randomly generated. Min x is 0 MeV/c. Max x is 53 MeV/c.
y = x/53.0; // y is the probability distribution function. Min y is 0. Max y is 1.
} // y is a triangular distribution. Hence, y = (1/53)
x.
while (1.0*rand()/RAND_MAX > y); // Because we want to start with the WHYYYYYYYYYYY????????????
return x;
}[/CODE]

highflyer8

I've written the above piece of code as part of a task. Would you please mind having a look at the code and checking for any possible errors or ways to improve the code?

Please! I'll upload the document if you wish.

highflyer8

Thanks!

How does the compiler interpret

[CODE]if (determinant = 'E')[/CODE]

anyway?

highflyer8 Light Poster

Hi, if I run the following code and press L on the screen, I should be getting a leapfrog.txt textfile. But I only see my previous euler.txt. What is wrong with the code.

Thanks in advance for any help.

[CODE]#include

include
include
include "H:\Visual Studio 2008\Projects\section2\threevector.h"

using namespace std;

void errors(double, threevector, ofstream&); // Function that calculates the errors
// and outputs the results

int main()
{
char determinant;
cout << "Press E to use Euler's method or L to use leapfrog method." << endl;
cin >> determinant;

if (determinant = 'E')                                            // Euler method
{
    ofstream outfile("euler.txt");
    outfile << "Time \t Vx \t Vy \t Vz \t Vxerror \t Vyerror \t Vzerror \t Vmagerror" << endl;

    threevector vn(0.0, 0.0, 2.0);                                    // Initial vector velocity
    threevector  b(1.0, 0.0, 0.0);                                    // Magnetic field
    double delta_t = 0.01;

    for (int i = 0; i < 2001; i++)                                    // Calculates the velocity from t = 0 to t = 20  
    {                                                                 //                         in steps of delta_t = 0.01
        double t = delta_t*i;                                         // Time
        if (t == 0.0)
        {
            errors(t, vn, outfile);
        }
        else
        {
            vn += ((vn^b)*delta_t);                                    // New velocity
            errors(t, vn, outfile);
        }
    }
}

else if (determinant = 'L')                                        // Leapfrog method
{
    ofstream outfile("leapfrog.txt");
    outfile << "Time \t Vx \t Vy \t Vz \t Vxerror \t Vyerror \t Vzerror \t Vmagerror" << endl;

    threevector vnminus1;                                               // where vnminus1 will be stored
    threevector vreserve;                                               // where vn       will be stored

    threevector vn(0.0, 0.0, 2.0);                                      // Initial vector ...

highflyer8 Light Poster

I am an undergraduate student and. I have been facing a difficulty with my studies for quite some time. I hope you wouldn't mind sparing a few minutes to advise me on this matter.

The problem is that whenever I read my lecture notes or a textbook or a labscript, I tend to question every single sentence in every paragraph. Also, I spend a lot of time trying to restructure the notes (by rewriting them again) so that the arguments flow smoothly and so that all the assumptions have been taken into account. This becomes a laborious task. As an example, here is an extract from a computing labscript.

[B]Create another project workspace called section4. From the course website, copy the file fourvector.h. This file will look as shown in Figure 6. Notice the mechanism in fourvector.h by which we specify the derived class inherits from the base class: class fourvector : public threevector. Notice that we need to #include the threevector.h file in fourvector.h so that the compiler knows about it when it reads the inheritance statement; this is why threevector.h is not needed in the main program (see Figure 7). Since the fourvector class inherits from the threevector class, then when we make a fourvector object, we are also making a threevector object implicitly at the same time. Hence, we have to specify the threevector constructor as part of the fourvector constructor. There are three constructors in the fourvector class and each calls the appropriate constructor from the ...

highflyer8

If I implement the above and other changes, then I have the following constructor:

[CODE]//Constructor
particle(double mass, double px, double py, double pz) : threevector(px, py, pz)
{
sett(sqrt( (pxpx) + (pypy) + (pzpz) + (massmass) )) ;
}[/CODE]

But still I get an error message:
'particle' : illegal member initialization: 'threevector' is not a base or member

What could be the problem?

highflyer8

px, py and pz?

highflyer8

The error message is for the constructor of the particle class. I don't know what's causing the mistake. Could someone please help?

highflyer8 Light Poster

Hi, I am getting an error message when using base classes. The error message is

x: undeclared identifier
y: undeclared identifier
z: undeclared identifier

The particle class derives from the fourvector class which derives from the threevector class, as follows.

[CODE]#ifndef THREEVECTOR_H // Prevents the class being re-defined

define THREEVECTOR_H
include // Include input/output stream

//#include

include

class threevector
{

private:
double xcoord, ycoord, zcoord; // Private data members
double scalar;

public:

// Default constructor
threevector() 
{
    xcoord = 0.0;
    ycoord = 0.0;
    zcoord = 0.0;
}
// Cartesian constructor
threevector(double x, double y, double z)
{
    xcoord = x;
    ycoord = y;
    zcoord = z;
}
// Polar Constructor
threevector(double r, double theta, double phi, char angletype)
{
    if (angletype == 'd')
    {
        double pi = acos (-1.0);
        phi  = (phi * pi) / 180; 
        theta = (theta * pi) / 180;
    }
    else 
    {}
    xcoord = r * sin(theta) * cos(phi) ;
    ycoord = r * sin(theta) * sin(phi) ;
    zcoord = r * cos(theta);
}
// Spherical polar constructor
/*threevector(double r, double theta, double phi, char angle_type)
{
    if ((angle_type == 'd') || (angle_type == 'r'))
    {
        if (angle_type == 'd')
        {
            double pi = acos(-1.0);
            phi *= (pi/180);  
            theta *= (pi/180);
        }
        else
        {}

        xcoord = r*sin(theta)*cos(phi);
        ycoord = r*sin(theta)*sin(phi);
        zcoord = r*cos(theta);
    }
    else
    {}
}*/

// Access method for coordinates
double getx()
{
    return xcoord;
}
double gety()
{
    return ycoord;
}
double getz()
{
    return zcoord;
}

// Access method ...

highflyer8

I know, but if I write

[CODE]outfile << "Mistaken angle type" << std::endl;[/CODE]

where outfile is the name of the object of class ofstream, the code gives an error message.

highflyer8

Thanks! I much rather prefer the if-else ladder.

I am wondering if there is a way to print an error message in the

[CODE]else{}[/CODE]

part of the if-else ladder.

highflyer8

"You'll have to find a better way to control that situation.":

Why? Isn't the code I have written any good? Sure, it does not return -9.25596e+061 when the input is not a 'd' or an 'r', but that number should signal that something is amiss. Please help me understand the motivation for improving the code and how to go about modifying it.

highflyer8

Thanks very much!

Let me ask one other question about a constructor I have created.

Here's the code:

[CODE] // Spherical polar constructor
threevector(double r, double theta, double phi, char angle_type)
{
if ((angle_type == 'd') || (angle_type == 'r'))
{
if (angle_type == 'd')
{
double pi = acos(-1.0);
phi = (pi/180);
theta
= (pi/180);
}
else
{}

        xcoord = r*sin(theta)*cos(phi);
        ycoord = r*sin(theta)*sin(phi);
        zcoord = r*cos(theta);
    }
    else
    {}
}[/CODE]

If the constructor call in the main program inputs an angle_type of anything other than d or r, then the threevector returns -9.25596e+061.
Why is that number returned?

highflyer8

"This makes sense for a function designed only to produce output":

Am I right to say that

the variable [I]object.method(argument)[/I] does not have a return value when the method prints values to a file (as its job is to print, not return values),
but that, since the method is writing to a file and the argument is an output file, the argument should get modified, which is why the ampasand is used to modify the argument (or file) each time the method is implemented in the main program?

P.S.: WaltP, I will be posting on this thread from now on.

highflyer8

"A reference allows you to make modifications to the argument/parameter and have those modifications be reflected in the original scope of the variable":

Ok! This I understand.

"which is necessary for the data stream to work properly.":

Why is it necessary for the data stream to work properly?

highflyer8

Sorry, that link doesn't work. Here's the link again:

[url]http://www.daniweb.com/software-development/cpp/threads/353213/1501385#post1501385[/url]

Thanks in advance for any help.

highflyer8

Yes, exactly. The two posts are related.

But still, please help me answer that question of mine. :-)

Why does the print method in the post at
[url]http://www.daniweb.com/software-deve...threads/353213[/url]
have void as its return type?

highflyer8

Thanks for the point!

I have modified the type of the argument in the print function to ofstream&.
Even then, the code does not compile. (I guess that's because the the argument does not refer to any ofstream object in the main program. Am I right?)

Next, I defined an ofstream object in the main program and then the code compiles.

My question is:
why should my argument be a reference to an existing file stream, not a copy of one? Please reply.

highflyer8 Light Poster

Compiling the following the class in the main program returns error C2784.

What could be causing the problem?

[CODE]#include // Include input/output stream

include

class threevector
{

public:
double xcoord, ycoord, zcoord;

// Default constructor
threevector()
{
    xcoord = 0.0;
    ycoord = 0.0;
    zcoord = 0.0;
}

// Cartesian constructor
threevector(double x, double y, double z)
{
    xcoord = x;
    ycoord = y;
    zcoord = z;
}

// Method to print out contents to screen
void print()
{
    std::cout << xcoord << '\t'
                  << ycoord << '\t'
              << zcoord << std::endl;
}

//Method to print out contents to file
void print(std::ofstream fout)
{
    fout << xcoord << '\t'
         << ycoord << '\t'
         << zcoord << std::endl;
}

};[/CODE]

highflyer8

I understand the application of [I]void[/I] to methods (e.g. access and modifier methods)that return a number. In those cases, the number is returned back to the main program and stored in the computer, so the data needs a type to exist. That part is clear.

What I do not understand is the difference between the performance of a print method and other methods. A print method writes the data to an output file. It does not return any data to the main program in a way similar to the access or modifier methods(am i right?) but rather takes an ofstream object as its input and stores data within that object. In that sense, it is returning data to the main program. So shouldn't we replace void with ofstream?

highflyer8 Light Poster

Any method (within a C++ class) that prints to a file or to a screen has a return type of void. What role does the keyword [I]void[/I] perform?

highflyer8 Light Poster

I have seen the following in a abook:

"The argument(s) of a method can be any type of object (as long as its class has been made available to the program), as well as the predeļ¬ned default types of variable. For example, methods in our three-vector class are not limited to just accepting arguments of type threevector, int, double, etc."

I understand that the first statement is telling us that objects of all classes made available to the program can be used as arguments of a method.

What I do not understand, however, is how the second statement follows logically from the first. "Methods in our three-vector class are not limited to just accepting arguments of type threevector, int, double, etc." Sure! No problem! But what other types of objects are you thinking of?

highflyer8

Banfa: Actually I meant -10^5. I'm sorry I confused myself.

highflyer8

Banfa: Thanks for the help. I implemented your advice. The Kahan Summation works fine with your code, but having applied the algorithm to my code, I still get the same wrong answers for any integers below -14.0. And 10^-5 is way out of the question.

Please help!!!

(Ketsuekiame: I was actually talking about large negative numbers (eg 10^-5). )

[CODE]

include
include
include
include
include

using namespace std;

int main ()
{
double t = - 14.0; // t is the argument of the exponential function.
double fsum = 1.0; // fsum is the cumulative sum in the calc of the answer.
double fbefore = fsum; // to be used for the while statement
int n = 1; // n is the denominator of the power series
double comparing; // to be used in the while statement
int iterations = 0;
double term = 1.0; // each additional term in the series.
double c = 0.0; // c is a running compensation for lost low-order bits.
do
{
iterations = iterations + 1;
term = term * ( t/n );
double y = term - c; // So far, so good: c is zero.
double p = fsum + y; // Sum is big, y small, so low-order digits of y are lost.
c = (p - fsum) - y; //(t - sum) recovers the high-order part of y; subtracting y recovers -(low part of y)
fsum = p;
n = n + 1;
double ...

highflyer8 Light Poster

Hi,

I have to calculate the exponetial of a large (on the order of 10^5) negative number. I tried using exp(), the exponential function from the cmath library, but I get an answer of 0. So, I tried to use the power series for the exponential function. For numbers from -1 to -14, I get answers which are accurate (within the percentage error set in the while statement). But for any number above -14, the answer diverges from the true value. For a number as small as 10^-5, the answer is a large positive number (which is nonsenical).

Please help me understand what's wrong with the code, if anything, and how it can be improved. (Or is there another better way to calculate the exp of a large -ve number?)

[CODE]

include
include

using namespace std;
int main()
{
double t = - 16; // t is the argument of the exponential function.
double fsum = 1.0; // fsum is the cumulative sum in the calc of the answer.
double fbefore = fsum; // to be used for the while statement
int n = 1; // n is the denominator of the power series
double comparing; // to be used in the while statement
int iterations = 0;
double term = 1; // each additional term in the series.
do
{
iterations = iterations + 1;
cout << iterations << endl;
term = term * ( t/n );
fsum = fsum + term;
n = n + 1; ...