[QUOTE=alexRivera;1153759]yes[/QUOTE]

[CODE]while( one < SIZE && two < SIZE )
{
a = heap1.returnvalue(one);
b = heap2.returnvalue(two);
if( a <= b)
{
a++;
}
else
{
cout<< b << endl;
b ++;
}
}[/CODE]

This looks as though it is going to be an infinite loop consider the size of SIZE and how both one and two are going ever going to be either > or equal to SIZE.

[QUOTE=alexRivera;1153251]actually nothing i just get a error message telling that 'a' and 'b' haven't been declared. the problem i'm having is setting up the merge between the two heaps.[/QUOTE]

Hi,
I see, so you have solved problem by formally declaring a and b?

Am I right in saying you want to merge heaps 1 and 2 into a third heap but in ascending order?

Hi, AlexRivera,

What does happens during execution of the program in the part you have pointed out?

Is the loop infinite?

Yeah multimap would only be good if you had pairings. multiset would be better.
Similar to multimap and would work for what you want.

The multimap allows you to store key value pairs with the same key. It has functions like count which would be useful for your type of thing.

You can read it up here:

Hi gamerchick.

So, what is the problem?

Any joy Ayesha or are you still stuck?

Sorry I meant

[CODE]
string RINGS[rings];
string letters;
for (int i=0; i<rings; i++)
{
getline(inFile,letters,'\n');
RINGS[i]=letters;
}
[/CODE]

Indeed we do not know the number of rings for the cryptex but once the user enters the number of rings which you do prompt him/her to do so we then know the size of the array.

This should work

I think your error might be a segmentation fault.

Try this:

[CODE]
string RINGS[N];
string letters;
for (int i=0; i<rings; i++)
{
getline(inFile,letters,'\n');
RINGS[i]=letters;
}
[/CODE]

That should work.

Hi Ayesha91,

How is the order of the letters in the file?

Is each ring separated by spaces or each individual ring is on a separate line?

Hi green_leav

I have sort of a solution but I not going to give it all to you but rather guide you.
First let me suggest you use strings if you want to avoid the 2d char arrays at least directly seeing as you are new to c++;

Let us look at the example in your assignment description:

KFZLQMDWJUSHGCEIXRAOPNVTYB
IMWZPFJBKLTNOEQDHUXGVYASRC
FAMIETZORWPSQUNGLDYBKXHCVJ
XNAKVPICQHDFWEGBRTMLZOUSYJ
ZSYFDOWIJCAKPBTXLRUNGQMVHE

The Unlocking word is Green with the secret word being Apple right?
[CODE]

void align(std::string keys], std::string unlocking_word)
{
for(int a=0;a <= unlocking_word.length()-1;a++)
{
while(keys[a].at(i)!= unlocking_word.at(a))
{
}
}
int main()
{
int n;
std::cout<<"Enter number of keys"<<std::endl;
std::cin>>n; //=5
std::string keys[n]; //we declare an string array

//here are the keys from your assignment description.
s = "KFZLQMDWJUSH[B]G[/B]CEIXRAOPNVTYB";
s = "IMWZPFJBKLTNOEQDHUXGVYAS[B]R[/B]C";
s = "FAMI[B]E[/B]TZORWPSQUNGLDYBKXHCVJ";
s = "XNAKVPICQHDFW[B]E[/B]GBRTMLZOUSYJ";
s = "ZSYFDOWIJCAKPBTXLRU[B]N[/B]GQMVHE";

``````std::string unlock_word = "GREEN"; //the unlocking word
[B]align(keys, unlock_word)[/B]; // we pass the keys and unlock word(GREEN) as //parameters to the method align
return 0;``````

}
[/CODE]

In the function [B]void align(std::string str[], std::string unlocking_word) [/B]we need start a for loop to loop once for each letter in the unlocking word GREEN which is 5 but c++ string are char arrays which start at 0. so we need to stop it one short of 5 because 0 is a valid position ant that is where G goes R goes to 1. E goes to 2 E goes to 3 and N goes to 4 \n goes to 5 this terminates the string e.g:
[\n]
G R E ...

Hi Wilen,

What does your code look like?

[QUOTE=green_leav;1084612]dear GrubSchumi,

first of all the user will enter the number of test cases (2) then the number of rings (5) and next the unlocking word which is GREEN and finally the secret word _P___ but my problem is how can i let the program find the rest of the secret word lettes? and how can i get a help from the unlocking word?[/QUOTE]

It is likely that the unlocking word is a char array itself.

Use a loop to search the first sequence

e.g. GREEN being the unlocking word

[CODE]
char unlocking_word [] = "GREEN";

void align(char s[], char [] unlocking_word)
{}
[/CODE]

then you have a loop that looks for the G in

[COLOR="Green"]KFZLQMDWJUSH[/COLOR][COLOR="red"]G[/COLOR]CEIXRAOPNVTYB
While looping saves the chars in green into another temp char array. Once finding G we then replace the Green chars in the original char with G and the proceeding black characters then concatenate the green characters from the temp char array back onto the original char array etc...

Sorry if that is not too clear. Again come back if you want further help.

Hi green_leav,

Who provides the test cases?

What I mean by this is, do you have to devise the rings and secret words yourself i.e

KFZLQMDWJUSHGCEIXRAOPNVTYB
IMWZPFJBKLTNOEQDHUXGVYASRC
FAMIETZORWPSQUNGLDYBKXHCVJ
XNAKVPICQHDFWEGBRTMLZOUSYJ
ZSYFDOWIJCAKPBTXLRUNGQMVHE

or do you have to devise the program which at runtime will take a set of keys during the test?

If you are to provide your own rings then the first step is to devise your unlocking word and then your secret word else

You would likely need a 2d array of char something like this:

[CODE]
void align(char s[])
{
....................
}
int main(int argc, char **argv)
{
int n;
std::cout<<"Enter number of Rings"<<std::endl;
std::cin>>n;
char s[n];
align(s);

................................

``return 0;``

}
[/CODE]

This is very skeletal but I think should give ideas.

Feel free to tell me what you think.

hi,

Why do you need to convert it to characters?

Hi,

GetLength should not be void and should return an int
so rather

[CODE]
int MyString::getLength(char [])
[/CODE]

Hi,

If the first name second name and phone number are consistently in this order throughout the file then an ifstream read object in a while loop may work;

[CODE]
read>>firstnamearray[n]>>lastname[n]>>phonenumberarray[n];
n++;
[/CODE]

[QUOTE=dkalita;1065592]Incorrect syntax.

When u write string y it declares an array of string with 0 elements and if u want to initialize them write
[CODE]
string y[] = {"dog", "cat"};
[/CODE][/QUOTE]
Yes, My bad.

It is also likely to print out trash along with the "dog, cat". I refer to the method I suggested.

Hi,

Why not make an array of strings and return to a pointer.

So rather you have

[CODE]
string * Test::getNames(string[] names)
{
string y = "dog";
y = "happy";
y = "night";"
return y;
}

[/CODE]

that might work.

Hi,

Your algorithm is incorrect: Let us assume we want 5 test numbers entered in the order 10, 9, 8 7, 6

So tha array would be like this:

          ['\n'] Remember you declared and array of: int scores

[CODE]
void SortNumbers()
{
cout <<"the sorted list is ";
for(i= 0; i <= num; i++)
{
if(scores[i]>scores[i+1])
Swap(scores, i);
cout << scores[i] << " ";
}
cout << endl;
}
void Swap(int scores[], int i)
{
int temp;
temp = scores[i];
scores[i]=scores[i+1];
scores[i+1] = temp;
}

[/CODE]

          ['\n']

Your for loop begins and compares 10 and 9 finding 10 is greater than 9 and thus going int the swap function and swaps giving us this:

          ['\n']

It then exits and returns to the sortNumbers() function and prints
scores which is 9 then i++. It then takes 10 which is now in scores and compares to scores which is 8 and indeed 10 is greater than 8 so back into the swap function to swap and back to sortNumber and print scores which is 8. The array looks like this:

          ['\n']

Let us extrapolate: after 6 the comparison continues because 10 is greater than 0

          ['\n']

So after for(i= 0; i <= ...

Hi,

I think you mean
[CODE]
int calcTotal(int sales)
{
//declare variables
int company = 0;
//sales accumulator
for (int row = 0; row < 6; row = row + 1)
for (int col = 0; col < 2; col = col + 1)
//accumulate sales
company = company + sales[row][col];
//end for col
//end for row
return company;
} //end of calcTotal function
[/CODE]

that should work if you array is always going to be fixed to  but will not if the size varies.

Hope this helps.

[QUOTE=mymyzzz;1064329]void SortNumbers()
{
cout <<"the sorted list is ";
for(i= 0; i < num; i++)
{
if(scores[i]>scores[i+1])
Swap(scores, i);
cout << scores[i] << " ";
}
cout << endl;
}
this is what i have done differently, the num being how many values i had, when i put in 5 for num, and values, 20, 39, 49, 70, and 10,
program prints 0, 10, 20, 39, 49.
why does it do this?[/QUOTE]

Hi,

many thanks for the response

If we go back to where you enter the numbers.
[CODE]
for(int i=1; i <=num; i++)
{
do{
cout <<"enter score " << i << ": ";
cin >> scores[i];
if((scores[i] <= 0)||(scores[i] >=100))
cout << "invalid score\n";
}while((scores[i] <= 0)||(scores[i] >=100));
//this is where i input the scores.
[/CODE]

Particularly your for([COLOR="Red"]int i=1[/COLOR]; i <=num; i++)

[CODE]
void SortNumbers()
{
cout <<"the sorted list is ";
for(i= 0; i < num; i++)
{
if(scores[i]>scores[i+1])
Swap(scores, i);
cout << scores[i] << " ";
}
cout << endl;
}
[/CODE]

for([COLOR="Red"]i= 0;[/COLOR] i < num; i++)

Notice the two for statements. When you input you are starting at array position 1 and then when printing you are starting at array position 0. Position 0 has nothing so it prints 0.
So change the first for loop int to = 0 as well.

[QUOTE=mymyzzz;1064319]thank you, it kinda worked, because when i put in my inputs, it will read in 0, and not the highest number.... what is going on?[/QUOTE]

Hi,

Please may explain it again, I am not sure I follow.

Hi,

I think your problem is actually in the
[CODE]
void SortNumbers()
{
cout <<"the sorted list is ";
for(i= 0; i <scores; i++)
{
if(scores[i]>scores[i+1])
Swap(scores, i);
cout << scores[i] << " ";
}
cout << endl;
}
[/CODE]

for(i= 0; i <[COLOR="Red"]scores[/COLOR]; i++)

rather I think your want the length of the array, I.e to walk trough the length all the values in the array making the comparisons and swaping. So for this we should rather write

[CODE]
for(i= 0; i <sizeof(scores) / sizeof(int); i++)
[/CODE]

Hi tasky23,

You need a bit more to open the file. Declaring an instance of ifstream is the correct start but it should read:

[CODE]
ifstream infile2;
//then to open the file.
infile2.open("file.txt",ios::in);
[/CODE]

then you may do your infile2 >> Player.Name;

Hope that gets you on the right path.

In your while(ture) statement where you ask the user to to select an option you have

[CODE]
cin>>cInput;
[/CODE]

immediately proceeding that put cin.ignore() to remove the '\n' which is always left in the input stream following the use of cin>>.

So it should look like this.

[CODE]
cin>>cInput;
cin.ignore();
[/CODE]

so from getline(cin.ignore(), to_modify) remove the .ignore() and simply have getline(cin, to modify).

Hi Annettest,

Sorry for the delay. Ok on to the first question or I may be able to answer both at once:

1) I'm not sure that I am clear on what is going on here (from yesterday's code example). What is your translation? I am particularly confused about where x and y are coming from.

T& operator(double x, double y) { return grid[ y*xsize + x ]; }

A) double x, double y are parameters being passed to the operator that is being overloaded. in C++ we have function overloading where and inheriting class changes the functionality of a function it inherited from a parent class. We also have operator overloading where we change the functionality of the operator. examples of operators in c++ are the following:

+
=
• new
delete
etc..........

There are quite a few to list all. In the code you have the operator appears to be missing because it should read:

[CODE]
T& operator+(double x, double y) { return grid[ y*xsize + x ]; }
//or
T& operator==(double x, double y) { return grid[ y*xsize + x ]; }
//or
T& operator new(double x, double y) { return grid[ y*xsize + x ]; }
[/CODE]

depending on the operator you are overloading. Right now as it is, it will not compile.

The double x and y parameters are used to find the location in the array. For example imagine we have an array please keep in mind we have a single dimension ...

Hi,

Ok your first question:

1) So, regarding the template method you described first, what you are saying is that the whole point of the template is so that I can take a struct or class of fluidProperties and have them have all the functionality of the template class, Grid2D?

A) Yes. The template <typename T> allows for flexibility in that typename is the data type like int, or a class and struct defined by the user. <typename T> can be any type and is used if to make a generic class where the <typename T> needs to change depending on the needs of the user. So we have the generic class declared and I want to use the datatype int I would correctly write:

[CODE]
Grid2D <int> grid;//correct
[/CODE]

That means every instance of T in the class is now an int. At the same time I want to use the same class but with fluidProperties, I will say:

[CODE]
Grid2D <fuildProperties> grid; //correct as well
[/CODE]
All references to 'T' in Grid2D now are of type fluidProperties
without any need to make modification to the original declaration of class Grid2D.

2) Where I'm getting confused is in defining the size the the grid. In your first piece of code below the struct definition, you have this:

T grid;

But I already define my grid size parameters in the Grid2D class. How does your line above fit in with what I already defined in the Grid2D class? In other ...

Hi,

Firstly, you would need to construct a data struct defined by you. I do not know the details of the struct properties but the struct would look something like this:

[CODE]
struct fluidProperties //this struct contains the properties
{
string name; //name of the fluid this type is only for example.
//some type property1;
//some type property2;
//some type property3;
//ect...
};
[/CODE]

The class then appears although at this stage we can go straight to the main method because you want to link the the struct of fluid properties to the grid but what we are actually creating is a grid of struct fluidProperties. What we can do is make a 2d array (grid) of struct fluidProperties e.g:

[CODE]
template <typename T>
class Grid2D
{
private: // or public: which ever suits your needs
T grid;
};

int main()
{
Grid2D<fluidProperties> grid2DObject;
return 0;
}
[/CODE]
The reason we have Grid2D<fluidProperties> grid2DObject; is because of the template keyword used prior to declaring the class Grid2D. This means that the typename T are fluidProperties data types. You could also say Grid2D<int> grid2DObject that now means typename T are of int data type.

T grid is a 10 * 10 grid you declare the object like this if you know in advance the size of the grid however if the size of the grid is subject to change depending on your needs you might want to dynamically allocate the memory i.e the size of grid2D grid is not always fixed ...

Hi,

I take it it does not compile. I think you would need a good c++ book. Because just to pick things up to create what you are trying to create.

Firstly before the template declaration you need the statement "using namespace std;"

the class members xsize, ysize, grid need types

Then your constructors need to be named exactly as the class for which they are defined for e.g

[CODE]
using namespace std;
template <typename T>
class Grid2D
{
int xsize, ysize, grid;
public:
Grid2D() : xsize(0), ysize(0), grid(0) { }

[/CODE]