Sci@phy 97 Posting Whiz in Training

Here's an idea:
First check is your number teen, or not.
If it is teen number (1 is first digit) then check second digit and write:

//just for example
case 1: str = "Eleven"; break;
case 2: str = "Twelve"; break;
//...

if it's not teen number, then you have to check first digit and make str = "Fifty", or str = "Ninety", etc.
Then check second digit and add to str:
str += "Two", str+="Three", and so on...
HTH

Sci@phy 97 Posting Whiz in Training

If you want to be able to write

something = 4 + var;

You have to overload once more operator+.

First, declare it as friend of class, and then write it like:

Array<T> operator+ (const float f, Array<T> myVal);

That's because if you define operator+ as a member of class it is interpretting:
val + 3;
as:
val.operator+(3);
So if you write:
3 + val;
it is interpretted as:
3.operator+ //it's clearly rubbish

monkey_king commented: Very helpfull +1
Sci@phy 97 Posting Whiz in Training

I don't think that <cmath> is in std namespace:
Example with iostream (using namespace std;)

Example with cmath (doesn't have using...)


Maybe he declared another function named sqrt? Or a variable perhaps.

Sci@phy 97 Posting Whiz in Training

Try to write it, and see will it work :)

Sci@phy 97 Posting Whiz in Training

No, not about class keyword now :)
But what is make, team and number?
You use them as instances of class racecar, and I fail to see why do you need that.

But yet again, maybe it's my fault.

Sci@phy 97 Posting Whiz in Training

In that case, I think it's fine. Just try to explain to me please what is line:
racecar make, team, class, number;
Why are you making instances of racecar class?

Sci@phy 97 Posting Whiz in Training

You don't need to write your own list!
Lists in c++

And "class" is reserved c++ keyword, you can't use it as varable named class!

Sci@phy 97 Posting Whiz in Training

If we could see a bit more of your code?

Sci@phy 97 Posting Whiz in Training

Don't mention it. And, in C++ spirit, I'm obliged to tell you to look at vectors, because that's better for handling a large arrays.

Sci@phy 97 Posting Whiz in Training

You still use array numbers, although you don't need them. In
readInputFile
use *(list+i) instead of numbers, like:

infile>>*(list+x);

And write selectionSort.

Another question: why do you print out numbers[4]?

Sci@phy 97 Posting Whiz in Training

First of all, you have code:

void openInputFile(ifstream&infile);
//it should be:
void openInputFile(ifstream& infile);

Second:

void readInputFile(int *list[],ifstream&infile);
//int *list[] doesn't make any sense. You have two options:
int *list //or
int list[]

Third: take a look at

void readInputFile(int,ifstream&infile); 
//and
void readInputFile(int *list[],ifstream&infile){
//...

They're not the same, fix this.

Fourth: In readInputFile you use
int numbers[100];
to store data.
But you should use list[], you want to fill that array?

Try these modifications, and then see if it works

Sci@phy 97 Posting Whiz in Training

You cannot return a pointer in one case, and "packet" in other. Both should be packets, or pointers. How do you want to use this function?

Sci@phy 97 Posting Whiz in Training

Yes, it's ok.
But it's better to write:

if ( (stars[i][j]/5) > 6.0)

That way you are certain that it will work.

Sci@phy 97 Posting Whiz in Training

Well, first, "class" is a c++ keyword, you can't use that name.
Second, that last else in your code should be:
else if (weight >= 3500 && year >= 1980)
or:
else

Because else means "if nothing before is true", it can't have an expression to evaluate.

Sci@phy 97 Posting Whiz in Training

I guess you defined
float stars[20][20]?
You can't write stars + stars[j], because you have to write two dimensions (two brackets):
stars[j]... always.
hth

Sci@phy 97 Posting Whiz in Training

Shouldn't the include<string> be actually #include<cstring>?
He doesn't use any string object, only string functions like strcmp, strcpy etc...

Sci@phy 97 Posting Whiz in Training

Sounds like you're in a hurry...
First of all, DON'T USE <iostream.h> and <string.h>...
Instead use <iostream> and <cstring>.
Second, main can't be declared like that, it has to be:

int main(){
//code here
return 0;
}

Cheers!

EDIT: and yes, you are using system(), that means you have to include header for it!
and yes, if using objects from std namespace, you have to declare that you're using it, write
using namepsace std;
at front, although it's a bad habit

Sci@phy 97 Posting Whiz in Training

Can you be more specific? Why do you need string?
Maybe you can use vector<char> instead of array of chars?

Sci@phy 97 Posting Whiz in Training

If print is a function... you need brackets:

(currnode->contact).print();

Sci@phy 97 Posting Whiz in Training

You can use ostringstream from <sstream>, i use that, although it may not be the easyest way.

#include <sstream>

std::string Convert (float number){
     std::ostringstream buff;
     buff<<number;
     return buff.str();
}

ostringstream and istringstream are basically the same as cout and cin, but they don't print stuff on screen. So you can use them as "anything_to_string converter" (ostringstream), and "string_to_anything converter" (istringstream).

Sci@phy 97 Posting Whiz in Training

Try with something easy for start.

Sci@phy 97 Posting Whiz in Training

The best thing is not to use string to hold only one letter (very bad idea). So instead of

string letter;

you better write:

char letter;

HTH

Sci@phy 97 Posting Whiz in Training

And what is the problem?
To help you a little, your sequence is the same as:
(-1)^2 * x^1/1! + (-1)^3 * x^2/2!...

Sci@phy 97 Posting Whiz in Training

It's a long shot, but maybe while optimizing compiler got rid of unneeded functions and code in library?

Salem commented: Yes, except it's the linker, not the compiler. +21
Sci@phy 97 Posting Whiz in Training

I'm aware of that, but that's not the issue here.
If i go with string, when trying to access deleted memory site, OS gives an error (because of pointer accessing something he shouldn't)
If i go with my object, when trying to access deleted memory site, I can access it!

Sci@phy 97 Posting Whiz in Training

Neither nor. The compiler knows the size of your objects. And delete does work! The memory area just isn't used by other objects.

Thx, I'm going to do that. But just out of curiosity, let's say i write:

string *ptr = new string;
string *alt = ptr;
ptr->assign("Happy Day");

cout<<"On alt adress is: "<<*alt<<endl;
    
cout<<"deleting ptr"<<endl;
delete ptr;
cout<<"ptr adress: "<<ptr<<endl;
cout<<"alt points to: "<<*alt<<endl;

Now program is terminated as it tries to read *alt (so delete really destroyed contents on that memory location).
If i replace string with my own Complex, it works fine, like it never was deleted.
How did string writers managed to do that?

Sci@phy 97 Posting Whiz in Training

Hi all.
I've written my own class Complex, that stores complex numbers.
I've overloaded a whole bunch of operators so that you can work with them like with normal numbers.

Then i wanted to overload 'new', but I tried it before overloading, and it "seems" to be working.
I can write

Complex *ptr = new Complex;

And it works so far, but I'm not sure if it allocates enough space?

And delete doesn't work, because data is accessible after using delete.
Should I overload 'delete' and let 'new'? Or overload both?

Sci@phy 97 Posting Whiz in Training

I've tried solution with IsAnotherInstanceRunning(), and it works great.

But since the header file includes windows.h, it can't run on unix-types... I'd appreciate some help on that filed

Sci@phy 97 Posting Whiz in Training

Hello.
Any way of preventing multiple instances of executables?

I'm writing a program that uses a file, it would be quite messy if someone would start another instance of same program.

If it depends on OS, I would like to see solutions for windows and unix-type (linux) systems.

Thanx