JasonHippy 739 Practically a Master Poster

I'm trying to make a program that will read two txt files, with GPA information (one for females and one for males) arranged like this:

M 4.0
M 3.7
M 2.9

I've been instructed to used pass by reference void functions with no global variables. My major issue is how do I make a function to open the files then another to initialize variables? Here's what I've got so far, it's pretty rough.

If some one can even just explain conceptually how to do something like this, that would be great.

//GPA.cpp
//CMP-110
//October 09'



#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>

    //Function Prototypes
void openFiles(
void initialize(
void sumGrades(
void averageGrades(
void printGrades(


int main()
{

openFiles()


}


void openFiles(ifstream& gpa)
{
    ifstream mData;
    ifstream fData;
    ofstream outGpa;

    mData.open("c:\\maleGPA.txt");
    fData.open("c:\\femaleGPA.txt");

    outGpa.open("c:\\finalGpa.txt");
    outGpa << fixed << showpoint;
    outGpa << setprecision(2);

    
}
    
void initialize(&)
{
    int mCount = 0;
    int fCount = 0;
    double mGPA = 0.00;
    double fGPA = 0.00;
    int countFemale = 0;
    int countMale = 0;
    double sumFemaleGpa = 0.00;
    double sumMaleGpa = 0.00;
}

void sumGrades(&)
{

OK, I'm not sure exactly what you're after here but this snippet might help you a little:

#include<iostream>
#include<fstream>
#include<string>
#include<vector>

using namespace std;

////////////////////////////////////////////////////////////////////////////////
/// opens a file and reads its contents into a vector of strings.
////////////////////////////////////////////////////////////////////////////////
/// \param<filename> const reference to a string
/// \param<content> reference to a vector of strings
////////////////////////////////////////////////////////////////////////////////
void readInputFile(const string &filename, vector<string> &content)
{
	ifstream infile;
	infile.open(filename);


	string …
JasonHippy 739 Practically a Master Poster

Alternatively, if you only wanted the extra block to be shown if the value of the parameter was 3 then you could change this block from my previous listing:

if(i==myCondition)
{
	cout << "i = " << i << " and myCondition = " << myCondition << endl;
	cout << "This block of code only gets called when i == myCondition." << endl;
	cout << "Is that what you were aiming for?" << endl << endl;
}

to this:

if(myCondition==3)
{
	cout << "This only gets called when myCondition is passed in as 3" << endl;
}

And then your results will look like the attached .png
So now the extra block will appear on each iteration, but only if the value of the passed in parameter is 3

JasonHippy 739 Practically a Master Poster

Thank you for your answer.
In my example, MYCONDITION is known. But in my code, MYCONDITION is not. It's known only at the time of execution as an argument in the command line.

Then what you need to do is parse the command line and store the relevant arguments in variables and then use those variables to determine what happens in your code.

So perhaps something like this?

#include<iostream>
using namespace std;

#define MAXVAL 10

// program takes one argument and is invoked like this:
// program.exe {value for myCondition 1-10}
// e.g.
// program 2
// This will run the program and will display an extra message on the 2nd iteration of the loop
int main(int argc, char* argv[])
{
	int myCondition;

	// Check the command line parameters...
	// First ensure that there are only two arguments (filename and the value for "myCondition")
	if(argc==2)
	{
		// ok, we have the correct number of arguments, 
		// so convert the 2nd argument in the array to an int
		// and assign it to myCondition.
		myCondition = atoi(argv[1]);

		// Ensure myCondition is within our bounds
		if(myCondition<=MAXVAL && myCondition>0)
		{
			// now we'll loop 10 times and say hello each time
			for(int i=1; i<=MAXVAL; ++i)
			{
				cout << "Hello #" << i << endl;
				
				if( i==myCondition) // display an extra message or three!
				{
					cout << "i = " << i << " and myCondition = " << myCondition << endl;
					cout << "This block of code only gets called …
JasonHippy 739 Practically a Master Poster

I have already created a video player in AS3.0. The Client wants to convert it to a component. I need some good to follow tutorials on creating own components. I had know the concepts of creating components and utilizing that as a SWC. I need to create the component with the interface already designed at flash authoring time and have to give the provision to change the button styles which has to be edit by the client itself.

Experts! please come forward and help me!

Hmm, I used to work with flash components from time to time at my previous job, (both creating and customising components) but those were all AS1 and AS2 components. And although I work pretty much exclusively with AS3 nowadays when tinkering with flash at home, I haven't done anything with components in a really long time (over 2 years) and it was never in AS3!

If I get a chance I'll try to take a look at what differences there are between creating components in AS2 and AS3 and I'll try to get back to you. Actually, it's been so long, I'm probably gonna have to get up to speed with component creation from scratch.

Heh heh, but who knows; it might even be the perferct excuse for me to meet up with some of my former colleagues for a beer or three!

In the meantime, this looks like a good tutorial to take a look at for starters..
http://www.adobe.com/devnet/flash/articles/creating_as3_components.html

JasonHippy 739 Practically a Master Poster

Aha, I've just quickly tested it and it seems to work!
Here's a little program I knocked up, loosely based around previously posted code in this thread:

#include <iostream>
#include <algorithm>
#include <deque>
#include <ctime>
#include <iterator>

using namespace std;

struct Str
{
	int a,b;
};

bool deq_test(Str& deq1, Str& deq2)
{
	if(deq1.a==deq2.a)
	{
		return(deq1.b<deq2.b);
	}
	else
		return(deq1.a<deq2.a);
}

int main()
{
	deque<Str> deq;
	srand(time(NULL));
	Str MyStr;

	cout << "Generating values and populating deque:" << endl;
	for(int i=0; i<6; ++i)
	{
		MyStr.a = rand()%10;
		MyStr.b = rand()%10;
		cout << "a = " << MyStr.a << ", b = " << MyStr.b << endl;
		deq.push_back(MyStr);	
	}

	cout << endl << "Sorting Deque..." << endl << endl;
	sort(deq.begin(), deq.end(), deq_test);
	
	cout << "Sorted values are: " << endl;
	for(deque<Str>::iterator iter = deq.begin(); iter!=deq.end(); iter++)
	{
		cout << "a = " << (*iter).a << ", b = " << (*iter).b << endl; 
	}
}

And some sample output is shown in the attached .png.
Looking at the png, you can see that there are several values which have an 'a' value of 2. These have successfully been sorted by their 'b' values.

Problem solved??

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

I have already try this ... and i have not been able to successfully write the comparison function which would sort deque by both values.

With your code deque is sorted only by a value, so youl'll get
let's say:
02
01
05
13
11
15
21
20

instead of :
01
02
05
11
13
15
20
21

I've not actually tried this, but would something like this work for the deq_test function?

bool deq_test(Str& deq1, Str& deq2)
{

	if(deq1.a==deq2.a)
	{
		return(deq1.b<deq2.b);
	}
	else
		return(deq1.a<deq2.a);
}

In other words, if the values of deq1.a and deq2.a are the same, you sort them by their b values. Otherwise you sort them by their a values.

As mentioned, I've not tested this but I think it should work!
Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

Hi Friends Is There Any Way To Open And ReEdit An .exe File... Suppose I Have a Portable .exe File Which Needs No Installation in My Windows. And I Want To Edit Some Icons or Some Text which is Given in The .exe File So What Should I Need To Do ???

I Have Drag And Dropped The .exe File on The Notepad But When Its Shows Me The Script its Impossible to Read The Signals or Commands..

Shortcutly "HOW TO EXTRACT AN .EXE FILE"


Thanks in Advance.

Ok, well for starters what you're seeing in Notepad isn't any kind of script, it's actually machine code but rendered in notepad as ascii text. But if you view the .exe with a Hex editor, then things will become a little clearer...As long as you can read machine code that is! ;)

If you only want to edit text and icons in the program, then you could use something like resource hacker:
http://www.softpedia.com/get/Programming/File-Editors/Resource-Hacker.shtml

Resource hacker can partially decompile an exe and will display any resources it uses (strings and bitmaps). You can then edit the resources, recompile the executable and save it. (but don't forget to keep backups of your original .exe files!)

Resource hacker won't necessarily work 100% of the time for all .exe's and there are no guarantees that the exported .exe will work properly after editing the resources and recompiling, but I understand that it does work sometimes!

I have seen …

JasonHippy 739 Practically a Master Poster

Hey kiddo,

I've just emailed the link you gave me to JasonHippy as he is probably way more advanced in flash than me. Plus it's actionscript 2.0 so I don't really dabble with that.

In terms of adding a counter. I believe you would have to interface it to a php script. However, I'm a bit busy at the mo so won't be able to help much.

Take it easy.

Morning all!
Apologies for the lack of activity recently, I've been out of action for a week or so thanks to a rather severe case of sinusitis...I initially made the mistake of ignoring it, hoping it would sort itself out...Unfortunately it just got worse! Doh!

Anyway, I took a look at the link that iamthwee sent me, but the link was invalid. The site it linked to gave an error message saying that the file could not be found.

If the OP could zip up the original files and email 'em to me (I've already PM'ed her my email addy!) I can take a look at changing the font!

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

I'm trying to pick out whether or not a prime number is given by a user, when they input a number. This is what I have, but it' not working correctly....can anyone suggest anything?

#include <iostream>
using namespace std;

void main()
{
	int n;

	while (true)
	{
	cout << "Enter an integer: ";  cin >> n;
	if (n!=2 && (n%2==0 || n%3==0 || n%5==0))
		cout << "Not Prime" << endl;
	else
		cout << "Prime" << endl;
	}
	cout << endl;

}

Hey there!
Don't forget to look at the replies in your other thread where you've already asked about this!
http://www.daniweb.com/forums/thread230230.html

After you got an answer to your original question about odd numbers, you went on to ask about primes!

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

Another thing that was pointed out by one of my math-geek colleagues was that my algorithm would also incorrectly flag 1 as prime.

Now I always thought that 1 was prime (it only divides evenly by itself and 1, so it kinda fits the criteria).
However, according to my colleague; traditionally that was the case, but nowadays there is a slightly different school of thought and 1 is no longer considered prime, for reasons I can't be arsed to go into! He did explain but I kinda zoned out...heh heh! What?! It's early! I haven't had any coffee yet!! ;)

Apparently 1 hasn't been considered prime since the 1950's or thereabouts...So not wanting to be stuck in the past (without a DeLorean fitted with a flux capacitor, heh heh!), we could alter my algorithm to flag 1 as not prime like this:

if(numIn==2)
        return true;
else if(!(numIn%2) || numIn==1)
	return false;

Incidentally, I was a little bored at work yesterday, so at lunchtime while I was waiting for a long build to finish I altered the function to work with unsigned long long integers and then created a quick little program which used my little function to calculate all the primes in the range from 1 up to the value returned by std::numeric_limits<_ULONGLONG>::max() (which on my pc returns as 18,446,744,073,709,551,615...a very large number indeed!) and output them to a text file....

I let it run for a few hours while I got on with some …

Gaiety commented: you gotta lot of energy...! +1
JasonHippy 739 Practically a Master Poster

Do you mean something like this??

numarray = [1,2,-3,4,5,-25]

for n in numarray:
    print "The inverse of", num, "is", num * -1
    #print("The inverse of", num, "is", num*-1)
    # use the above line if you're using python 3.x!

The output from the program is:

>>>
The inverse of 1 is -1
The inverse of 2 is -2
The inverse of -3 is 3
The inverse of 4 is -4
The inverse of 5 is -5
The inverse of -25 is 25
>>>

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

I've just had a quick look at the fie and I don't think you can change the <font> easily. It looks like it is drawn with code or something.

Hey Iamthwee,
re: the font issues...

Do you want me to take a look?
I should be able to work out how to change the font. If the .fla file is in CS3 format, I should have no probs doing it myself. But if it's CS4, I'll can decompile the swf and poke around in it's guts to see what's going on and then run you through the steps required to fix it in CS4!

It may even be possible to modify the fla so that fonts are handled differently.
If you do need a hand give me a shout!
Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

Hey Gaiety!
Good point, the original code was just quickly bashed out, off the top of my head and yes I missed 2 out!..

OK, so if the passed in number is 2 we need to return true (Prime), otherwise if it is divisible by 2 we need to return false (not Prime)
So the only needed change in my original code is this:

if(numIn==2)
        return true;
else if(!(numIn%2))
	return false;

So my final code looks like this: (comments stripped out!)

bool IsPrime(int numIn)
{
	if(numIn==2)
		return true;
	else if(!(numIn%2))
		return false;

	int testNum=3, limit = numIn;
	
	while(limit>testNum)
	{
		if(!(numIn%testNum))
			return false;

		limit = numIn / testNum;
		testNum+=2;
	}

	return true;

}

And that solves the problem! Now 2 will be returned as a prime number!

My code does pretty much what yours does, but mine is a tiny bit more efficient as it immediately discounts all even numbers and it uses a few other little tricks which I'll explain shortly!

Comparing the algos:
Your algorithm checks against everything from 2 upwards, so if the number we were testing was 19:
Your algorithm would check against 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19 before deciding it was prime (18 calculations)

Whereas using my algorithm with the above change; if the number is 2 it's instantly flagged as prime, if it's even it's instantly flagged as not Prime..
Using 19 as our number, calling my function would not trigger either of those conditions, so it would …

JasonHippy 739 Practically a Master Poster

Thanks for the help! Is there a way to determine if the numbers are prime or not, based on the code above?

could you say:

if ( posnum / 1 = posnum/posnum)
     cout << "Number is Prime";
else
     cout << "Number is NOT prime";

For starters; in your code just above you need to use the == (equality) operator to test for equality, not the = (assignment) operator.
Also, that is definitely not the correct formula for determining a prime number!

If you look at the first part of your expression:
'posnum/1' would always evaluate to the value of posnum, for example if posnum was 7 (which IS a prime number), then the result of posnum/1 would be 7 (because 7/1=7)
Also :
'posnum/posnum' will always evaluate to 1, again using 7 as an example: 7/7=1

So your algorithm would decide that the number 7 is not prime, which is utterly wrong!

Incidentally, the only time that your algorithm (posnum/1==posnum/posnum) would say that posnum is prime is when the value of posnum is 1.

What I'd do is create a function which tests whether a number is prime and returns a boolean. Something like this:

// tests if the passed in integer is prime
// returns true if prime, false if not prime.
bool IsPrime(int numIn)
{

	// we'll test this value against numIn using the % operator
	int testNum=3; 
	// Note: we only want to test numIn against ODD numbers …
JasonHippy 739 Practically a Master Poster

All you need to do is use the modulus operator %.
So check the value of posnum % 2
What this does is it divides posnum by 2 and returns the remainder.
Here's a brief look at what is returned.
1 % 2 returns 1
2 % 2 returns 0
3 % 2 returns 1
4 % 2 returns 0
..... and so on
99 % 2 returns 1
100 % 2 returns 0

so if you use %2, you can easily test if a value is odd or even!
If it is odd, 1 is returned, if it is even 0 is returned.

likewise if you used %4 you get this...
1%4 returns 1
2%4 returns 2
3%4 returns 3
4%4 returns 0
5%4 returns 1
6%4 returns 2
.......and so on
99%4 returns 3
100%4 returns 0


Anyway, you need to use %2 to test for odd/even. So what you need to do is this:

#include <iostream>
#include <iomanip>
using namespace std;

void main()
{
	int posnum;
	int oddint;
	int i;
	
	while (true)
	{
		cout << "Please Enter a Positive Integer: ";
		cin >> posnum;
		cout << endl;

                // error here: what if the user enters something less than 1?
		// if (posnum == 1)
               // Do this instead
               if(posnum <2)
			cout << "Number must be 2 or larger...Please enter another Positive …
JasonHippy 739 Practically a Master Poster

This is my driver program where this problem is located. Could it have to do with my iterator?

#include "Shape.h"
#include "Circle.h"
#include "Rectangle.h"
#include "Triangle.h"
#include <list>
#include <iostream>

using namespace std;

int main()
        {
        list<Shape *> L;
        list<Shape *>::iterator itr;

        L.push_front(new Circle("blue", 11));
        L.push_front(new Circle("green" , 5));

        L.push_front(new Rectangle("purple", 5, 15));
        L.push_front(new Rectangle("red", 15, 27));

        L.push_front(new Triangle("yellow", 10, 3));
        L.push_front(new Triangle("black", 3, 30));

        cout << "\nPrinting all shapes..." << endl << endl;

        for(itr = L.begin(); itr != L.end(); ++itr)
                (*itr)->print();

        cout << "\nPrinting only circles..." << endl << endl;

        Circle* c=dynamic_cast<Circle*>(*itr);
        if(c != NULL)
                c->print();
        else
                cout << "error" << endl;

        return 0;
        }

Your dynamic_cast is fine, but take another look at your code..You've iterated through the list and printed all items, then you've printed a message saying that you're going to print only the circles.
Next is where you're going wrong. You're trying to dynamic_cast the iterator....now at this point the iterator will be pointing to the last element in the list, if the last element is a circle then the dynamic_cast will work.

But what you really need to be doing is iterating through the list again and attempting to dynamic_cast all of the items in the list like this:

cout << "\nPrinting only circles..." << endl << endl;

        // iterate through the list and try casting all elements to circle..
        for(itr = L.begin(); itr != L.end(); ++itr)
        {
            Circle* c=dynamic_cast<Circle*>(*itr);
            if(c != NULL)
                    c->print();
            else
                    cout << "error" << endl;
        }
JasonHippy 739 Practically a Master Poster

Line 4 is initializing the vector to have longitud number of elements. Each push_back() will add another item to the end of the vector, which will increase the vector size.

You don't want to use push_back() if you initialize the vector like that. Just use [] operator

for (unsigned i = 0; i < palabra.size(); i++, letra += 1)
{
       palabra[i] = 'a';
}

Also, line 7 is wrong because vector does not have an overloaded << operator. So "<< " " makes no sense.

Doh, the dragon got in there while I was composing my rambling post! heh heh! :)

JasonHippy 739 Practically a Master Poster
unsigned longitud;
cin >> longitud;
    vector<char> palabra(longitud);
    for (unsigned i = 0; i < palabra.size(); i++, letra += 1)
    {
        palabra[i].push_back ('a') << " ";
        }

The error i get:

error: request for member `push_back' in `(&palabra)->std::vector<_Tp, _Alloc>::operator[] [with _Tp = char, _Alloc = std::allocator<char>](i)', which is of non-class type `char'

I don't even understand what this error is saying :-/

Your problem is with the way you're using the vector with the push_back function.
push_back is used to put an item onto the back of the vector, but you can't say at item in the vector push a value to the back of the vector.
The following code:

palabra.push_back('a');

would basically find the last empty element in the vector (or if there was not enough space, the vector would reassign itself some more memory and grow some extra spaces ). It then pushes the item ('a') into the last element of the vector.

When trying to index an element of a vector and assign it a value, you can use an iterator or a standard array-style index to reference an item in the vector and assign it a value.
So from looking at your code, I think what you're trying to do is this:

palabra[i]='a';  // NOTE: the << " "; part would also throw an error so that's been removed!

You should also note that 'letra' has not been declared/defined correctly in your snippet...If you have it declared elsewhere in your code, then …

JasonHippy 739 Practically a Master Poster

The following code is working!
function and function pointer are defined
I defined two probe function:
mysin1 and mysin2
both works with myfunc with in first argument
but I dont't understand,
because mysin2 wait for a function_pointer not a function

#include <math.h>
#include <iostream>

using namespace std;

typedef double func(double v);
typedef func *func_pointer;

double myfunc(double x)
{
  return x*x;
}

double mysin1(func infunc, double x)
{
  return sin(infunc(x));
}

double mysin2(func_pointer inpointer, double x)
{
  return sin((*inpointer)(x));
}

int main() 
{
   func newf;
   func_pointer newfp;
 
   cout << mysin1(myfunc,2.) << ", " << sin(4.) << ", " << mysin2(myfunc,2.) << endl;
   return 0;
}

result:
-0.765802, -0.765802,-0.765802

ok, well for starters, the reason your call to mysin2 is working is because you are passing in myfunc, it doesn't matter that you haven't passed a strict function pointer, it gets treated as a pointer anyway.
It should also be noted that mysin1 and mysin2 both take function pointers, regardless of how things might look!

So you could pass myfunc to mysin1 or mysin2 in any of three ways:

1. The way you've already used, passing myfunc directly:

..... mysin2(myfunc, 2.) << .....

2. passing using the 'address of' operator (&):

..... mysin2(&myfunc, 2.) << .....

3. assigning your function pointer (newfp) to point to myfunc and then passing newfp to mysin2:

func_pointer newfp = &myfunc; // or newfp=myfunc;
..... mysin2(newfp, 2.) << .....

Although all three methods work, I …

JasonHippy 739 Practically a Master Poster

As you've pointed out, you can pass a pointer to a function as a parameter to a function.

And yes, it is possible to make a function return a pointer to a function, but the syntax is a little messy!

But no, you can't do it without pointers as far as I'm aware.

I haven't had anywhere near enough coffee this morning to be able to put a coherent example together, but take a look at the tutorial here:
http://www.newty.de/fpt/fpt.html

The tutorial explains all you need to know about function pointers and contains links to downloadable .pdf versions of the tutorial (in french and english) plus zipped source code!

Cheers for now,
Jas.

p.s. Question to admins/moderators: Should I download and zip up the files on the referenced page, and then post them here as an attachment (in case the referenced page gets taken down in the future)? Or should I leave it as is?

JasonHippy 739 Practically a Master Poster

Raja's suggestion is a good one.

There is another alternative if you're using a professional edition of the flash IDE. Pro versions of Flash ship with the 'Flash Video Encoder', this can be used to convert various video formats to .flv.

It doesn't support directly converting .swf to .flv, but there is a workaround:

1. Open up your .fla in the flash IDE and export your .swf as a movie in .mov or .avi format ( select 'File->Export->Export Movie' in the menu or press ctrl+alt+shift+S )

2. Enqueue the exported movie (.avi or .mov) in the video encoder and convert it to .flv

As already mentioned, you can only do this if you've got a professional edition of the Flash IDE and the 'Flash Video Encoder' installed.

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

Ballpark?

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>
using namespace std;

int main()
{
   string init[] = {"one", "two", "three", "four", "five" };
   vector<string> vec(init, init + sizeof init / sizeof *init);
   copy(vec.begin(), vec.end(), 
        ostream_iterator<string>(cout, "\n"));
   return 0;
}

/* my output
one
two
three
four
five
*/

Of course!
Good thinking...Dave, I'd not thought of that!
Nice use of the copy algortihm too...I'd forgotten about that little STL gem!

JasonHippy 739 Practically a Master Poster

However, using push_back(), you'd do it like this:

#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main()
{
	string strs[] = {"String1","String2","String3","String4","String5"};
    // we still need to know how many strings there are
	int count=5; 

	// no need to reserve any space in the vector 'cause we'll use push_back()
	std::vector<string> vec;

	// so lets populate the vector....
	for(int index=0;index<count; ++index)
	{
		vec.push_back(strs[index]);
	}

	// Now let's see what the vector contains
	cout << "The strings in the vector are:" << endl;

	for(vector<string>::iterator iter = vec.begin(); iter!=vec.end(); iter++)
	{
		cout << (*iter) << endl;
	}

	string dummy;
	getline(cin, dummy);
}

This is by far the preferred way of doing things!

Jas.

JasonHippy 739 Practically a Master Poster

OK, push_back definitely is the safest way of populating a vector. However, the method I'm about to show is not particularly good practice, but it can be done and it does have it's uses:

#include<iostream>
#include<string>
#include<vector>


using namespace std;

int main()
{
	// here are our original strings in an array of strings
        // for the sake of this example imagine that strs[] was
	// passed in as an argument so we don't know upfront how 
        // many strings are in the array 
	string strs[] = {"String1","String2","String3","String4","String5"};

	// But before we attempt to reserve some space on a vector,
        // we need to know how many strings there are..... 
        // trying to count them doing something like this
	// int count=0;
	// while (strs[count])
	//     ++count;
	// 
	// Would not work as std::string cannot be evaluated like 
        // that...So we actually need to know upfront how many there are
	// in order to reserve space in the vector.
	int count=5; // so this value would have to be passed-in too!

	// reserve 'count' spaces in our vector
	vector<string> vec(count);

	// now our vector has enough space to hold all of the strings in the passed-in array....
    // so we'll set up a loop to copy strings from the array to the vector:
	for(int index=0;index<count; ++index)
	{
                // This can be used, but it is dangerous
		//vec[index] = strs[index];

                // This is safer..Less likely to cause a crash if you 
                // overstep the mark with index!
                vec.at(index]=strs[index];
	}

	// …
Ancient Dragon commented: Yes, that will work too. +24
JasonHippy 739 Practically a Master Poster

Ah hang on, I see the problem.....I should've spotted this off the bat! heh heh!

#include<iostream>
#include<string>

using namespace std;

 class STD1{
         int id;
         string name;  // you can't initialise it here because this is the technically the header for the class!
          char status;
 public :
         void pinfo();
         void ginfo();
};
void STD1::ginfo(){
        // but you could do it here
        name = string(""); // this should initialise name
        // alternatively, write a constructor for your class 
        // and initialise name there!
        cout<<"Enter ID : ";
        cin>>id;
        cout<<"\nEnter Name : ";
        cin>>name; // now the cin should work!
        cout<<"\nEnter Status : ";
        cin>>status;
}
void STD1::pinfo(){
        cout<<"Student Info Is ... ID : "<<id <<" Name : "<<name <<" Status : "<<status;
}

int main()
{
        STD1 m;
        m.ginfo();
        m.pinfo();
        return 0;
}

I think that might be what you're looking for!
Either initialise it in the ginfo function as shown above or add a constructor to the class and initialise it there!

So using the constructor option:

#include<iostream>
#include<string>

using namespace std;

 class STD1{
         int id;
         string name; 
          char status;
 public :
	 STD1(){name = string("");} // ensure that name is definitely initialised!
         void pinfo();
         void ginfo();
};
void STD1::ginfo(){
        cout<<"Enter ID : ";
        cin>>id;
        cout<<"\nEnter Name : ";
        cin>>name; // now the cin should work!
        cout<<"\nEnter Status : ";
        cin>>status;
}
void STD1::pinfo(){
        cout<<"Student Info Is ... ID : "<<id <<" Name : "<<name <<" Status : "<<status;
}

int main()
{
        STD1 m;
        m.ginfo();
        m.pinfo();
        return …
JasonHippy 739 Practically a Master Poster

Why don't you try using the shlobj.h function SHGetSpecialFolderPath to get the path to the users My Documents folder? It would save all of the messing about your doing there!

Try replacing the code in your main function with this:

int main()
{
    // get the path to the current users my documents folder
    // storing it in an LPSTR
    LPSTR userDocsPath = new CHAR[MAX_PATH];
    SHGetSpecialFolderPath(0, userDocsPath, CSIDL_MYDOCUMENTS, 0);

    // now copy the path into a std::string
    std::string path = std::string(userDocsPath);

    // delete the LPSTR as we don't need it any more...
    delete userDocsPath;

    // Now you've got the path to your users 'My Documents' folder
    // stored in path, you can append any further directories onto it. 
    // e.g.
    path.append("/OMG"); 
    // NOTE: using forward slashes works in file paths, double backslashes are not necessary!

    // Not sure you need to bother creating an 
    // LPSECURITY_ATTRIBUTES object seeing as you're setting it to null!
    CreateDirectory(path.c_str(), 0);
    cout << "\nFolder Created!\n";
}

For more info take a look at the following pages:
SHGetSpecialFolderPath:
http://msdn.microsoft.com/en-us/library/bb762204(VS.85).aspx
CSIDL values:
http://msdn.microsoft.com/en-us/library/bb762494(VS.85).aspx

Hope that is of some help!
Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

i use
string name="";
and
string name;

both give me diffrent error ...

What about this?......

string name = string("");

That should do the trick!

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

Do you really need to use a counter in your log file?

If it's something that's been specified for your project and you absolutely have to use it, then I guess you aught to do something like dkalita has suggested. If this is the case then ignore everything below as it is completely irrelevant and I'm sorry for wasting both space and time!

However if it's not necessary, would it make more sense to use a timestamp in your log file? So each time you write something to your log file you write out a little header with a timestamp?

Before you go panicking about getting the date/time, I've written my own little logger class which I use to debug some of my Windows projects and it uses timestamps. I'll take you through some of the relevant code to give you some ideas you can use for logging stuff in your own apps.

My logger class (JasLogger) is a header only file. So all of the code is in the header...Saves me having to include the .cpp file in my projects! I usually just include the header while debugging my project and once I'm done I remove the header and any instances of the logger. But I do also use it as a permanent logging mechanism in some projects too!

Anyway, the main point is I've written a little bit of code in it which allows the creation of a timestamp in the log.

JasonHippy 739 Practically a Master Poster

Which version of visual studio are you using?

JasonHippy 739 Practically a Master Poster

Everything works except trace,
output panel shows:

Starting new compile.
Loading configuration file C:\Program Files\FlashDevelop\Flex_SDK\frameworks\flex-config.xml
Loading configuration file C:\Documents and Settings\rajarajan\Desktop\ProjectTracing\obj\ProjectTracingConfig.xml
obj\ProjectTracing633905373543906250 (999 bytes)
(fcsh)
Build succeeded
Done (0)
[Capturing traces with FDB]

OK, well the only thing I can think of is perhaps you aren't using one of the debug flash players...Only the content debugger versions of flashplayer will allow you to see trace actions.
The standard player doesn't show them.

Try going to http://www.adobe.com/support/flashplayer/downloads.html and download and install the flash player 10 projector content debugger.

Once you've got it, set your copy of Flashdevelop up, so it uses the content debugger as the external player. Next, reload your project and try building/testing it!
You should now be able to see trace statements!

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

What you need to be doing here is taking a good look at your input file and your code....

The data you've used in your original post contains a few full-stops/periods These are causing the problems you're seeing.
This is your original data:

23
.12
3
35
3
.
.
.
67
1
4

ok, now stepping through your code, what we see is this....
1. you open your file...fine, file opens ok.
2. you read p from the input file, p is set to 23
3. you read alpha from the input file, alpha is set to 0.12
4. you read numkeys from the file, numkeys is set to 3
5. you set up a loop to loop from 0 to numkeys+1.
The loop does this:
1st iteration: assign key the next value in the file. -> key = 35
2nd iteration: assign key the next value in the file. -> key = 3
3rd iteration: assign key the next value in the file.....
But what's this? The next thing from the file is a full-stop/period '.' and not an int...so because key is an int, it's not being assigned anything, so it remains to be 3.
4th iteration: Again, it's another '.' and not an int, so the value of key does not change, the value of key is still 3.

Finally after the …

JasonHippy 739 Practically a Master Poster

To put dkalitas point a little more succinctly:
If you want to execute several statements under an if() statement, then you should enclose them with curly braces '{}'.
e.g.

if(condition)
{
    doSomething();
    something = something_else;
}
else
{
    foo=bar;
    bar=another_thing;
}

If you only want to use one statement under an if, then you don't need to use the braces...Braces are optional in that case!
e.g.

if (condition)
     doSomething();
else
    something = something_else;

or perhaps

if(condition)
    doSomething();

foo = bar;
bar = something;

if(foo==bar)
    doSomethingElse();

So in your code, because you haven't used any braces under any of your if() statements; The first statement under the if() will only get executed if the if statements condition is met...All subsequent statements will be executed regardless of the result of the if statement. (see dkalita's 2nd snippet. That's how the compiler will interpret your code without the braces!)

Cheers for now,
Jas.

dkalita commented: that was a detailed answer.... :) +1
JasonHippy 739 Practically a Master Poster

Yup you got it Raja, that's how you set up the path to the SDK and the path to the external flash player!

I've got my Flashdevelop set up to use the flashplayer10 debug executable!
Note: in the FlashViewer section of the program settings, ensure that the 'Movie Display Style' property is set to External!
'Popup' and 'Document' use the default player (fp 9 debug ActiveX)

In order to demonstrate tracing in flashdevelop, I've knocked a little example project together. (see attached files.)

To actually create the project, I've just gone to 'project->new project' in the menu and then in the dialog I've selected the 'AS3 Project' template and called the project Tracing.

Flashdevelop has now created a few directories (bin, lib and src) and files. Briefly exploring the generated files and folders:
The bin folder is where the final .swf will end up being built.
Initially the bin folder contains a html file which is set up to embed the final .swf using swfobject.js (found in the js sub-folder). It also includes expressinstall.swf, which is also used by the html page, in case people viewing the page have an older version of flash...in which case, it can download and install the correct version.

The lib folder is where you can put any assets for your project (Bitmaps fonts etc.). It should be noted that simply adding items to the lib folder does not make them instantly accessible to …

JasonHippy 739 Practically a Master Poster

Sorry I'm late to the conversation...Not been about today!

I'm on my linux box again, so I haven't got a copy of Flashdevelop open in front of me...But if memory serves, there is trace functionality built into Flashdevelop. It always used to be an external plugin, but I'm pretty certain it's finally been integrated into the IDE now.

Unfortunately, I think the trace functionality only works if the actionscript file is part of a project....It doesn't seem to work if you're building/testing a single standalone AS file that isn't part of a project.

Theres no need to create any .fla's or .swfs with CS4....No need for any of that at all..Although Flashdevelop does integrate really well with the Flash IDE's, so you don't have to completely abandon the Flash IDE if you don't want to. You can get the best of both worlds! Another advantage of having the Flash IDE installed (especially if it's the professional) is you can use the more advanced Flash components in your Flashdevelop projects! Anyway..going off topic there!

Where were we? Oh yeah!
If you want to use the trace functionality, all you need to do is create a new AS3 project using one of Flashdevelops built in AS3 templates...I'd pick one of the more minimal AS3 templates...(without seeing it in front of me I can't think exactly which template it is, but you should be able to work it out!)

Then start adding your classes to your project, …

JasonHippy 739 Practically a Master Poster

OK.
At the moment, Flashdevelop is only available for windows. (I believe there are mac and *nix ports in the pipeline...Not sure how well it runs on wine.). So Windows XP or Vista is the main prerequisite. (should also work on windows 7 too!)

The other main prerequisites are the Java 1.6 runtime and the flash player 9 active X runtime control (I think I use the debug version!). I think you might also need one of the .NET runtimes (2 or 3 I expect!). All of these are free downloads! If you're running vista or 7 then the appropriate .NET runtime will most likely be in place already.

Once you've got the pre-requisites installed, you'll also need the Flex 3 SDK...If you have Flash CS3 or CS4 installed, then the SDK is already installed somewhere (can't remember offhand what the default path is).
So if you have CS3/CS4, you need to locate the SDK and make a note of the path!

If you don't have CS3/CS4, or if you can't find the SDK, you can download the Flex3 SDK for free from Adobe. Once you've downloaded the SDK, unzip it somewhere on your hard-drive and make a note of it's location!

Next download and install the latest version of FlashDevelop from flashdevelop.org.
The installer is pretty straightforward...set your preferred installation options and away you go!

Once it's installed, fire it up and away you go!

Copy and paste the following …

JasonHippy 739 Practically a Master Poster

Here is another problem..for the purpose to inverse an array.

void reverse(const int list[], int newlist[], int size)
{
for(int i = 0, j = size - 1; i<size; i++, j--)
{
newlist[j] = list
}
}

i am not understand this function especially the for loop..anyone can kindly explain?
Thanks for advance ^^.

OK, well I'll step through it with you...
So you have two arrays, both of which must be of the same size and you're passing both arrays into the function along with the size.
And you want to know what's going on in the loop...

For this example we'll imagine we're passing two arrays into the function, both have three elements..so the size will be 3.
'list' contains the values 10,20,30, 'newlist' contains the values 0,0,0

Looking at the body of the loop:

{
    newlist[j] = list[i]
}

We can see that i and j are used to index the two arrays..i indexes the array 'list' and j indexes the 'newlist' array.

Looking at the initialisation section of the for loop:

for(i=0, j=size-1

so i is 0
j is set to size-1 (3-1=2)

In other words, i will initially index the front of the 'list' array (list[0]), whereas j initially indexes the back of the 'newlist' array (newlist[2]).

Looking at the break condition of the loop:

i<size;

We can see that the loop continues while the value …

JasonHippy 739 Practically a Master Poster

One thing you need to bear in mind if you are dealing with three high scores...

If somebody gets a new high score, you need to shift the exisiting high scores down a place. Dkalita's post doesn't take this into consideration, so if you ran Dkalitas example in your debugger and you had the following scores in 1st and 2nd place:
score1st = 85
score2nd = 68

If you entered another score of 98, Dkalitas example would give you this:
score1st = 98
score2nd = 68

But what you'd expect to see is this:
score1st = 98
score2nd = 85

So the first thing you need to do is shift the current high score down a place and then put the users score in the top spot!

Here's a simple example to show you what I mean...

#include <iostream>
using namespace std;

int main()
{
	int score1st=0, score2nd=0, score3rd=0, studentScore, count=0;

	for(;;++count) // loop forever!
	{
		cout << "Enter a student score (or enter a negative score to quit):";
		cin >> studentScore;

		if(studentScore<0) // break out of loop if studentScore is negative
			break;
		else if(studentScore>score1st) // new high score
		{
			// shift the 2nd highest score into 3rd place
			score3rd = score2nd;

			// shift the current top score into 2nd place
			score2nd = score1st;

			// finally put the students score into 1st place
			score1st = studentScore;
		}
		else if(studentScore > score2nd) // new 2nd highest score
		{
			// …
JasonHippy 739 Practically a Master Poster

Sorry, had a manic weekend and a long week at work this week!

Still not had a chance to get onto the ol' desktop at home to fire up CS3 yet.

But from what I can see of Raja's solution, it looks pretty good. But I'm determined to take a look at your files at some point!
If/when I do, I'll post anything I come up with.

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

dynamic_cast

void IObserver::Update(ISubject* observSubject){
  cout <<  dynamic_cast<Subject*>(observSubject)->getValue();
}

Hmm, using dynamic_cast is an option. But if the OP ends up creating several different classes derived from ISubject, then it would make more sense to make the getValue function a virtual in the base class and then override it in all derived classes. That way the code in Observer::Update remains short and succinct.

void Observer::Update(ISubject * obsevSubject)
{
    cout << observSubject->getValue();
}

Otherwise they'd have to perform several dynamic_casts to check every possible type. So you'd have to do something like this:

void Observer::Update(ISubject* observSubject)
{
    size_t output;
    if(dynamic_cast<Subject*>(observSubject))
        output =  dynamic_cast<Subject*>(observSubject)->getValue();
    else if (dynamic_cast<OtherSubject*>(obsevSubject))
        output = dynamic_cast<OtherSubject*>(observSubject)->getValue();
    else if ........ // ad nauseum for every derived type

   cout << output;
}

So dynamic_cast is an option if there aren't likely to be many classes derived from ISubject, but personally I'd probably still go with using a virtual in the base class!

Alternatively, if the getValue function is common to all derived classes and returns the same type of variable, then it may be worth percolating the functionality upwards into the base class!
i.e. make getValue a base class function and make value a member variable in the base class too!

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

I'm assuming that the posted code are just snippets...So I'll assume that you've declared/defined an Observer class and actually defined the getValue function.....Both of those are missing from the posted code...

Looking at the rest of the code, the only other thing that seems odd is the fact that the getValue function is a member of the derived class Subject, but is not a member of the base class ISubject.

Bearing that in mind...
Where you're using a pointer to an ISubject object in your Observer::Update function, I don't think the getValue function will be visible to the ISubject pointer.

But if you make the getValue function a virtual or pure virtual member of the base class ISubject, then the version delcared in the Subject class should get treated as a polymorphic override and will therefore be called. So if the ISubject pointer points to an instance of a Subject object, then the Subject::getValue will be called in the Observer::Update function....At least, that's how it looks to me, judging by the snippets you've posted!

If that's not the solution to the problem, perhaps .zip up your code and attach it here so we can take a more detailed look!

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

I'm currently listening to the unmistakable sound of tinnitus...
Everybody sing along if you know the words, come on you know how it goes. It goes:
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee.... heh heh!

Funnily enough, unless my sense of pitch is out, it's currently ringing at somewhere around an e...Hang on no, it seems diatonic, is that a c I can hear below it? Wow, I've got high pitched chords going on in my head!!
With the pounding of my eardrums, this is starting to resemble some kind of wierd industrial noise track.... Like Merzbow, or Whitehouse... Aaagh, I can't stop analysing it now!

Methinks 'tis time to drown it out with something a little more musical before it sends me completely sideways!

Remember: If the music's too loud, you're not deaf enough yet!" - heh heh! ;)

JasonHippy 739 Practically a Master Poster

just thinking... wouldnt it have made more sense to just change "Program files" to "Program_files" or something similar?

Not really, because in MS Windows the 'Program Files' folder is the system default folder for programs to be installed in (and there are usually a lot of programs installed there!).

Simply renaming the 'Program Files' folder to 'Program_Files' would cause most (if not all) of your programs to either malfunction, or not work at all when you tried to run them.
The OS probably wouldn't take it too well either!

Plus any shortcuts you have for any programs in the 'Program Files' folder will also stop working...(e.g. desktop shortcuts and start menu links)

So in this case...No! Changing the folder name would definitely not be the best option. Ene's line of code is by far the best solution to the problem!

Cheers for now,
Jas. :P

JasonHippy 739 Practically a Master Poster
os.system('"C:/Program Files/IrfanView/i_view32.exe" ' + filename)

Dammit...I thought I'd tried that combination of string in string earlier..... Obviously that was one permutation I missed!

Hang on....Looking back at my failed scripts from when I was playing around, I had the " and the ' the wrong way around! Damn these fat drummer fingers! grrr! heh heh! :D

Thanks for that Ene! Yes that's far better than my solution!

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

I've just done a bit of digging around on python.org and found this:
http://bugs.python.org/issue1524

Looks like I'm not the first person to come up with this workaround....See the post made by daniel.weyh on the 25th June 2008.

Jas.

JasonHippy 739 Practically a Master Poster

It took a bit of playing around, but think I've found a workaround for this....

I noticed in the docs for os.system() (Yes I RTFM!) it mentions that the subprocess.call() should be used instead.
So I had a go with subprocess.call() but I soon ran into very similar problems, it still didn't like the spaces in the path.

After a bit of playing around and using a bit of lateral thinking I decided to try using subprocess.call() to call 'cmd.exe' passing it the path to a program in 'Program Files' as a parameter.

Now, I don't have winamp installed on my pc, so I decided to try and fire up Audacity using the following code:

import subprocess

subprocess.call(r'C:\WINDOWS\system32\cmd.exe /C "C:\Program Files\Audacity\audacity.exe"')

And you know what?? It bloody works!

After that, I decided to try using os.system in exactly the same way (use it to fire up cmd.exe with the path to Audacity as a parameter):

import os

os.system(r'C:\WINDOWS\system32\cmd.exe /C "C:\Program Files\Audacity\audacity.exe"')

Guess what??
That worked too!

Woot woot! :)

You'll get a little cmd window that will pop-up alongside whatever program you fire up, but it will disappear when you close the program down again.

So, all you need to do is copy one of the bits of code posted above and then replace my path to Audacity with the path to your installation of Winamp!

Hope that solves your problem.
Cheers for now,
Jas.

pysup commented: cool.. Thanks +1
JasonHippy 739 Practically a Master Poster

Ok, here are my answers...

My life according to Frontline Assembly

Are you a male or female?
Gun

Describe yourself:
Dissident

How do you feel?
Outcast

Describe where you currently live:
Plasma springs

If you could go anywhere, where would you go?:
Vanished

What is your favorite form of transportation:
Machine Slave

Your best friend[s] is[are]:
Parasite

You and your best friends are:
Lowlife

What's the weather like?:
Heat Wave

Favourite time of day?
Armageddon

If your life was a TV show, what would it be called?
Maniacal

What is life to you?
Mental Distortion

Your current relationship?
Laughing Pain

Your greatest fear?
Humanity

What is the best advice you have to give?
Resist

Thought for the Day?
Everything Must Perish

How would you like to die?
Virus

Your soul's present condition is:
Burnt Soul

Your motto is:
Don't trust anyone


Wow, those were some cheery answers! I had considered using A.C. as the band, but most of the replies would've been too rude! heh heh!

J.

JasonHippy 739 Practically a Master Poster

Being a miserable sod, I don't usually do crap like this. But what the hell?! I'm bored!

Using only song titles from ONE ARTIST, cleverly answer these questions.. Don't repeat a song title. It's a lot harder than you think!
Copy the following text into your post and then answer the questions/statements..

My life according to {insert band name here}...

Are you a male or female?

Describe yourself:

How do you feel?

Describe where you currently live:

If you could go anywhere, where would you go?:

What is your favorite form of transportation:

Your best friend[s] is[are]:

You and your best friends are:

What's the weather like?:

Favourite time of day?

If your life was a TV show, what would it be called?

What is life to you?

Your current relationship?

Your greatest fear?

What is the best advice you have to give?

Thought for the Day?

How would you like to die?

Your soul's present condition is:

Your motto is:

OK, I'll go first...repost will follow shortly...

JasonHippy 739 Practically a Master Poster

// Doh...that was wrong! {snipped}

JasonHippy 739 Practically a Master Poster

hmm, I got 6 out of 10...
Score said 5-6 > Not too shabby..

So I guess what I've heard people saying about me is true...I am a bit of a bar-steward!
At least, that's what I think they've been saying! ;) heh heh!

I couldn't take the other test...The website could not be found...Doh!

JasonHippy 739 Practically a Master Poster

3 out of 3....Not dumb!
(Phew!)