vectors

Hello triying to simplify my code I obtain a lot of mistakes
for example I don't know how I must prototype the funtion combinacion that brings two vectors...

thanks

#include <iostream>
#include <string>
//#include <ginac/ginac.h>

using namespace std;
//using namespace GiNaC;

void combinacion(string, string);
void setFormula(int, int);
vector<string> fact;
vector<string> operacion;
int main()
{
/* symbol r("r"), M("M"), teta("teta");
ex g00 = 1-2.0/r;
*/
combinacion(fact, operacion);

return 0;
}

void combinacion(string factor,string operacion)
{

fact=["r","M","teta","1","2"];
operacion["+","-","*","/","^","sin"];
for(int j=0;j<=4;j++)
{
for(int i=0;i<=5;i++)
{
setFormula(j,i);
}
}
}
void setFormula(int j, int i)
{
formula = getFactor(j) + getOperacion(i) //+ formulaN;
cout<<"formula...= "<<formula<<" j="<<j<<" i="<<i<<endl;
// formula=formulaN;
}
Hello psosmol,



PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code.

Along with the proper indenting it makes it easier to read your code and also easier to respond to your post.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.

I found the second link to be the most help.



To start with before you can use a vector you need to include the header file "<vector>".

Lines 10 and 11 are better put in "main" and not defined as global variables.

To pass the variables "fact" and "operation" to a function it would look like this:
void combinacion(). Since "fact" and "operation" are global variables the whole file has access to them. By passing them to a function you create local variables to that function which overshadows the global variables.

If you define "fact" and "operation" inside "main" to pass them to a function the function definition would be:
void combinacion(std::vector<std::string> fact, std::vector<std::string> operacion).

I am guessing that lines 29 and 30 are to put information into the vector. If so this is not the way to do it.

In the function "setFormula" you need to define formula before you can sue it. Also the two "get" function are not defined anywhere.

Looking at your program you might want to start with:http://www.cplusplus.com/doc/tutorial/

And for vectors: http://www.cplusplus.com/reference/vector/vector/

You might define "operation" as: const std::vector<char> operacion{'+', '-' ,'*', '/', '^', 's'}; If your idea is for the user to enter information that will end up in "operation then it would be:
std::vector<char> operacion;. Since most of the operators are a single character this would work better as a type "char" and for "sin" just use "s".

I can usually figure out a program, but this on has me perplexed and disheveled.

You can start by letting people know what your intentions are for the program.

Hope that helps,

Andy
Hello, I have new problems with my code :
error: no match for call to
I don't know what it means

thanks
the code is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <string>
#include <vector>
#include <ginac/ginac.h>

using namespace std;
using namespace GiNaC;

void setRama(vector<string>, vector<string>);
void setRamaPrim(vector<string>,vector<string>);
//vector<vector<string>> rama{4,5};
//vector<vector<string>> rama;
vector<string> rama;
vector<string> ramaPrim;
string oper="";
int n=0;
int main()
{
	vector<string> fact={"r","M","teta","1","2"};
	vector<string> operacion={"+","-","*","/","^","sin"};

/*	symbol r("r"), M("M"), teta("teta");
	ex g00 = 1-2.0/r;
*/
	setRama(fact, operacion);
	setRamaPrim(rama,fact);
	return 0;
}

void setRama(vector<string> factor, vector<string> operacion)
{		
	for(int j=0;j<=4;j++)
	{
		for(int i=0;i<=5;i++)
		{
			rama.push_back(factor[j] + operacion[i]);
	cout<<"rama...=" << " j=" << j << " i=" << i << "oper:"<<operacion[i]<<endl;
						
		}
	}
}
void setRamaPrim(vector<string> ram, vector<string> factor)
{
	for(int i=0; i<ram.size();i++)
	{
		for(int j=0;j<factor.size();j++)
		{
			ramaPrim.push_back(ram(i)+factor(j));
		}
	}
}
Hello psosmol,

On line 48 "ram(i)" and "factor(j)" are interpreted as function calls. What you want is "ram[i]" and "factor[j]". The square []s mean subscript in this case.

error: no match for call to
I don't know what it means


I do not either. Next time post the actual error message not your condensed version that leaves out the important parts.

Hope that helps.

Andy
thanks Andy, it works
Topic archived. No new replies allowed.