// How can I rewrite this loop to C++ from C
// I dont know how to define vectors x, z, and v!
// x, z, and v are vectors, and N is the number of vectors x and z (N=2).

c:= 10;     
N:= 2;          
p:= 3;
b:=5;

for r:= 1 to p do {
    sum(i:= 1 to N, v[i,r]) = 1;
    sum(i:= 1 to N, v[i,r]*z[i]) = zz[r];
    sum(i:= 1 to N, v[i,r]*x[i])  = b;  
}

Recommended Answers

All 4 Replies

That's not C code -- looks more like pascal or java.'

At any rate, in C/C++ you have to declare variables before they can be used. so if you want to use a vector then you have to incude the vecor heade file

 #include <vector>
 using std::vector;

This code looks very odd. I've been trying to figure out what language it is, but I can't. It has the hallmarks of a Pascal-style language, i.e., the := assigments and the for r:= 1 to p do syntax, which are both definitely Pascal. However, the use of { } instead of begin end makes it very odd because all Pascal-style languages that I know would use the latter.

And then, the sum(i:= 1 to N, v[i,r]) = 1; lines baffle me a bit. By Pascal syntax, the single equal sign should mean a test for equality, which doesn't make sense without some sort of if-statement or conditional. If it's an assignment, then what is being assigned? The result of the sum? Makes no sense.

Is it a symbolic math language? As in, that line constrains the column of "v" to have a sum equal to 1. This does indeed look like something you could write in Maple, except that the syntax is a bit off. If this is a Maple-like language, then that code cannot be translated to C++, because it requires a symbolic math solver to run this. It might be any of the many CAS software that I am not too familiar with. If you need to run this kind of a program in C++, then you would have to link to a CAS library like GiNaC, Maxima, SAGE, SymPy, etc...

I tried to figure this out too. It looks like a derivitive of Pascal, but everything inside of the loop is very strange.

Is this the OP's attempt of converting from this mystery language to C++?

Modula maybe. It certainly isn't C.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.