Conver PSEINT a XCAS

Messages in english

Modérateur : xcasadmin

compsystems
Messages : 518
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

Conver PSEINT a XCAS

Message par compsystems » dim. sept. 16, 2018 1:06 am

Hi BP, PSEINT is a software to learn programming logic that can also export to different languages c/c++, I have collaborated with the translation to XCAS, see below, the conversion works well, wait for next news.

Just as a suggestion, we want the word Done to be reserved, so that the compilation does not throw the global variable message

thank you very much.
PSEINT HOME PAGE
http://pseint.sourceforge.net/slide/pseint.html

Code : Tout sélectionner

sin_titulo_00():={
	
	DispG; ClrIO; ClrGraph;
	
	printf( "Hola Mundo" );
	
	Pause; DispHome; 
	
	return Done; 
}:; 

sin_titulo_01():={
	
	local a, b, c, d, ee_, f, p; 
	
	assume(a,integer) 
	assume(b,real); 
	assume(c,integer);
	assume(d,integer);
	
	assume(ee_,DOM_STRING); 
	assume(f,DOM_STRING); 
		
	assume(p,DOM_STRING); 
	
	DispG; ClrIO; ClrGraph;
	
	a:=1;
	b:=2.5;
	c:=true;
	d:=false;
	ee_:="Hola"; 
	f:="Hola Mundo";
	
	InputStr("p",p);  
	printf( p );
	
	Pause; DispHome; 
	return Done;
}:;

sin_titulo_02():={
	
	local a;
	local b;
	local c;
	local d;
	
	assume(a,integer); 
	assume(b,real); 
	assume(c,DOM_STRING); 
	assume(d,integer); 
	
	DispG; ClrIO; ClrGraph;
	
	input( "a", a ); 
	input( "b", b ); 
	InputStr( "c", c ); 
	input( "d", d ); 
	
	printf( a ); 
	printf( b ); 
	printf( c ); 
	printf( d ); 
	
	inputform( "a", a, "b", b, "c", c, "d",d ); 
	
	printf( string(a)+string(b)+ c +string(d) ); 
	
	printf( "Esta linea no lleva enter al final" );
	
	Pause; DispHome; 
	return Done;
	
}:;

sin_titulo_03():={
	local c;
	assume(c,integer);
	
	DispG; ClrIO; ClrGraph;
	
	c:=0;
	while c<=10 do
		c:=c+1;
	printf( c );
	end;
	
	c:=0;
	repeat
		c:=c+1;
		printf( c );
	until c=10;
		
	if c=10 then
		printf("Si");
	end;
		
	if c=10 then
		printf("Si");
	else
		printf("No");
	end;
	
	Pause; DispHome; 
	return Done;
}:;

sin_titulo_04():={
	local a, b, c, d, ee_, n;
	
	assume(a,DOM_LIST); 
	assume(b,DOM_LIST); assume(c,DOM_LIST); assume(d,DOM_LIST);
	assume(ee_,DOM_LIST);
	assume(n,integer);
	
	DispG; ClrIO; ClrGraph; 
	index:=1; 
		
	a:= makelist( 10 ); 
	b:= matrix( 20, 30 ); 
		
	c:= makelist( 40 );
	d:= matrix( 50, 5 );
	
	Input("n",n);
	ee_:= makelist( n ); 
		
	Input( "a(1)", a[[1]] ); 
	a[[10]]:= a[[1]];
	printf( b[[10,10]] );
	
	Pause; DispHome; 
	return Done;
}:;

sin_titulo_05():={
	
	local a, b, c, index_rows, index_cols, ii_, j;
	
	assume(a,DOM_LIST); 
	assume(b,DOM_LIST);
	assume(c,integer);
	assume(index_rows,integer); assume(index_cols,integer);
	assume(ii_,integer); assume(j,integer);
	
	DispG; ClrIO; ClrGraph; 
	index:=1; 
	
	a:= makelist( 10 ); 
	b:= matrix( 3, 6 ); 
	
	for ii_ from 1 to 10 do 
		a[[ii_]] := ii_*10;
	end;
	
	for index_cols from 1 to dim(a) do 
		printf( a[[index_cols]] ); 
	end;
	
	c:= 0;
	for index_rows from 1 to dim(b)[[1]] do 
		for index_cols from 1 to dim(b)[[2]] do 
			c:=c+1;
			b[[index_rows,index_cols]] := c;
		end;
	end;
		 
		 
	for ii_ from 3 to 1 step -1 do
		for j from 1 to 5 step 2 do
			printf( b[[ii_,j]] );
		end;
	end;
	 
	 
	return Done;
}:;

sin_titulo_06():={
	
	local c; 
	assume(c,integer);
	
	DispG; ClrIO; ClrGraph; 
	
	input("c",c);
	
	switch(c){
		case 1:{
			printf("1");
			break;
		}
		case 3:{ 
			printf("3, 5 o 9");
			break;
		}
		case 5:{
			printf("3,5 o 9");
			break;
		}
		case 9:{
			printf("3, 5 o9");
			break;
		}
		case 7:{
			printf("7");
			break;
		}
		default:{
			printf("no es 1, 3, 5, 7, 9");
			break;
		}
	}
	
	Pause; DispHome; 
	return Done;
}:;


sin_titulo_07():={ 
	local a, b, c;
	
	assume(a,DOM_LIST);
	assume(b,DOM_LIST);
	assume(c,integer);
	
	DispG; ClrIO; ClrGraph; 
	
	a:= makelist( 10 );
	b:= matrix( 3, 4 );
		
	printf( FuncionDoble(5) );
	NoRetornaNada(3,9);
	
	c:=0;
	c:=PorReferencia(c);
	printf(c);
	
	RecibeVector(a);
	RecibeMatriz(b);
	
	return Done;
	
}:; 



FuncionDoble(b):={
	local a; assume(a,integer);
	a:=2*b;
	return a;
}:;

NoRetornaNada(a,b):={
	printf("NoRetornaNada 9+3=");
	printf(a+b);
}:;

PorReferencia(b):={
	local b; assume(b,integer);
	b := 7
		return b;
}:;

RecibeVector(v):={
	input( "v(1)", v[[1]] );
	printf("v[[1]]=");
	printf( v[[1]] );
	
	v[[2]]:=50;
	printf("v[[1]]=");
	printf( v[[2]] );
}:;

RecibeMatriz(m):={
	input( m[[1,1]] );
	printf( m[[1,1]] );
	
	m[[1,2]]:=25;
	printf( m[[1,2]] );
}:;

sin_titulo_08():={
	
	local a,b,c,d,ee,f;
	assume(a,integer); assume(b,integer);
	assume(c,integer); assume(d,integer);
	assume(ee,DOM_STRING); assume(f,DOM_STRING);
	
	DispG; ClrIO; ClrGraph; 
	
	a:=11; 
	b:=2; 
	c:=true; 
	d:=false; 
	ee:="Hola"; 
	f:="Mundo"; 
	
	printf( "algebraicos");
	printf( a+b ); 
	printf( a*b ); 
	printf( a/b ); 
	printf( a-b ); 
	printf( a^b ); 
	printf( a mod b ); 
	
	printf( "relacionales");
	printf( a==b ); 
	printf( a?b); 
	printf( a<b ); 
	printf( a>b ); 
	printf( a=b ); 
	printf( a=b ); 
	
	printf( "logicos");
	printf( c and d ); 
	printf( c or d );
	printf( NOT (c and d) ); 
	
	printf( "para cadenas" );
	printf( ee+" "+f ) ;
	
	printf( ee==f );
	printf( ee?f ); 
	printf( ee<f ); 
	printf( ee>f ); 
	printf( ee=f ); 
	printf( ee=f ); 
	
	Pause; DispHome; 
	return Done;
}:;

sin_titulo_09():={
	
	local x,s; 
	assume(x,real);
	assume(s,DOM_STRING);
	
	DispG; ClrIO; ClrGraph; 
	angle_radian:=1;
	x:=1.5;
	s:="Hola";
	
	printf( sqrt(x) ); 
	printf( abs(x) ); 
	printf( ln(x) ); 
	printf( exp(x) ); 
	printf( sin(x) ); 
	printf( cos(x) ); 
	printf( tan(x) ); 
	printf( asin(x) ); 
	printf( acos(x) ); 
	printf( atan(x) ); 
	printf( round(x) ); 
	printf( iPart(x) ); 
	printf( randint( 0, 15 ) );
	printf( size(s) ); 
	printf( Minusculas(s)); 
	printf( Mayusculas(s) ); 
	printf( mid(s,0,2) ); 
	printf( append(s," Mundo") ); 
	printf( append("Mundo ",s) ); 
	printf( expr("15.5" ) ); 
	printf( string(15.5) ); 
	
	Pause; DispHome; 
	return Done;
}:;

Mayusculas(str):={
	local c, sout:="";
	local s:=size(str);
	local s2:="";
	
	for c from 0 to s-1 do
		s2:= mid(str,c,1);
	if (s2 >= "a" and s2 <= "z") then
		sout:= sout+ char( (65+ ord( s2 )-97 ));
	else
		sout:= sout+s2;
	end;
	end;
	return( sout );
}:;

Minusculas(str):={
	local c, sout:="";
	local s:=size(str);
	local s2:="";
	
	for c from 0 to s-1 do
		s2:= mid(str,c,1);
	if (s2 >= "A" and s2 <= "Z") then
		sout:= sout+ char( 97-(65-ord( s2 )) );
	else
		sout:= sout+s2;
	end;
	end;
	return( sout );
}:;

sin_titulo_10():={
	
	DispG; ClrIO; ClrGraph; 
	
	ClrIO; ClrGraph; 
	Pause; 
	WAIT( 1 );
	printf(p); 
	
	Pause; DispHome; 
	return Done;
}:;


parisse
Messages : 5112
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: Conver PSEINT a XCAS

Message par parisse » dim. sept. 16, 2018 6:07 am

You can replace return Done; with return "Done";

Répondre