I'm not sure what the restrictions are or how you're supposed to handle it, but you can make a new preprocessor variable NUMQUEUES set to the number of Queues you'd like to handle. Within RunSimulation create a "vector<Queue<int> > vQueues(NUMQUEUES)" in lieu of the original Queue. Immediately after the time for loop, create a for loop through the Queues:Sapiens said:Can anyone help me here.
I have no idea where to start. But I'm burned out. I have to take this program and edit it so that it has support for multiple queues.
for (vector<Queue<int> >::iterator iQueue = vQueues.begin(); iQueue != vQueues.end(); ++iQueue)
{ ... }
Sapiens said:Can anyone help me here.
I have no idea where to start. But I'm burned out. I have to take this program and edit it so that it has support for multiple queues.
typedef vector< float > FloatVector;
ODEsolver::FloatVector etc
FloatVector fv = FloatVector(size, initValue);
I believe that your problem is that you're trying to use the typedef as if it were a static instance of an object (referring to it as ODEsolver::FloatVector) when a typedef cannot be made into a static since it cannot be made into an object instance.Zoramon089 said:Grr, having some more trouble. So, I have those same .h and .cpp files.
In my ODEsolver.h file, in public I have
Code:typedef vector< float > FloatVector;
And whenever I need to refer to it in ODEsolver.cpp I call
and call whatever on it. The problem is that vector has a default constructor where you can enter in the capacity and fill it with a value which I can do in the .h file byCode:ODEsolver::FloatVector etc
Code:FloatVector fv = FloatVector(size, initValue);
The problem is whenever I try calling that in the source file it won't let me use that constructor. In fact, it doesn't even recognize FloatVector at all. If I mouse over it in Visual C++ it says typedef<error-type> which I have no idea what that means
string name;
cout << "Enter Full Name: ";
getline(cin, name);
cout << endl << "Your Name: " << name << endl<< endl;
phalestine said:Code:string name; cout << "Enter Full Name: "; getline(cin, name); cout << endl << "Your Name: " << name << endl<< endl;
ok so lets say the input was entered as First Middle Last,
How would I have it print First M. Last or Last, First M. ? Any hints?
CrankyJay said:string[] splitName = name.split(' ');
printf("%s %c. %s, splitName[0], splitName[1].CharAt[0], splitName[2]); // First M. Last
printf("%s, %s %c, splitName[2], splitName[0], splitName[1].CharAt[0]);// Last, First M.
phalestine said:still couldnt get it to work, I see what you're doing though you are looking for an empty space ' '. I was thinking of using "find(url)" but not sure how to do it exactly.
CrankyJay said:One of the string libraries has a method in there called split which will let you specify a character, in this instance a space, to split a string by into an array of strings.
It may be <stdstring> or <stdstring.h>
or just <String>
or <stdio> ... haha, one of those.
Haven't done C++ in awhile but that should put your on the right path.
Here's how I would do it:phalestine said:Code:string name; cout << "Enter Full Name: "; getline(cin, name); cout << endl << "Your Name: " << name << endl<< endl;
ok so lets say the input was entered as First Middle Last,
How would I have it print First M. Last or Last, First M. ? Any hints?
string first, middle, last;
cin>>first>>middle>>last;
cout<<endl<<"Your Name: "<<last<<", "<<first<<" "<<middle.substr(0, 1)<<"."<<endl;
It's defined in <string>, but I'm pretty sure std::string doesn't have a split method.CrankyJay said:One of the string libraries has a method in there called split which will let you specify a character, in this instance a space, to split a string by into an array of strings.
It may be <stdstring> or <stdstring.h>
or just <String>
or <stdio> ... haha, one of those.
Haven't done C++ in awhile but that should put your on the right path.
CrayzeeCarl said:Here's how I would do it:
Code:string first, middle, last; cin>>first>>middle>>last; cout<<endl<<"Your Name: "<<last<<", "<<first<<" "<<middle.substr(0, 1)<<"."<<endl;
Chichikov said:It's defined in <string>, but I'm pretty sure std::string doesn't have a split method.
You'll need to use find and substr.
Chichikov said:It's defined in <string>, but I'm pretty sure std::string doesn't have a split method.
You'll need to use find and substr.
Actually, there is a split method for char*'s. The method "strtok" tokenizes a c string, thus allowing you to split it on the match of a substring (c string).Chichikov said:It's defined in <string>, but I'm pretty sure std::string doesn't have a split method.
You'll need to use find and substr.
/* strtok example */
#include <stdio.h>
#include <string.h>
int main ()
{
char str[] ="- This, a sample string.";
char * pch;
printf ("Splitting string \"%s\" into tokens:\n",str);
pch = strtok (str," ,.-");
while (pch != NULL)
{
printf ("%s\n",pch);
pch = strtok (NULL, " ,.-");
}
return 0;
}
Output:
Splitting string "- This, a sample string." into tokens:
This
a
sample
string
#include <iostream>
using namespace std;
double larger (double x, double y)
{
double tempmax;
double max = 0;
if (x > y)
tempmax = x;
else
tempmax = y;
if (tempmax > max)
max = tempmax;
return (max);
}
int main()
{
double max;
cout << "Enter 15 Numbers" << endl;
for (int counter = 0; counter<8; counter++)
{
double x;
double y;
double tempmax;
cin >> x;
cin >> y;
tempmax = larger (x,y);
}
cout << "The largest number is " << max << endl;
return 0;
}
#include <iostream>
using namespace std;
double larger (double x, double y);
int main()
{
double x;
double y;
double tempmax;
double max = 0;
cout << "Enter 16 Numbers" << endl;
for (int counter = 0; counter<8; counter++)
{
cin >> x;
cin >> y;
if (x > y)
tempmax = x;
else
tempmax = y;
if (tempmax > max)
max = tempmax;
}
cout << "The largest number is " << max << endl;
return 0;
}
thanks for the help you too TheExodu5, brained farted with the two inputs in the for loopToby said:double max;
cin>>max;
double temp;
for(int count=0;count<14;count++)
{
cin>>temp;
max=larger(max, temp);
}
Edit: oh, returning double. Max is a double then.
Toby said:I figure this is a good place to ask:
Would knowledge of Python/Perl, Java, and C#&.net be beneficial when looking for a job?
My CS outline only requires me to do one. I have a better opportunity to do C# and .net this semester, but I also know I want to do Java.
Should I spend the extra $ to learn all of them?
Once you learn a programming language, you shouldn't really need to spend any money to learn another one. You should be able to pick it up with books or online resources.Toby said:I figure this is a good place to ask:
Would knowledge of Python/Perl, Java, and C#&.net be beneficial when looking for a job?
My CS outline only requires me to do one. I have a better opportunity to do C# and .net this semester, but I also know I want to do Java.
Should I spend the extra $ to learn all of them?
Toby said:I figure this is a good place to ask:
Would knowledge of Python/Perl, Java, and C#&.net be beneficial when looking for a job?
My CS outline only requires me to do one. I have a better opportunity to do C# and .net this semester, but I also know I want to do Java.
Should I spend the extra $ to learn all of them?
I agree with this. If I were you, I would just stick with C# and focus on extending your knowledge into either database or web (or both).ianp622 said:Once you learn a programming language, you shouldn't really need to spend any money to learn another one. You should be able to pick it up with books or online resources.
This looks like a good C# book.Toby said:Are there some good books on python/java/C# that give you programming assignments to complete?
Edit: Agree with this as well. It's better for you to be good enough at one language to actually build real-world applications than to have just experimented with several.Chichikov said:Pick one and stick with it.
Pick one and stick with it.Toby said:I figure this is a good place to ask:
Would knowledge of Python/Perl, Java, and C#&.net be beneficial when looking for a job?
My CS outline only requires me to do one. I have a better opportunity to do C# and .net this semester, but I also know I want to do Java.
Should I spend the extra $ to learn all of them?
CrayzeeCarl said:This looks like a good C# book.
i=argNum+1;
char* part = argv[i];
while(strstr(part,".")==NULL)
{
strcat(part, "_");
i++;
strcat(part, argv[i]);
}
Zoramon089 said:Looping over a structure called argv, with argNum values. The values are:
title
01.txt
Zoe said:So let me make sure I understand this. You have an array of strings, argv = {"title", "01.txt"}. Is argNum equal to 1 or 2?
i=argNum+1; // i = 0 + 1 = 1
char* part = argv[i]; // part = "title"
if (strstr(part,".")==NULL) // "title" does not contain "." -- passes
{
strcat(part, "_"); // part = "title_"
i++; // i = 1 + 1 = 2
strcat(part, argv[i]); // part = "title_01.txt"
}
if (strstr(part,".")==NULL) // "title_01.txt" contains "." -- fails
{}
Better get used to thatZoramon089 said:NEVER MIND
The problem was this stupid Athena computer system...basically Linux sucks, copying from a pdf removed characters that shouldn't have, it screwed up the tokenization and made them separate indices instead of together...etc, just forget it. So pissed
deadbeef said:Better get used to that99% of the time everything will be broken, then you finally fix it, say "neat!", and then move on to something else that's broken, haha
Haha compiler bug? Reeks of desperationZoramon089 said:Yeah, I'm already onto the next problem, random Seg Faults in an array that is already initialized. I tried asking someone and they said it might be a "random transient bug in the compiler" Really?!
60_gig_PS3 said:seg faults are not random you probably overran the array
An array of pointers is what you want?Zoramon089 said:Mmm, I dunno...I can't find anywhere I did.
Ok so the array is initialized like this
theType* data = new theType[width * height];
data[0] = theTypeObj;
SEG FAULT
And for some reason, just printing out a character over a for loop is getting some very strange output printed when it's done (./a4 is the command to run)
*** glibc detected *** ./a4: double free or corruption (!prev): 0x00000000010f3070 ***
*Random numbers and letters here*
Zoramon089 said:Mmm, I dunno...I can't find anywhere I did.
Ok so the array is initialized like this
theType* data = new theType[width * height];
data[0] = theTypeObj;
SEG FAULT
And for some reason, just printing out a character over a for loop is getting some very strange output printed when it's done (./a4 is the command to run)
*** glibc detected *** ./a4: double free or corruption (!prev): 0x00000000010f3070 ***
*Random numbers and letters here*
Zoramon089 said:Mmm, I dunno...I can't find anywhere I did.
Ok so the array is initialized like this
theType* data = new theType[width * height];
data[0] = theTypeObj;
SEG FAULT
And for some reason, just printing out a character over a for loop is getting some very strange output printed when it's done (./a4 is the command to run)
*** glibc detected *** ./a4: double free or corruption (!prev): 0x00000000010f3070 ***
*Random numbers and letters here*
Zoramon089 said:Mmm, I dunno...I can't find anywhere I did.
Ok so the array is initialized like this
theType* data = new theType[width * height];
data[0] = theTypeObj;
SEG FAULT
And for some reason, just printing out a character over a for loop is getting some very strange output printed when it's done (./a4 is the command to run)
*** glibc detected *** ./a4: double free or corruption (!prev): 0x00000000010f3070 ***
*Random numbers and letters here*
#include <iostream>
using namespace std;
class TestClass {
public:
TestClass() {}
void soundOff() {
static int n = 0;
cout << "TestClass " << n << " reporting" << endl;
++n;
}
};
int main(int argc, char** argv) {
int k = 10;
TestClass* pTest = new TestClass[k];
for (int i = 0; i < k; ++i) {
if (pTest) {
pTest[i].soundOff();
++pTest;
} else {
cerr << "pTest == NULL";
return -1;
}
}
return 0;
}
./a.out
TestClass 0 reporting
TestClass 1 reporting
TestClass 2 reporting
TestClass 3 reporting
TestClass 4 reporting
TestClass 5 reporting
TestClass 6 reporting
TestClass 7 reporting
TestClass 8 reporting
TestClass 9 reporting
Zoramon089 said:Mmm, I dunno...I can't find anywhere I did.
Ok so the array is initialized like this
theType* data = new theType[width * height];
data[0] = theTypeObj;
SEG FAULT
And for some reason, just printing out a character over a for loop is getting some very strange output printed when it's done (./a4 is the command to run)
*** glibc detected *** ./a4: double free or corruption (!prev): 0x00000000010f3070 ***
*Random numbers and letters here*
This will not compile.wayward archer said:try this:
int x = width * height;
theType *data = new theType[x];
theTypeObj *y = new theTypeObj(whatever args);
data[0] = y;
new will by default throw a std::badalloc exception on failure. It will never return null.Chichikov said:Did you make sure the allocation succeeded (i.e. returned pointed isn't null)?
You might be getting out of memory there (which is quite possible if your width and/or height are large numbers).
This is too vague for me to help you with. Post real code.Zoramon089 said:Mmm, I dunno...I can't find anywhere I did.
Ok so the array is initialized like this
theType* data = new theType[width * height];
data[0] = theTypeObj;
SEG FAULT
And for some reason, just printing out a character over a for loop is getting some very strange output printed when it's done (./a4 is the command to run)
*** glibc detected *** ./a4: double free or corruption (!prev): 0x00000000010f3070 ***
*Random numbers and letters here*
That's true if -Slavik81 said:new will by default throw a std::badalloc exception on failure. It will never return null.